Jump to content
Sign in to follow this  
By-Jokese

Spawning object in front of player.

Recommended Posts

I have coded this simple scripts, that should place an object (var name "_object"), 1 meter away from the player in the same direction he is facing.

_pos = getPosATL _unit;
_azimuth = getDir _unit;
_far = 1; //Distance from the player to the _object

_x = (_pos select 0) + (_far * (cos _azimuth));
_y = (_pos select 1) + (_far * (sin _azimuth));

_obj = createVehicle [_object, [_x, _y, (_pos select 2)], [], 0, 'CAN_COLLIDE'];

I have used that technique on many other sites, but cant make it work in Arma... The object keeps spawning where it wants.... (Not random location but depending where you are facing it has 2-3 different locations where it spawns)...

Can any help?

Share this post


Link to post
Share on other sites

All directions used ingame works of compass direction (0 = North, 90=east) 

which is not technically mathematically "correct". Switching sin and cos around in your code should do it. 

 

There are multiple commands to help with this conversion, such as getPos (see alternative syntax)

Share this post


Link to post
Share on other sites

@By-Jokese

Also make sure to check out the BIS function library which contains a bunch of handy functions for geometry (dirTo, relPos, ...) and vector maths (vectorMultiply, vectorAdd, crossProduct, dotProduct, rotateVector2D, ...). :don16:

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×