• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

A problem to do with Angles

Status
Not open for further replies.
Level 3
Joined
Jun 14, 2007
Messages
56
Hi gents.

Simple problem here;
I want to have a unit slowly rotate, at a constant speed, to face the way the controlling player clicks

The idea is that it is not a one off thing, rather something that will constantly update in the main looping trigger.

the looped script cannot be something as simple as this:
  • Unit - Make unit face point over 2.0 seconds
as it wouldnt be a constant rate of change, a full 180 degree turn would take as long as a simple 5 degree turn


furthermore it cannot be something like this:
JASS:
local real direction
local real angle = AngleBetweenPoints(unit, target)
if angle > direction  then
     set direction = direction + 10
else 
     set direction = direction - 10
endif
call UnitFaceAngle(unit, direction)
as angles are clamped between 0 and 360. If you are facing angle 10 and you click angle 350 then it would go all the way around turning left, instead of turning right which is closest.

So what is an easy, clean way of making a unit choose to either start rotating left or rotating right to eventually be facing the same direction as has been ordered?

Help is much appreciated.
Matt
 
Level 14
Joined
Aug 31, 2009
Messages
775
An easier way would be to give the unit a movement speed (temporarily or permanently depending on what you're actually aiming to achieve here) of 1. You will need to edit the Gameplay Constants though to allow such a small movement speed as I think the default minimum is something like 150.

When you right click, the unit will attempt to move to that location, and in doing so, will have to turn to face that way - though it won't get particularly far with just a movement speed of 1. Then you can use a trigger to cancel that movement order afterwards just to make sure.
 
Level 3
Joined
Jun 14, 2007
Messages
56
Hey dude, thanks for your reply man.

In this case, this part of coding was actually just a small part of a more complex system that simulates realistic car movement. And it was also for starcraft 2's editor

But yeah your approach worked fine! I hadn't considered using the units own turn rate and the 1 move speed doesn't seem to cause any problems. Swt as!
 
Level 9
Joined
Oct 11, 2009
Messages
477
If you want a unit to face a unit/point, then reduce its animation speed like this;
  • Slow Animation Trigger
    • Events
    • Conditions
    • Actions
      • Animation - Change YOUR UNIT's animation speed to SPEED%
For the facing part, use periodic trigger(s) and update the unit's facing angle by 36.00 every 0.1 second(s).

*360.00 angle/second = 36.00 angle/0.1 second(s)*
 
Status
Not open for further replies.
Top