SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 31/03/2015, 03:01 PM   #1
CalvinC
High-roller
 
CalvinC's Avatar
 
Join Date: Nov 2014
Location: Denmark
Posts: 1,831
Reputation: 114
Default 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.
CalvinC is offline   Reply With Quote
Old 31/03/2015, 06:14 PM   #2
Sascha
High-roller
 
Sascha's Avatar
 
Join Date: Jul 2009
Location: Germany
Posts: 1,494
Reputation: 70
Default 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
Sascha is offline   Reply With Quote
Old 31/03/2015, 06:32 PM   #3
CalvinC
High-roller
 
CalvinC's Avatar
 
Join Date: Nov 2014
Location: Denmark
Posts: 1,831
Reputation: 114
Default 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.
CalvinC is offline   Reply With Quote
Old 31/03/2015, 07:04 PM   #4
Sascha
High-roller
 
Sascha's Avatar
 
Join Date: Jul 2009
Location: Germany
Posts: 1,494
Reputation: 70
Default 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
Sascha is offline   Reply With Quote
Old 31/03/2015, 08:18 PM   #5
CalvinC
High-roller
 
CalvinC's Avatar
 
Join Date: Nov 2014
Location: Denmark
Posts: 1,831
Reputation: 114
Default 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.
CalvinC is offline   Reply With Quote
Old 01/04/2015, 06:42 AM   #6
Gammix
High-roller
 
Gammix's Avatar
 
Join Date: Jan 2015
Location: Canada
Posts: 1,773
Reputation: 856
Default 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:

Gammix is offline   Reply With Quote
Old 01/04/2015, 09:33 AM   #7
CalvinC
High-roller
 
CalvinC's Avatar
 
Join Date: Nov 2014
Location: Denmark
Posts: 1,831
Reputation: 114
Default 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.
CalvinC is offline   Reply With Quote
Old 01/04/2015, 09:59 AM   #8
BroZeus
High-roller
 
BroZeus's Avatar
 
Join Date: Jan 2014
Location: India
Posts: 1,398
Reputation: 173
Default 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:VxFloat:VyFloat:Vz;
    
GetVehicleVelocity(vehicleidVxVyVz);
    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
            
FloatAngle,
        
FloatAngleX,
        
FloatAngleY,
                
FloatVelocityX,
                
FloatVelocityY,
                
FloatVelocityZ,
                
Float:c_speed GetVehicleSpeed(vehicleid);//current speed
            
;

            
GetVehicleVelocity(vehicleidVelocityXVelocityYVelocityZ);
            
GetVehicleZAngle(vehicleidAngle);
            
AngleX floatsin(-Angledegrees);
            
AngleY floatcos(-Angledegrees);
            
SetVehicleVelocity(vehicleidAngleX * (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.
BroZeus is offline   Reply With Quote
Old 01/04/2015, 11:50 PM   #9
Sascha
High-roller
 
Sascha's Avatar
 
Join Date: Jul 2009
Location: Germany
Posts: 1,494
Reputation: 70
Default Re: Speed boost

Quote:
Originally Posted by CalvinC View Post
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.
Sascha is offline   Reply With Quote
Reply

Thread Tools
Display Modes

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


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


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


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.