Author Topic: Add Velocity  (Read 1362 times)

I just need to know how i add a players velocity torwards the direction he is looking, but i don't know the equation dealing with the players rotation (if that is how it should be done or is it raycasting, or both?)

anyone care to help?

Code: [Select]
%player.addVelocity(vectorScale(%player.getForwardVector(),%speed));

Code: [Select]
%player.addVelocity(vectorScale(%player.getForwardVector(),%speed));

ok thanks, lets say the player is looking north, how would i add velocity directly west to him.

Code: [Select]
%player.addVelocity(vectorScale(%player.getForwardVector(),%speed));
It doesn't say how much velocity it goes forward. ?




I'm still new to coding.

im still wondering how i can do this to make a player add velocity directly to his left/right

im still wondering how i can do this to make a player add velocity directly to his left/right

instead for getting the forward vector you would need to do some equation to find the vector of a person's right or left.  I'm terrible with vectors and I can only do so much with raycasts, so I'm not sure exactly what code to use.

I tried to work it out. It involved using axisToEuler and some tricky maths. Didn't work though. Pretty sure Truce or Space Guy will come in here with an easy method completely foiling my attempt :cookieMonster:

Pretty sure Truce or Space Guy will come in here with an easy method completely foiling my attempt :cookieMonster:

Well since Space Guy is sleeping...  :cookieMonster:

Code: [Select]
%pos = vectorAdd(%pos,%offx * %vy + %offy * %vx SPC %offy * %vy + %offx * -%vx SPC %offz);
%pos is the position of the player
%vx and %vy are the two components to the player's forward vector*
%offx, %offy, and %offz are the position offsets

For example, to get a position 5 units to the player's right, %offx would be 5.
And 3 units to the left and 3 units behind would be %offx = -3 and %offy = -3.

*easiest way:

Code: [Select]
%fv = %pl.getForwardVector();
%vx = getWord(%fv,0);
%vy = getWord(%fv,1);

AAAAUghghh.... vector math.

Good to know there is someone out there that gets it, though.

position
velocity
I checked your script in-game just to be sure, and it's definitely not what he is asking. Maybe you should go sleep as well :cookieMonster:

I checked your script in-game just to be sure, and it's definitely not what he is asking. Maybe you should go sleep as well :cookieMonster:

I think you're the one tired here - I used it as an example to get a position relative to where the player's facing. For velocity, instead of vectorAdd(%pos,<expression>), you can %pl.addVelocity(<expression>). It uses the same calculations.