floatsin floatcos

Started by BeckzyBoi, Jun 25, 2018, 10:11 PM

Previous topic - Next topic

BeckzyBoi

Do such functions exist in Squirrel? I need them to get a position directly infront of a player using the player's facing angle.

P.S. I am not a newbie around here. I've been a guest for many years. I have been unable to register for as long as I can remember. IDK what made me try again today - but it worked! Hallelujah?

BeckzyBoi

local x, y;
x = player.Pos.x + sin(player.Angle) * 5.0;
y = player.Pos.y + cos(player.Angle) * 5.0;

What am I doing wrong? The result is never a position in front of me.

ysc3839

#2
@BeckzyBoi #2 You may need this.
https://forum.vc-mp.org/?topic=252.msg1384#msg1384


Just change your code to:
local x, y;
x = player.Pos.x + cos(player.Angle) * 5.0;
y = player.Pos.y + sin(player.Angle) * 5.0;

BeckzyBoi

#3
Quote from: ysc3839 on Jun 25, 2018, 10:59 PM@BeckzyBoi #2 You may need this.
https://forum.vc-mp.org/?topic=252.msg1384#msg1384


Just change your code to:
local x, y;
x = player.Pos.x + cos(player.Angle) * 5.0;
y = player.Pos.y + sin(player.Angle) * 5.0;

That finds the position to the right of me, not in front. I need to be able to determin the a position so far infront of me.

Edit:

function RadtoDeg( radian )
{
return radian * 57.2958;
}

I've used that to change the VC radian angle to degrees, and it's still not getting the position in front of me.

Saiyan Attack

function GetForwardPoint( pos, gap, angle )
{
  local x = pos.x + 1.0 * cos(angle) - gap * sin(angle)
  local y = pos.y + 1.0 * sin(angle) + gap * cos(angle);
  return  Vector(x.tofloat(), y.tofloat(), pos.z.tofloat());
}

Usage: GetForwardPoint(veh.Pos, /* distance between you and your object*/ 25.0,player.Angle);

BeckzyBoi

Thanks for your reply Saiyan Attack. Looking at your code I believe it will work - that is only because someone has already sent me a very similar snippet in a PM. They're extremely similar and probably both work. Thanks

Edit: This topic can be locked now (however you wish)

umar4911

Quote from: BeckzyBoi on Jun 26, 2018, 01:28 AMThanks for your reply Saiyan Attack. Looking at your code I believe it will work - that is only because someone has already sent me a very similar snippet in a PM. They're extremely similar and probably both work. Thanks

Edit: This topic can be locked now (however you wish)
You and admins can mark this topic as solved and lock it.
RT Member | Asian City Scripter | CTB Contributor | VKs Contributor | European City Contributor | EAD Scripter