Updated velocity function
#5

Just an update to that other velocity function I released but this one is quicker and easier to understand or use I think.

I made this post seperate as it's just about the function, the other thread is for the filterscript and commands etc. This is also better for people who just want the function to put into their own scripts and not have to figure out the other script (not that it's tough, just a task I mean).

Function -> Pastebin

The arguments are:

id = the id of the player or vehicle you wish to add the velocity to (the function will fail on invalids)
type = the type of element you are going to be adding it to (player/vehicle, default is player (0))
axis = which axis do you want to add the velocity to (x,y,z, default is y (north/south))
power = how much acceleration to add to that axis (default is 1.0 (quite quick still))

Usage:

pawn Код:
//ripped from my current script, the vehicle keypress
case 0: AddVelocity( GetPlayerVehicleID( playerid ), 1, 0, gPower[ playerid ] ); //forwards
case 1: AddVelocity( GetPlayerVehicleID( playerid ), 1, 0, -gPower[ playerid ] ); //backwards
case 2: AddVelocity( GetPlayerVehicleID( playerid ), 1, 1, -gPower[ playerid ] ); //left
case 3: AddVelocity( GetPlayerVehicleID( playerid ), 1, 1, gPower[ playerid ] ); //right
case 4: AddVelocity( GetPlayerVehicleID( playerid ), 1, 2, gPower[ playerid ] ); //up
case 5: AddVelocity( GetPlayerVehicleID( playerid ), 1, 2, -gPower[ playerid ] ); //down
default: AddVelocity( GetPlayerVehicleID( playerid ), 1, 0, gPower[ playerid ] ); //forwards
So the first line:

pawn Код:
AddVelocity( GetPlayerVehicleID( playerid ), 1, 0, gPower[ playerid ] ); //forwards
The arguments are:

id = the players vehicle id
type = vehicle (1)
axis = y (0)
power = gPower is currently at 1.0 so add 1.0 (positive = forward, negative is backwards on y)

A few usefull defines incase you want them also:

pawn Код:
#define Y 0
#define X 1
#define Z 2
#define PLAYER 0
#define VEHICLE 1
Example:

pawn Код:
AddVelocity( GetPlayerVehicleID( playerid ), VEHICLE, Y, gPower[ playerid ] ); //forwards
@Mods:

If you think this should be part of this thread and not seperate then please move it, cheers.
Reply


Messages In This Thread
Updated velocity function - by Donny_k - 04.09.2009, 17:35
Re: [REL] keypress velocity for vehicles. - by V1ceC1ty - 04.09.2009, 17:37
Re: [REL] keypress velocity for vehicles. - by [mad]MLK - 04.09.2009, 17:42
Re: [REL] keypress velocity for vehicles. - by Donny_k - 04.09.2009, 17:57
Updated velocity function - by Donny_k - 07.09.2009, 09:37

Forum Jump:


Users browsing this thread: 1 Guest(s)