Vice City Multiplayer

VC:MP 0.4 (Beta) => Script Discussion => Topic started by: NE.Restricted on September 10, 2014, 10:21:35 pm

Title: Calculate the forward point
Post by: NE.Restricted on September 10, 2014, 10:21:35 pm
I would like to calculate the forward point from an object.
For example a car object is 120 degrees (rotated) so a function which when I want to move it forward by 1 point, I would write:
whatever(startingpointx,spy,spz,angleofobject,amounttomoveforward);
Anyone knows how it is done?
Title: Re: Calculate the forward point
Post by: heekz.shadow on September 10, 2014, 10:41:26 pm
Quote
Code: [Select]
// [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:

Code: [Select]
player.Pos = GetForwardPoint( FindVehicle(0) /* example */, FindVehicle(0).EulerAngle.z );

You can modify it to your needs, it's from the unofficial forum
Title: Re: Calculate the forward point
Post by: NE.Restricted on September 10, 2014, 11:00:05 pm
Quote
Code: [Select]
// [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:

Code: [Select]
player.Pos = GetForwardPoint( FindVehicle(0) /* example */, FindVehicle(0).EulerAngle.z );

You can modify it to your needs, it's from the unofficial forum
Well how to specify how many points forward? I need this to make my plane and UFO in my server (and custom vehicles).
Title: Re: Calculate the forward point
Post by: NE.Restricted on September 11, 2014, 01:49:51 pm
Help!
Title: Re: Calculate the forward point
Post by: stormeus on September 11, 2014, 06:14:15 pm
Quote
Code: [Select]
// [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:

Code: [Select]
player.Pos = GetForwardPoint( FindVehicle(0) /* example */, FindVehicle(0).EulerAngle.z );

You can modify it to your needs, it's from the unofficial forum
Well how to specify how many points forward? I need this to make my plane and UFO in my server (and custom vehicles).

Modify the 25.0 constants to however many X/Y units you want, and if you need to spawn something overhead just change the Z field of the Vector.