# setElementVelocity forwards

## Recommended Posts

I need help with this! I want to use setElementVelocity to make a ped go forwards (in the direction it is facing). How can I do this as setElementVelocity works along the x and y axis of the map and not the player.

nah dont see how that works, i want it so that if im facing north my velocity will be x, y + 0.1, z.

If im facing south it would be x, y - 0.1, z

east would be x + 0.1

west x - 0.1

that part is easy but how can i calculate what it should be for all the stuff in between. For example if i face north east (45 degrees) it will be x + 0.1, y +0.1 z. But if im facing at 10 degrees for example, how can i make the script calculate what the x and y should be?

```function setElementForwardVelocity( elem, vel )
local ang = getElementRotation( elem );
local vx = math.cos( ang ) * vel;
local vy = math.sin( ang ) * vel;
return setElementVelocity( elem, vx, vy, 0 );
end
```

Haven't tested it but should work.

ok its been a while but i want to come back to this. I want this so that i can put it in the parachute recource so that i glide more than fall. At the moment i did my parachute resource so that if im not holding controls it sets my velocity as x+1 and y+1 but of curse that just has me shooting off 45 degrees NE. How can i set my velocity to make myself go forward as im falling in parachute script

```function setElementForwardVelocity( elem, vel )
local ang = getElementRotation( elem );
local vx = math.cos( ang ) * vel;
local vy = math.sin( ang ) * vel;
return setElementVelocity( elem, vx, vy, 0 );
end
```

Haven't tested it but should work.

Added the function to my script but for e.x: setElementForwardVelocity(localPlayer,2) does nothing for me.

```function setElementForwardVelocity( elem, vel )
local ang = getElementRotation( elem );
local vx = math.cos( ang ) * vel;
local vy = math.sin( ang ) * vel;
return setElementVelocity( elem, vx, vy, 0 );
end
```

Haven't tested it but should work.

What is the math.rad, math.cos and math.sin?

```function setElementForwardVelocity( elem, vel )
local ang = getElementRotation( elem );
local vx = math.cos( ang ) * vel;
local vy = math.sin( ang ) * vel;
return setElementVelocity( elem, vx, vy, 0 );
end
```

Haven't tested it but should work.

What is the math.rad, math.cos and math.sin?

http://lua-users.org/wiki/MathLibraryTutorial

Added the function to my script but for e.x: setElementForwardVelocity(localPlayer,2) does nothing for me.

It doesn't work while you stand on the ground, you get stuck. You have to first jump and then use it (alternatively set your position above the ground and then use it, or setElementVelocity upwards and then timer and setElementVelocity forwards, lol).

Added the function to my script but for e.x: setElementForwardVelocity(localPlayer,2) does nothing for me.

It doesn't work while you stand on the ground, you get stuck. You have to first jump and then use it (alternatively set your position above the ground and then use it, or setElementVelocity upwards and then timer and setElementVelocity forwards, lol).

Just shoots me in the same direction every time

It just shoots me North... Any Ideas?

Simple as that.

• 1