Home   Help Search Login Register  

Author Topic: Positioning on a specific side  (Read 1189 times)

0 Members and 1 Guest are viewing this topic.

Offline Rellikki

  • Members
  • *
  • Die-hard OFP player
Positioning on a specific side
« on: 18 Jun 2009, 20:14:22 »
Let's imagine that I have an object, a road for example, which will every time have a different spawning position and a direction. I was wondering if it's possible to spawn another object, which would always be next to the road on a specific side? This would be of course piece of cake with a simple, basic setPos command, if the road was always facing the same direction, but that wouldn't always be right, because of the random direction of the road. I hope you know what I mean.
So as I asked, is it possible to spawn the another object always on a specific side of the road, regardless of the road's angle?

Edit: Here's two pictures of what I had in mind for better understanding. 4 different examples in each of the pictures. The orange arrow resembles the road and its random direction and the green dot resembles the other object which I want to be on the specific side.

Notice how in the first picture the green dot is always on the same side from the road's angle. That's how I want it to be.



However, this happens with just a simple setPos command, which I don't want to happen:

« Last Edit: 20 Jun 2009, 15:24:05 by Rellikki »

Offline eegore

  • Members
  • *
Re: Positioning on a specific side
« Reply #1 on: 20 Jun 2009, 03:02:38 »

  Trust me Im no genius on this stuff but I would play with a "dowatch" command and coordinnate that with a "deletevehicle" command. 

  Im not sure how you are placing a stretch of road but if you have an object placed ahead on the road then you could have a soldier unit look at the object immediately, then have a trig delete him with a time of "2".

  Then I would use a setpos command for an item to his right after 1 second.

  This would have the soldier appear on the road, and look down the road at initialization.  Then the object you need to appear would show up after 1 second, (to his right) then the soldier gets deleted another second later.


  Truthfully I have no idea if this would work, and I have no idea how the roadway is random in direction but maybe those commands will help?

 

Offline Rellikki

  • Members
  • *
  • Die-hard OFP player
Re: Positioning on a specific side
« Reply #2 on: 20 Jun 2009, 15:21:18 »
I'm not really sure what you mean by that. ??? What's the soldier for?

Quote
Im not sure how you are placing a stretch of road
I'm using an editor update to place roads. ;) The random direction of it is made with a script, but that's another story...

Quote
Then I would use a setpos command for an item to his right after 1 second.
Well, the problem here is that I don't know how to return a specific side of an object from its angle...

Offline dr. seltsam

  • Members
  • *
Re: Positioning on a specific side
« Reply #3 on: 21 Jun 2009, 13:21:30 »
Easy solution:

Place.sqs
Code: [Select]
_obj1 = _this select 0
_obj2 = _this select 1
_ang  = _this select 2
_dis  = _this select 3
_h    = _this select 4

_p=getpos _obj1
_d=getdir _obj1
_a=_d+_ang
_r=[(_p select 0)+_dis*sin _a,(_p select 1)+_dis*cos _a,(_p select 2)+_h]
? local _obj2 : _obj2 setpos _r
exit

Now execute this file with the following parameters:

[first_object,second_object,relative_angle,relative_distance,relative_height] exec "Place.sqs"

first_object:               Is the object that is used as center, your roadway
second_object:           Is the object that should be placed relative to the first, after spawning of course
relative_angle:            For the right side use 90, for left use -90 or 270, or any other desired value
relative_distance:       The distance object2 should have to object1
relative_height:          The relative height, mostly 0

[road1,car7,90,2,0] exec "Place.sqs"

will place car7 to the right side of road1 in a distance of 2m and at the same height as road1...
If the calculation of the height of object1 brings up an unexpected value, play a bit with the input parameter until object2 shows up at the desired height.
:)

Offline Rellikki

  • Members
  • *
  • Die-hard OFP player
Re: Positioning on a specific side
« Reply #4 on: 30 Jun 2009, 10:20:16 »
Sorry for the late reply.
I just tried that out and it seems to work all fine, so thanks. :)