Author Topic: Fixing the rotation of projectiles  (Read 2255 times)

rudyman

  • Guest
When I create a projectile with this code:

Code: [Select]
%slot=myProjectile.mountPoint;
%projectile=new Projectile()
{
dataBlock=myProjectile;
initialVelocity=2;
initialPosition=%obj.getMuzzlePoint(%slot);
sourceObject=%obj;
sourceSlot=%slot;
};

The projectile appears at the right muzzle point but it always shoots in the same direction. How do I make it so it always moves in the direction the player is looking?

You can't.  Once fired you can't change it.

rudyman

  • Guest
You can't.  Once fired you can't change it.

I want to set the rotation before it's fired, where I'm setting the position, etc.

Er rudy, velocity is the combination of speed and direction. Maths 101:

To have your projectile going at a speed of 5 on the X axis, your velocity would be: 5 0 0
To have your projectile going down at a speed of 50, your velocity would be: 0 0 -50
To have your projectile angled at 45 degrees down at a speed of 25 from the ejection point, it would be: 25 0 -25
Got it?

Next, to have it go in the direction of the player, you need this code to calculate where he's looking:
Code: [Select]
%obj = %player;
%initPos = %obj.getMuzzlePoint(%slot);
%muzzleVector = %obj.getMuzzleVector(%slot);

%objectVelocity = %obj.getVelocity();
%muzzleVelocity = VectorAdd(VectorScale(%muzzleVector, %projectile.muzzleVelocity), VectorScale(%objectVelocity, %projectile.velInheritFactor));
%muzzleVelocity would be your projectile initialVelocity.