Home   Help Search Login Register  

Author Topic: how do i make one unit turn and face another?  (Read 2437 times)

0 Members and 1 Guest are viewing this topic.

Offline DurbanPoison

  • Members
  • *
how do i make one unit turn and face another?
« on: 11 Jun 2011, 23:45:49 »
hi there,

I did a search but couldn't find the specific thing im looking for so am gonna ask for help :P

I have a 1v1 mission where each player tries to reach the other side and touch a flag to win a point.
I have randomly added a few animations when one player reaches the flag and scores.. ie. he'll do a handstand.

When this anim happens the other player claps his hands above his head...  only problem is he is ususally facing a different direction! so is there anyway to have a player controlled unit turn and face the other player?
i am noobish with script so tried dowatch and setdir but these don't seem to do what im trying to do!

any ideas? and thanks :)

Offline B2KDragon

  • Members
  • *
    • Dogs of War
Re: how do i make one unit turn and face another?
« Reply #1 on: 11 Jun 2011, 23:49:37 »
Are these units AI, or is this part of a cutscene?

I know how to do it for AI, but apart from that. I am not to sure to be honest.

Offline DurbanPoison

  • Members
  • *
Re: how do i make one unit turn and face another?
« Reply #2 on: 12 Jun 2011, 02:24:06 »
Yes, it's part of a brief cut scene that plays each time someone scores

Offline F2kSel

  • Members
  • *
Re: how do i make one unit turn and face another?
« Reply #3 on: 12 Jun 2011, 14:02:17 »
What part of setdir doesn't work, it will set a player in the direction you choose or do you mean it looks bad as it's done instantly?

Offline DeanosBeano

  • Addons Depot Staff
  • *****
  • SirDeanosbeano bstowed on me by sui ;)
    • Fraghaus
Re: how do i make one unit turn and face another?
« Reply #4 on: 12 Jun 2011, 16:22:05 »
 you can use SetDir, remember  to blank out while you set them or  have camera slowoly move in from away ,

 setDir soldier 1 too so you can calculate where soldier 2 needs to face  for example if soldier 1 is facing 90 then soldier 2 needs to face 270 so there staring at eachother .

 
« Last Edit: 13 Jun 2011, 21:32:43 by DeanosBeano »
I love ofp

Offline Zipper5

  • BIS Team
  • ****
Re: how do i make one unit turn and face another?
« Reply #5 on: 12 Jun 2011, 16:35:46 »
There are a couple ways you can accomplish this:
Code: [Select]
turningUnit reveal targetUnit; turningUnit doWatch targetUnit; turningUnit lookAt targetUnitIf you can measure the angle that the unit has to turn through in order to be directly facing the target unit, you can do a setDir loop so that the turning is smooth. You will have to disable the "MOVE" part of the AI as in Arma 2 they will go back to where they were originally facing after using setDir. So, you can do something like this if the angle is 45 degrees:
Code: [Select]
turningUnit disableAI "MOVE";
_startDir = getDir turningUnit;
_endDir = 0;
while {_endDir != 45} do {
_endDir = _endDir + 1;
turningUnit setDir (_startDir + _endDir);
sleep 0.05;
};
That will turn him 45 degrees smoothly to the right. Change it to (_startDir - _endDir) to turn him to the left. Increase the delay and decrease the amount _endDir increases by to make it slower. Hope that helps!
« Last Edit: 12 Jun 2011, 17:24:56 by Zipper5 »