Jump to content
🛡️FORUMS ARE IN READ-ONLY MODE Read more... ×
Sign in to follow this  
fail2ban

Direction of unit during animation

Recommended Posts

Hi there,

I am kinda lost atm. I have read a lot of posts about animations and directions, but nothing seem to do the trick.

I am using animations on units and it looks like the animations have a default direction. No matter in which direction I place a unit, it will turn into the preset direction of the animation.

I have tried doWatch, lookAt and setFormDir. While doWatch and lookAt makes the unit look at a certain point, it won't move their bodies in the right direction. I have even tried to attach the unit to an empty helipad and turn the helipad. That works by the way, but once a unit is attached to an object, the animations won't be as smooth as normal.

I am running out of ideas. Any suggestions will be great. Thx in advance.

---------- Post added at 16:29 ---------- Previous post was at 15:48 ----------

Never mind, I think I have finally got a solution. I have tried to point the units to an opposite unit by doing something like

unitA doWatch unitB;

It looks like both units are too close together (1m) and therefor the enigne does not do the right move.

If I use a position with higher numbers instead like

unitA doWatch [9000,9000];

it works. Still strange and a lot of trial and error to get it right.

If one of you knows a better solution, I'll be happy to hear it.

Share this post


Link to post
Share on other sites

You can try getting the relative direction manually (with atan2), here's a simple test-case that works ok for me -

Just place a player-unit and a second unit, name the second unit unit2. Put in the player unit's init:

0 = this spawn {
    _pos1=position _this;
    _pos2=position unit2;
    _dir=((_pos2 select 0) - (_pos1 select 0)) atan2 ((_pos2 select 1) - (_pos1 select 1));
    _this setDir _dir;
    sleep 1;
    _this playMoveNow "ActsPercMrunSlowWrflDf_FlipFlopPara";
};

Share this post


Link to post
Share on other sites

Thx for the reply. Your tip works great with the player unit, but not the other way round. It won't change the direction of the AI unit.

Let me say you spawn two units, neither of it is the player, the units will not take care whatever you have put in setDir.

---------- Post added at 17:38 ---------- Previous post was at 17:22 ----------

I've got your example working, but instead of setDir I am using setFormDir. This will allow both units to look at each other and also rotate the body in the right direction.

Strange thing: it works only for animations that can be played with playMove, while switchMove animations do not seem to take care about the direction. I can still do the absolute positions mentioned above for the switchMove units, but if I'll find a more generic approach, that'll be great.

Share this post


Link to post
Share on other sites

Replacing

_this setDir _dir;

with

group _this setFormDir _dir;

made the unit do the move correctly unless he was in a group. Otherwise I needed to add doStop _this; right after the setFormDir line. However, this will change the direction of the group, which may be unwanted; you could temporarily make the unit leave the group ([_this] joinSilent grpNull;) and later return him if it won't break anything in the particular situation. In my tests the unit did the move at an offset though, so I needed to adjust the dir accordingly (in my particular case +20 degrees when not in a group and -30 degrees with the doStop; regardless of initial group direction, possibly dependent on the used formation (he was doing the move towards a unit in the same group)).

EDIT: Didn't notice your edit before posting.

Edited by geqqo

Share this post


Link to post
Share on other sites
Sign in to follow this  

×