Home   Help Search Login Register  

Author Topic: setPos syntax  (Read 558 times)

0 Members and 1 Guest are viewing this topic.

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
setPos syntax
« 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)?!?
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline Fragorl

  • Coding Team
  • Former Staff
  • ****
Re:setPos syntax
« Reply #1 on: 03 Feb 2005, 04:01:44 »
_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.

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re:setPos syntax
« Reply #2 on: 03 Feb 2005, 09:41:27 »
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?
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:setPos syntax
« Reply #3 on: 03 Feb 2005, 10:04:07 »
brackets are what you want sir, good ole brackets.

Code: [Select]
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 -

Code: [Select]
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....
« Last Edit: 03 Feb 2005, 10:07:08 by bedges »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:setPos syntax
« Reply #4 on: 03 Feb 2005, 10:20:43 »
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)
« Last Edit: 03 Feb 2005, 10:21:27 by THobson »

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:setPos syntax
« Reply #5 on: 03 Feb 2005, 10:24:57 »
hmmmm, i'd been wondering for a while how to do just that.

bedges cuts n pastes into his "useful stuff" folder ;)

thankyou sir.

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re:setPos syntax
« Reply #6 on: 03 Feb 2005, 10:32:03 »
Thanks bedges. Thanks THobson. Exactly what I needed to know.
OFPEC | Intel Depot
RETARDED Ooops... Retired!