SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 03/01/2019, 11:29 AM   #1
aKnoxx
Big Clucker
 
aKnoxx's Avatar
 
Join Date: Dec 2018
Location: United States Discord: ABC#6701
Posts: 76
Reputation: 0
Default How can I get the x y z pos of the BACK/FRONT of something?

Say I want to make a cmd to put an object IN FRONT of a player. Or spawn a vehicle IN FRONT of a player. How do I do that?

When I do it like this:

GetPlayerPos(playerid, x, y, z);

And then do

x +2, y, z

It spawns it +2 x. And then when I do +3 y, it spawns it +3 y, ect. I can't figure out how to make it spawn in front of me. I'd assume it has something to do with math and your facing angle but I can't figure out how to do it. How can I do something like that?

Last edited by aKnoxx; 03/01/2019 at 06:15 PM.
aKnoxx is offline   Reply With Quote
Old 03/01/2019, 12:01 PM   #2
beckzy
Beta Tester
 
Join Date: Dec 2006
Posts: 1,234
Reputation: 159
Default Re: How can I get the x y z pos of the BACK/FRONT of something?

Get the X and Y 2 units in front of a player:
Code:
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
x += floatsin(-a, degrees) * 2.0;
y += floatcos(-a, degrees) * 2.0;
Get the X and Y 2 units behind a player:
Code:
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x, y, z);
GetPlayerFacingAngle(playerid, a);
a = a < 180.0 ? a + 180.0 : a - 180.0;
x += floatsin(-a, degrees) * 2.0;
y += floatcos(-a, degrees) * 2.0;
__________________
beckzy is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Map] Idlewood House (interior included, front & back yard !) TudorTudy23 Maps 4 26/11/2014 08:54 PM
[GameMode] Modern War Battalation V2.8| Back to Back release after 8 months | 3500+ Lines | New CMDS | Radio System | Admin System Nirzor Gamemode Scripts 40 30/07/2013 07:09 AM
[GameMode] Modern War Battalation | V2.7 | Back To Back Release | 50+ Commands | 3500+ Lines | Admin System Attached Nirzor Gamemode Scripts 36 08/06/2013 04:27 PM
BF3 Front Yves Everything and Nothing 9 05/03/2013 11:25 AM
[HELP] Front Name martin3644 Scripting Help 6 06/02/2013 09:30 PM


All times are GMT. The time now is 06:25 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.