Velocity
Last updated
Was this helpful?
Was this helpful?
// check the value on Velocity...
bool isFalling = this.Velocity.Y < 0;
// or check the YVelocity property
bool isFalling = this.YVelocity < 0;using Microsoft.Xna.Framework;
...
float BulletSpeed = 150;
void CustomActivity(bool firstTimeCalled)
{
if(InputManager.Keyboard.KeyPushed(Microsoft.Xna.Framework.Input.Keys.Space))
{
var bullet = Factories.BulletFactory.CreateNew();
bullet.Velocity = new Vector3(BulletSpeed, 0, 0);
}
}using Microsoft.Xna.Framework;
...
float BulletSpeed = 150;
void CustomActivity(bool firstTimeCalled)
{
if(InputManager.Keyboard.KeyPushed(Microsoft.Xna.Framework.Input.Keys.Space))
{
var bullet = Factories.BulletFactory.CreateNew();
bullet.Velocity = new Vector3(BulletSpeed, 0, 0).AtAngle(MathHelper.ToRadians(45));
bullet = Factories.BulletFactory.CreateNew();
bullet.Velocity = new Vector3(BulletSpeed, 0, 0).AtAngle(MathHelper.ToRadians(22));
bullet = Factories.BulletFactory.CreateNew();
bullet.Velocity = new Vector3(BulletSpeed, 0, 0).AtAngle(MathHelper.ToRadians(0));
bullet = Factories.BulletFactory.CreateNew();
bullet.Velocity = new Vector3(BulletSpeed, 0, 0).AtAngle(MathHelper.ToRadians(-22));
bullet = Factories.BulletFactory.CreateNew();
bullet.Velocity = new Vector3(BulletSpeed, 0, 0).AtAngle(MathHelper.ToRadians(-45));
}
}if(InputManager.Keyboard.KeyDown(Keys.Right))
{
myCharacter.Velocity.X = 100;
}if(InputManager.Keyboard.KeyDown(Keys.Right))
{
myCharacter.Velocity.X = 100;
}
else
{
myCharacter.Velocity.X = 0;
}Vector3 vectorFromBulletToPlayer = Player.Position - Bullet.Position;
vectorFromBulletToPlayer.Normalize();
float speedToMoveAt = 30; // this means 30 units per second
Bullet.Velocity = vectorFromBulletToPlayer * speedToMoveAt;