OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: nominesine on 03 Feb 2005, 03:44:48
-
I want to teleport a unit named a1 to a position 500 meters behind the leader of a group named heroes. But I can't figure out the syntax for setPos. I know how to make the basic teleoprt to the same spot:
a1 setPos [getPos leader heroes select 0, getPos leader heroes select 1, 0]
As you can see a1 arrives on the exact location of leader heroes.
How do I make a1 appear 500 meters away from leader heroes (preferably behind, but it's not that important at the moment)?!?
-
_x = getPos leader heroes select 0
_y = getPos leader heroes select 1
_lead = leader heroes
a1 setPos [_x - 500*sin(getdir _lead), _y - 500*cos(getdir _lead), 0]
might do it.
-
Thanks, it looks as if it might work. But I would like to trigger the effect from a waypoint. I know there's a syntax usable as a single line in a trigger or wp, because I used it once in another mission, but now I canÂ't get it to work and I can't find the other mission. What's the syntax to use in a trigger or wp?
-
brackets are what you want sir, good ole brackets.
a1 setPos [(getPos leader heroes select 0) +/- x_offset , (getPos leader heroes select 1) +/- y_offset, 0]
just to explain a wee bit, the x_offset is positive if it's to the right of your target unit, negative if it's to the left.
similarly, y_offset is positive when it's in front, negative when it's behind.
so for 500 meters behind the leader of the group heroes -
a1 setPos [getPos leader heroes select 0 , (getPos leader heroes select 1) -500, 0]
EDIT - note, i'm not quite sure if that's left/right according to east/west of the map, or according to which direction the target loon is facing....
-
The select 0 is east-west on the map and select 1 is north-south.
To find the coordinates of a point in front of or to the side of an object
if:
x1,y1 are the coordinates of the object
theta is the direction of the object
d is the distance of the point from the object
then:
For a point in front of the object
X coordinate = x1 + d*sin(theta)
y coordinate = y1 + d*cos(theta)
(for a point behind use -d or theta + 180)
For a point to the right of the object
X coordinate = x1 + d*cos(theta)
y coordinate = y1 - d*sin(theta)
(for a point to the left use -d or theta + 180)
-
hmmmm, i'd been wondering for a while how to do just that.
bedges cuts n pastes into his "useful stuff" folder ;)
thankyou sir.
-
Thanks bedges. Thanks THobson. Exactly what I needed to know.