SA-MP Forums Speed boost
 New Account Members List Search Today's Posts Mark Forums Read

 31/03/2015, 03:01 PM #1 CalvinC High-roller     Join Date: Nov 2014 Location: Denmark Posts: 1,831 Reputation: 114 Speed boost I have 2 different methods of speed boosting, and they both do good things, but i'm unsure on how to combine them. I just put together a function with the 2 methods: pawn Code: `Boost(vehicleid, speed, method){    switch(method)    {        case 0:        {            // 1st method            new                Float: VelocityX,                Float: VelocityY,                Float: VelocityZ            ;            GetVehicleVelocity(vehicleid, VelocityX, VelocityY, VelocityZ);            SetVehicleVelocity(vehicleid, VelocityX * speed, VelocityY * speed, VelocityZ);        }        case 1:        {            // 2nd method            new            Float: Angle,        Float: AngleX,        Float: AngleY,                Float: VelocityX,                Float: VelocityY,                Float: VelocityZ            ;            GetVehicleVelocity(vehicleid, VelocityX, VelocityY, VelocityZ);            GetVehicleZAngle(vehicleid, Angle);            AngleX = floatsin(-Angle, degrees);            AngleY = floatcos(-Angle, degrees);            SetVehicleVelocity(vehicleid, AngleX * speed, AngleY * speed, VelocityZ);        }    }}` The 2nd method basically sets the vehicles velocity according to where it's facing. The good thing about this, is that it doesn't boost the vehicle in the direction that the vehicle is travelling, but the way it's facing. Say i'm drifting or reversing and use the 1st method, it will make me go sideways or backwards which is annoying. While this one makes me go forwards, which is what i want. The problem with this one is that it does not add to the speed, so it doesn't go faster than the speed given. I would like it to just go faster and faster the more you use the boost, which the 1st method does. I've tried experimenting a lot, but i'm just lost on how i can combine these 2 good things. So it somehow multiplies the velocity by the speed given. And also makes the vehicle go forwards by the angle method. __________________ [Tutorial] Custom Playerdamage system Desert Eagle's dealing too much damage, you want one-hit sniper kills, or damage based on body parts? Check this out.
 31/03/2015, 06:14 PM #2 Sascha High-roller     Join Date: Jul 2009 Location: Germany Posts: 1,494 Reputation: 70 Re: Speed boost have you considered using this method? http://wiki.sa-mp.com/wiki/SetVehicleAngularVelocity ----Edit---- nvm, got the method wrong, doubt this would help you, just ignore this post in this case __________________ Don't bother to contact me, I'm out of SA-MP
 31/03/2015, 06:32 PM #3 CalvinC High-roller     Join Date: Nov 2014 Location: Denmark Posts: 1,831 Reputation: 114 Re: Speed boost I don't see how the angular velocity has anything to do with this, but thanks for trying to help. __________________ [Tutorial] Custom Playerdamage system Desert Eagle's dealing too much damage, you want one-hit sniper kills, or damage based on body parts? Check this out.
 31/03/2015, 07:04 PM #4 Sascha High-roller     Join Date: Jul 2009 Location: Germany Posts: 1,494 Reputation: 70 Re: Speed boost Anyway, to add something more useable to this: Let's face this problem mathematically. Imagine 2 coordinate systems - 1. The static coords (sa-mp coordinates x y z) and 2. the dynamic coordinates (relative to the car - dX dY dZ) If you then calculate the shadow of the static system on the dynamic one (proportion in dX, dY and dZ direction), you could multiply it with this value. So - get the x y z velocity of the car - transfere the x y and z coordinates into dX dY and dZ - multiply dX dY dZ with "speed" e.g. (x, y, z) = (1, 1, 0) would be something like (1/sqrt(2) + 1/sqrt(2), 1/sqrt(2) + 1/sqrt(2), 0) = (dX, dY, dZ) [I guess at least] for an angle offset of 45 degrees (you can express this with cos and sin) I hope that this helps a bit more^^ __________________ Don't bother to contact me, I'm out of SA-MP
 31/03/2015, 08:18 PM #5 CalvinC High-roller     Join Date: Nov 2014 Location: Denmark Posts: 1,831 Reputation: 114 Re: Speed boost I don't understand what you mean with the dynamic coordinates. pawn Code: `(1/sqrt(2) + 1/sqrt(2), 1/sqrt(2) + 1/sqrt(2), 0) = (dX, dY, dZ)` Like this, i don't understand what you mean by that? __________________ [Tutorial] Custom Playerdamage system Desert Eagle's dealing too much damage, you want one-hit sniper kills, or damage based on body parts? Check this out.
 01/04/2015, 06:42 AM #6 Gammix High-roller     Join Date: Jan 2015 Location: Canada Posts: 1,773 Reputation: 856 Re: Speed boost Refer to this include's code: http://forum.sa-mp.com/showthread.php?t=309467 The function SetPlayerLookAt can be used for the same purpose. __________________ Follow me on Github: Follow me on Spotify: Donate on Paypal:
 01/04/2015, 09:33 AM #7 CalvinC High-roller     Join Date: Nov 2014 Location: Denmark Posts: 1,831 Reputation: 114 Re: Speed boost Setting the angle of the vehicle isn't really what i'm looking for, i mean boosting the vehicle forwards depending on it's facing "z" angle and it's current velocity. __________________ [Tutorial] Custom Playerdamage system Desert Eagle's dealing too much damage, you want one-hit sniper kills, or damage based on body parts? Check this out.
 01/04/2015, 09:59 AM #8 BroZeus High-roller     Join Date: Jan 2014 Location: India Posts: 1,398 Reputation: 173 Re: Speed boost Well that's because you are not taking current speed of vehicle into account. EDIT: Well first take out current speed add that speed to "speed" variable then multiply it like this - PHP Code: ``` stock GetVehicleSpeed(vehicleid)//to take out vehicle speed {     new Float:Vx, Float:Vy, Float:Vz;     GetVehicleVelocity(vehicleid, Vx, Vy, Vz);     new Float:rtn;     rtn = floatsqroot(floatpower(Vx*100,2) + floatpower(Vy*100,2));     rtn = floatsqroot(floatpower(rtn,2) + floatpower(Vz*100,2));     return floatround(rtn); } //now in 2nd method like this -  new             Float: Angle,         Float: AngleX,         Float: AngleY,                 Float: VelocityX,                 Float: VelocityY,                 Float: VelocityZ,                 Float:c_speed = GetVehicleSpeed(vehicleid);//current speed             ;             GetVehicleVelocity(vehicleid, VelocityX, VelocityY, VelocityZ);             GetVehicleZAngle(vehicleid, Angle);             AngleX = floatsin(-Angle, degrees);             AngleY = floatcos(-Angle, degrees);             SetVehicleVelocity(vehicleid, AngleX * (speed+c_speed), AngleY * (speed+c_speed), VelocityZ);//note change in this line         }  ``` __________________ "Be the change that you wish to see in the world." Check out my Github profile! Last edited by BroZeus; 01/04/2015 at 02:39 PM.
01/04/2015, 11:50 PM   #9
Sascha
High-roller

Join Date: Jul 2009
Location: Germany
Posts: 1,494
Reputation: 70
Re: Speed boost

Quote:
 Originally Posted by CalvinC I don't understand what you mean with the dynamic coordinates. pawn Code: `(1/sqrt(2) + 1/sqrt(2), 1/sqrt(2) + 1/sqrt(2), 0) = (dX, dY, dZ)` Like this, i don't understand what you mean by that?
By "dynamic Coordinates" I mean a second coordinate system.
So not only the static X Y Z that you have by default. Imagine a new center of coordinates at the vehicle, pointing into the vehicle direction, let's say: dX to the side of the vehicle, dY to the front of the vehicle, dZ to the roof of the vehicle.
This coordinate system is always moving with the vehicle. dY is always pointing into the direction that your vehicle is heading, dX (if your vehicle is not drifting) is pointing to the side (doors) and dZ upwards.
Basicly the same as the x/y/z offset for attached objects to the vehicle.

(I've added a small image for that as attachment)
Then you could use trigonometry (not sure how it's called in english) with sin, cos, and tan
dY would then be: sin(angle) = Y/dY
dX: sin(angle) = X/dX
if I'm not wrong now...

You can then easily calculate
dXspeed = Xspeed/sin(angle) + Yspeed/cos(angle)
dYspeed = Yspeed/sin(angle) + Xspeed/cos(angle)

As you are most often moving into 2 direction (x and y) you need to add both proportions to get the complete speed for the vehicle based coordinates.

dXspeed would then show the total speed pointing sideways to the car direction and dYspeed would be the complete speed into the direction the vehicle is moving in.
You then could just set "dXspeed" and "dYspeed" for the x and y parameter in theSetVehicleVelocity... at least this is working in my head, there might be some "small" mathematic mistake in it though

Edit: mind the edit
__________________
Don't bother to contact me, I'm out of SA-MP

Last edited by Sascha; 07/05/2016 at 09:45 AM.

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post Mohamedilham Scripting Help 1 19/09/2014 11:44 AM Saleem Scripting Help 2 29/06/2013 01:45 PM BlackBlood's Scripting Help 7 07/12/2011 06:54 AM stieben Help Archive 9 08/12/2010 05:58 PM

All times are GMT. The time now is 10:35 PM.

 -- (EN) English -- (RU) Русски SA-MP - Archive - Top