I want to spawn a ramp in front of player's vehicle. Can somebody tell me how to calculate the pos? Thanks! :)
Also trying to figure this out but can't for some reason the object doesnt appear when i touch its pos.
You can calculate the position in front of a player like so:
local pos = pPlayer.Pos;
local rot = pPlayer.Angle, rad = rot * 3.14159265359 / 180.0;
local x = pos.x, y = pos.y;
local x2 = x + 1.0 * cos(rad) - 25.0 * sin(rad);
local y2 = y + 1.0 * sin(rad) + 25.0 * cos(rad);
Quote from: Thijn on Feb 09, 2015, 05:22 PMYou can calculate the position in front of a player like so:
local pos = pPlayer.Pos;
local rot = pPlayer.Angle, rad = rot * 3.14159265359 / 180.0;
local x = pos.x, y = pos.y;
local x2 = x + 1.0 * cos(rad) - 25.0 * sin(rad);
local y2 = y + 1.0 * sin(rad) + 25.0 * cos(rad);
To be honest, understood nothing.... maybe my math skills suck.
Might give a bit more information: clicky (http://vcmp.liberty-unleashed.co.uk/forum/index.php?topic=2732.msg18616#msg18616)
Quote from: Shadow.// [Ka]Juppi's func from http://forum.liberty-unleashed.co.uk/index.php/topic,398.0.html
// ported to fit your needs
function GetForwardPoint( pos, angle ) // you must pass an angle in degrees
{
local rad = angle * PI / 180; // we convert to radians
local x = pos.x, y = pos.y;
local x2 = x + 1.0 * cos(rad) - 25.0 * sin(rad); // we calculate
local y2 = y + 1.0 * sin(rad) + 25.0 * cos(rad);
return Vector( x2, y2, pos.z ); // return a vector
}
usage:
player.Pos = GetForwardPoint( FindVehicle(0) /* example */, FindVehicle(0).EulerAngle.z );
Here is a ramp system made by Juppi (http://forum.liberty-unleashed.co.uk/index.php/topic,398.0.html), but for LU (http://liberty-unleashed.co.uk/).
Take from there the needed info, but give credits for Juppi.
Quote from: Thijn on Feb 09, 2015, 07:07 PMMight give a bit more information: clicky (http://vcmp.liberty-unleashed.co.uk/forum/index.php?topic=2732.msg18616#msg18616)
Quote from: Shadow.// [Ka]Juppi's func from http://forum.liberty-unleashed.co.uk/index.php/topic,398.0.html
// ported to fit your needs
function GetForwardPoint( pos, angle ) // you must pass an angle in degrees
{
local rad = angle * PI / 180; // we convert to radians
local x = pos.x, y = pos.y;
local x2 = x + 1.0 * cos(rad) - 25.0 * sin(rad); // we calculate
local y2 = y + 1.0 * sin(rad) + 25.0 * cos(rad);
return Vector( x2, y2, pos.z ); // return a vector
}
usage:
player.Pos = GetForwardPoint( FindVehicle(0) /* example */, FindVehicle(0).EulerAngle.z );
But there's also something wrong...
(https://forum.vc-mp.org/proxy.php?request=http%3A%2F%2Fi59.tinypic.com%2F2l9poy8.jpg&hash=c9d67f5ebb4a754481b56c028b2d09c72e870173)
function GetForwardPoint( pos, angle )
{
local x = pos.x + 1.0 * cos(angle) - 25.0 * sin(angle)
local y = pos.y + 1.0 * sin(angle) + 25.0 * cos(angle);
return Vector( x, y, pos.z );
}
Don't pass player's angle to GetForwardPoint function while driving the vehicle, because only vehicle's angle is changed!
See my next post! (http://forum.vc-mp.org/?topic=252.msg1404#msg1404)
Quote from: Gudio on Feb 10, 2015, 10:12 AMThere is no point to pass an angle in degrees since 0.4 supports radians.
function GetForwardPoint( pos, angle )
{
local x = pos.x + 1.0 * cos(angle) - 25.0 * sin(angle)
local y = pos.y + 1.0 * sin(angle) + 25.0 * cos(angle);
return Vector( x, y, pos.z );
}
Don't pass player's angle to GetForwardPoint function while driving the vehicle, because only vehicle's angle is changed!
GetForwardPoint( vehicle.Pos, vehicle.EulerAngle.z );
I haven't tested it.
The same issue. :(
How are you using it?
Hey, I've written this function for you. Use it with updated (https://bitbucket.org/stormeus/0.4-squirrel/downloads) squirrel module, because previous module returns vehicle's rotation with wrong order.
function CVehicle::GetRadiansAngle()
{
local angle;
angle = ::asin( this.Rotation.z ) * 2;
return this.Rotation.w < 0 ? 3.14159 - angle : 6.28319 - angle;
}
Usage: GetForwardPoint( vehicle.Pos, vehicle.GetRadiansAngle() );
Hopefully it works well now.
Sounds good, Gudio.
We should be able to set the distance also. Add a parameter for that. :)
Off:
Quote from: Gudio on Feb 11, 2015, 09:28 PMHey, I've written this function for you. Use it with updated (https://bitbucket.org/stormeus/0.4-squirrel/downloads) squirrel module, because previous module returns vehicle's rotation with wrong order.
Please use the Server & Plugin Updates (http://forum.vc-mp.org/?board=4.0) board so it would easier for us to be updated with any changes to the modules. :(
@Fuzzie, I have no rights to create a topic there.
@sseebbyy, you can do that. Increase someting in GetForwardPoint function :>
Quote from: Gudio on Feb 11, 2015, 09:28 PMHey, I've written this function for you. Use it with updated (https://bitbucket.org/stormeus/0.4-squirrel/downloads) squirrel module, because previous module returns vehicle's rotation with wrong order.
function CVehicle::GetRadiansAngle()
{
local angle;
angle = ::asin( this.Rotation.z ) * 2;
return this.Rotation.w < 0 ? 3.14159 - angle : 6.28319 - angle;
}
Usage: GetForwardPoint( vehicle.Pos, vehicle.GetRadiansAngle() );
Hopefully it works well now.
This is right:
function GetRadiansAngle(Rotation)
{
local angle;
angle = ::asin( Rotation.z ) * -2;
return Rotation.w < 0 ? 3.14159 - angle : 6.28319 - angle;
}
wat
I suggest you to delete your post @ysc3839
Quote from: Gudio on Feb 12, 2015, 12:02 PMwat
I suggest you to delete your post @ysc3839
What's the matter?
You just edited my function that works fine too. "::" is useless in functions outside the class.
Quote from: Gudio on Feb 12, 2015, 06:47 PMYou just edited my function that works fine too. "::" is useless in functions outside the class.
Thanks!