Author Topic: Calculate the forward point  (Read 4112 times)

0 Members and 1 Guest are viewing this topic.

Offline NE.Restricted

  • Wiseguy
  • **
  • Posts: 97
    • View Profile
Calculate the forward point
« 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?
I am NE.CrystalBlue!!!
Quote
i cant able to understand

Offline heekz.shadow

  • LU testers
  • Made Man
  • *
  • Posts: 249
    • View Profile
Re: Calculate the forward point
« Reply #1 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
Code: [Select]
[20:23] <habi> later only i heard that lu chatbox is customizable. On my first visit, it appeared ugly.
[20:23] <habi> May be that also be the reason why lu has no players

Offline NE.Restricted

  • Wiseguy
  • **
  • Posts: 97
    • View Profile
Re: Calculate the forward point
« Reply #2 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).
I am NE.CrystalBlue!!!
Quote
i cant able to understand

Offline NE.Restricted

  • Wiseguy
  • **
  • Posts: 97
    • View Profile
Re: Calculate the forward point
« Reply #3 on: September 11, 2014, 01:49:51 pm »
Help!
I am NE.CrystalBlue!!!
Quote
i cant able to understand

Offline stormeus

  • VC:MP Developer
  • VC:MP Veteran
  • *
  • Posts: 1122
    • View Profile
Re: Calculate the forward point
« Reply #4 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.
Do not PM me for support.