Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: ysc3839 on Feb 09, 2015, 04:06 PM

Title: How to calculate the pos in front of player's vehicle?
Post by: ysc3839 on Feb 09, 2015, 04:06 PM
I want to spawn a ramp in front of player's vehicle. Can somebody tell me how to calculate the pos? Thanks! :)
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: DizzasTeR on Feb 09, 2015, 04:56 PM
Also trying to figure this out but can't for some reason the object doesnt appear when i touch its pos.

Title: Re: How to calculate the pos in front of player's vehicle?
Post by: Thijn on Feb 09, 2015, 05:22 PM
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);
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: DizzasTeR on Feb 09, 2015, 05:27 PM
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.
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: Thijn on Feb 09, 2015, 07:07 PM
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 );
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: Sebastian on Feb 09, 2015, 09:12 PM
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.
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: ysc3839 on Feb 10, 2015, 08:29 AM
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)
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: Gudio on Feb 10, 2015, 10:12 AM
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)
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: ysc3839 on Feb 11, 2015, 02:45 PM
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. :(
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: Thijn on Feb 11, 2015, 06:05 PM
How are you using it?
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: Gudio on Feb 11, 2015, 09:28 PM
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.
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: Sebastian on Feb 11, 2015, 10:27 PM
Sounds good, Gudio.
We should be able to set the distance also. Add a parameter for that. :)
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: Fuzzie on Feb 12, 2015, 07:19 AM
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. :(
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: Gudio on Feb 12, 2015, 09:41 AM
@Fuzzie, I have no rights to create a topic there.
@sseebbyy, you can do that. Increase someting in GetForwardPoint function :>
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: ysc3839 on Feb 12, 2015, 11:14 AM
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;
}
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: Gudio on Feb 12, 2015, 12:02 PM
wat
I suggest you to delete your post @ysc3839
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: ysc3839 on Feb 12, 2015, 12:45 PM
Quote from: Gudio on Feb 12, 2015, 12:02 PMwat
I suggest you to delete your post @ysc3839
What's the matter?
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: Gudio on Feb 12, 2015, 06:47 PM
You just edited my function that works fine too. "::" is useless in functions outside the class.
Title: Re: How to calculate the pos in front of player's vehicle?
Post by: ysc3839 on Feb 13, 2015, 08:40 AM
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!