Quantcast

Jump to content

» «
Photo

Need help with setting position ahead of current position in C++

2 replies to this topic
LetsPlayOrDy
  • LetsPlayOrDy

    I'm just different...

  • Members
  • Joined: 24 Aug 2013
  • None

#1

Posted 21 December 2013 - 04:31 AM Edited by LetsPlayOrDy, 21 December 2013 - 04:33 AM.

OK, I have been trying to get this to work for a while now. What I'm trying to do is just set a vehicle's position to a position just a couple of feet in front of me. Now, I have found a way to do this in C# with the following code: 

Vector3 newPos = Player.Character.Position + 3 * Player.Character.Direction;

But, I want to do this in C++. I have gone into the source code of .NET Scripthook to see what it does with the + and * operators, and how to get the direction of the player/car.

 

Here is the get direction code (that is put into a function by me):

Vector3 SpeedoThread::GetDirection(Ped ped)
{
f32 Heading;
GetCharHeading(ped, &Heading);
Heading = DegreeToRadian(Heading);
Vector3 res;
res.X = (float)-sin(Heading);
res.Y = (float)cos(Heading);
res.Z = 0.0f;
return res;
}

The DegreeToRadian function is just 

 

float SpeedoThread::DegreeToRadian(float degrees) {
return degrees * float(PI / 180.0);
}

 

With the + and * operators, all it does is take two Vectors, and add/multiply the x, y, and z members together. Now, in the C# code, the variable being added is not a Vector3, it is a integer (I'm talking about the 3). My only guess of how these two things are being added together is instead of adding the first Vector3's x, y, and z members to the second Vector3's, it just adds the integer to x and y.

 

When I try to use the code that is most like the C# code above, which is: 

void SpeedoThread::SetPositionAhead(Vehicle veh, int aheadamount){
f32 x, y, z;
GetCarCoordinates(veh, &x, &y, &z);
x = x + aheadamount * GetDirection(GetPlayerPed()).X;
y = y + aheadamount * GetDirection(GetPlayerPed()).Y;
SetCarCoordinates(veh, x, y, z);
}

I teleport to just random places or something. I really don't know what happens there, but it is not what happens when I do the same thing with C#.

 

Does anyone know how to do this (get a position just a few feet in front of you)? I would greatly appreciate any answers :)

 

Also, if you think this is put into the wrong section of this website, or put onto the wrong website totally, can you direct me to a better website for my question? Thanks :)


Skorpro
  • Skorpro

    GTAholic

  • Members
  • Joined: 19 Jul 2009
  • Germany

#2

Posted 24 December 2013 - 04:33 AM

Hi!

I think it's better to get player's offset of coords and his heading (w/o Vector3)...

Check THIS out :)

 

Merry Christmas and a Happy New Year! :D


LetsPlayOrDy
  • LetsPlayOrDy

    I'm just different...

  • Members
  • Joined: 24 Aug 2013
  • None

#3

Posted 27 December 2013 - 07:18 AM

Hi!

I think it's better to get player's offset of coords and his heading (w/o Vector3)...

Check THIS out :)

 

Merry Christmas and a Happy New Year! :D

 

Thanks dude :D

And late merry christmas to you too! :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users