Speed boost -
CalvinC - 31.03.2015
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 Код:
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.
Re: Speed boost -
Sascha - 31.03.2015
have you considered using this method?
https://sampwiki.blast.hk/wiki/SetVehicleAngularVelocity
----Edit----
nvm, got the method wrong, doubt this would help you,
just ignore this post in this case
Re: Speed boost -
CalvinC - 31.03.2015
I don't see how the angular velocity has anything to do with this, but thanks for trying to help.
Re: Speed boost -
Sascha - 31.03.2015
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^^
Re: Speed boost -
CalvinC - 31.03.2015
I don't understand what you mean with the dynamic coordinates.
pawn Код:
(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?
Re: Speed boost -
Gammix - 01.04.2015
Refer to this include's code:
https://sampforum.blast.hk/showthread.php?tid=309467
The function
SetPlayerLookAt can be used for the same purpose.
Re: Speed boost -
CalvinC - 01.04.2015
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.
Re: Speed boost -
BroZeus - 01.04.2015
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 код:
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
}
Re: Speed boost -
Sascha - 01.04.2015
Quote:
Originally Posted by CalvinC
I don't understand what you mean with the dynamic coordinates.
pawn Код:
(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