• 🏆 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!

Camera Rotation

Status
Not open for further replies.
Level 37
Joined
Aug 14, 2006
Messages
7,601
Hey,

I have one very simply thing my brains can't handle.

This trigger moves the game camera pretty much randomly. I just want it to go right or was it left? Anyway you get the idea. Why does it give random rotations?

  • Look Right
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to YRight (CAMERA PANEL)
    • Actions
      • Camera - Set Player 1 (Red)'s camera Rotation to ((Rotation of the current camera view) + 22.50) over 1.00 seconds
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
I don't see anything particularly wrong with it.

What can happen is that it starts going mad if you've done a full 360 degree rotation.

The best would be to save the current rotation in a variable, change that variable, and set rotation to it.

Right - negative
Left - positive

90 degrees - north
180 degrees - west
0 degrees - east
270 - south
 
You need to use the modulo whenever you add or substract to an angle. The modulo returns the remainder of an equation. Example:

JASS:
set rotation = ModuloReal(rotation+20, 360)

This will return the rotation as a value between 0 and 360, but you can do it with any divisor. For instance, ModuloInt(x, 2) == 0 will return wether a number is even or odd (odd numbers will be 1 while even numbers will be 0). I am sure the modulo function also exists in GUI.

A second option is to use a variable approach:

set [rotation] to [rotation]+20

JASS:
if [rotation] > 360 then
    set [rotation] = [rotation]-360
elseif [rotation] < 0 then
    set [rotation] = [rotation]+360 
endif

This method is not as safe though and will glitch slightly if you add or substract a number larger than 360. You can solve this by using a loop that continiously adds or substracts 360 while the angle is out of bounds (larger than 360 or smaller than 0). Kinda overcomplicated when you know how to use the modulo, though.
 
Status
Not open for further replies.
Top