Arrow Key movement with camera rotation

vonDarkmoor

New Member
Reaction score
9
Ok so i got a map that has the Camera Following a unit from behind and close up. as the unit runs around the camera rotates with the unit staying on the back, using the following code:

Trigger:
  • Camera
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Camera - Pan camera for Player 1 (Red) to (Position of YOU 0000 <gen>) over 0.00 seconds
      • Camera - Set Player 1 (Red)'s camera Rotation to (Facing of YOU 0000 <gen>) over 0.00 seconds
      • Camera - Set Player 1 (Red)'s camera Angle of attack to 330.00 over 0.00 seconds
      • Camera - Set Player 1 (Red)'s camera Field of view to 70.00 over 0.00 seconds
      • Camera - Set Player 1 (Red)'s camera Distance to target to 400.00 over 0.00 seconds
      • Camera - Set Player 1 (Red)'s camera Height Offset to 150.00 over 0.00 seconds
      • Camera - Lock camera target for Player 1 (Red) to YOU 0000 <gen>, offset by (0.00, 0.00) using The unit's rotation


This part works fine as far as i know. YOU 0000 <gen> is the unit.

The part i am having trouble with is the arrow key movement, the forward works fine with :

Trigger:
  • Start Up Movement
    • Events
      • Player - Player 1 (Red) Presses the Up Arrow key
    • Conditions
    • Actions
      • Trigger - Turn on Up Movement &lt;gen&gt;

+
Trigger:
  • Up Movement
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Unit - Order YOU 0000 &lt;gen&gt; to Move To ((Position of YOU 0000 &lt;gen&gt;) offset by 100.00 towards (Facing of YOU 0000 &lt;gen&gt;) degrees)

+
Trigger:
  • End Up Movement
    • Events
      • Player - Player 1 (Red) Releases the Up Arrow key
    • Conditions
    • Actions
      • Trigger - Turn off Up Movement &lt;gen&gt;


Now i tried to use this same method for the rotation. I want the Left and Right arrow keys to rotate the unit. I couldnt find any "Rotate Unit" function so i order the unit to move to a position to the units right based on the units facing angle with the movement distance being ordered equal to 0. so the units turns toward the direction its ordered to turn then moves 0.

However the problem i am having is the unit will only move to the right and wont turn past a facing angle of 0. Here is the code.


I use the same Trigger-Turn on/off Triggers as with the forward movement.

Trigger:
  • Right Turn
    • Events
      • Time - Every 0.05 seconds of game time
    • Conditions
    • Actions
      • Set Unit_Angle = (Facing of YOU 0000 &lt;gen&gt;)
      • Unit - Order YOU 0000 &lt;gen&gt; to Move To ((Position of YOU 0000 &lt;gen&gt;) offset by 0.00 towards (Unit_Angle - 1.00) degrees)
      • Game - Display to (All players) the text: (String(Unit_Angle))


I use the same code for Left turn except i did
Trigger:
  • Unit - Order YOU 0000 &lt;gen&gt; to Move To ((Position of YOU 0000 &lt;gen&gt;) offset by 0.00 towards (Unit_Angle + 1.00) degrees)


The text display is just for testing to show me what angle its facing, whats happening is regardless of whether i press the Left or Right Arrow Key the unit turns to the Right and the Angle will subtract to 0 then the Unit stops moving even if i continue to press the Left or Right Arrow Key.

I tried adding :
Trigger:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • Unit_Angle Equal to 0.00
    • Then - Actions
      • Set Unit_Angle = 360.00
    • Else - Actions

But the unit would still not move and all that changed was the Text displayed now said 360 instead of 0.

I know there are going to be a lot of leaks with this system, i am just learning about leaks and once i get a system that works, ill go back and alter it to remove the memory leaks.

Also i did do a search for unit movement with arrow Keys, but i couldn't' find one that dealt with rotating a unit with arrow Keys.

Any Help would be greatly appreciated.
 

W!†A_cRaft

Ultra Cool Member
Reaction score
28
there are already systems that allow you to use movement and camera tracking made by some "more experienced" people, so to say.

I would suggest using one of them. Specially since they even cover that "omg the tree is in my view" kind of scenes.
 

vonDarkmoor

New Member
Reaction score
9
Do you know where i could find them? I tried searching the forums but i have very low searching skills.
 

vonDarkmoor

New Member
Reaction score
9
Thats not quite right, i need it to automatically follow the angle of the unit and be locked. i dont want the camera moving unless the unit moves, and i want it locked to the back of the unit at a particular distance and vertical angle
 

KJP

New Member
Reaction score
5
Dont know whether these will help, or is even what you want,

Trigger:
  • Press Left Arrow
    • Events
      • Player - Player 1 (Red) Presses the Left Arrow key
    • Conditions
    • Actions
      • Set Mov_KeyPress[0] = True

Trigger:
  • Press Up Arrow
    • Events
      • Player - Player 1 (Red) Presses the Up Arrow key
    • Conditions
    • Actions
      • Set Mov_KeyPress[1] = True

Trigger:
  • Press Right Arrow
    • Events
      • Player - Player 1 (Red) Presses the Right Arrow key
    • Conditions
    • Actions
      • Set Mov_KeyPress[2] = True

Trigger:
  • Release Left Arrow
    • Events
      • Player - Player 1 (Red) Releases the Left Arrow key
    • Conditions
    • Actions
      • Set Mov_KeyPress[0] = False

Trigger:
  • Release Up Arrow
    • Events
      • Player - Player 1 (Red) Releases the Up Arrow key
    • Conditions
    • Actions
      • Set Mov_KeyPress[1] = False

Trigger:
  • Release Right Arrow
    • Events
      • Player - Player 1 (Red) Releases the Right Arrow key
    • Conditions
    • Actions
      • Set Mov_KeyPress[2] = False

Trigger:
  • foward
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Set Unit_Avatarfacing = (Facing of Unit_Avatar)
      • Set Mov_TargetDest = (Position of Unit_Avatar)
      • Set Mov_TempX = (X of Mov_TargetDest)
      • Set Mov_TempY = (Y of Mov_TargetDest)
      • -------- Check Up arrow is pressed = not true --------
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Mov_KeyPress[1] Not equal to True
        • Then - Actions
          • -------- Check left arrow is pressed --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Mov_KeyPress[0] Equal to True
            • Then - Actions
              • Set Unit_Avatarfacing = (Unit_Avatarfacing + 20.00)
              • Unit - Make Unit_Avatar face Unit_Avatarfacing over 0.00 seconds
              • Custom script: call RemoveLocation (udg_Mov_TargetDest)
            • Else - Actions
              • -------- Check Right arrow is pressed --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Mov_KeyPress[2] Equal to True
                • Then - Actions
                  • Set Unit_Avatarfacing = (Unit_Avatarfacing - 20.00)
                  • Unit - Make Unit_Avatar face Unit_Avatarfacing over 0.00 seconds
                  • Custom script: call RemoveLocation (udg_Mov_TargetDest)
                • Else - Actions
                  • Custom script: call RemoveLocation (udg_Mov_TargetDest)
        • Else - Actions
          • -------- Up arrow is pressed = true --------
          • -------- Check left arrow is pressed = true --------
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Mov_KeyPress[0] Equal to True
            • Then - Actions
              • Set Unit_Avatarfacing = (Unit_Avatarfacing + 8.00)
              • Set Mov_TempY = (Mov_TempY + (Mov_MoveDistance x (Sin(Unit_Avatarfacing))))
              • Set Mov_TempX = (Mov_TempX + (Mov_MoveDistance x (Cos(Unit_Avatarfacing))))
            • Else - Actions
              • -------- Check Right arrow is pressed = true --------
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Mov_KeyPress[2] Equal to True
                • Then - Actions
                  • Set Unit_Avatarfacing = (Unit_Avatarfacing - 8.00)
                  • Set Mov_TempY = (Mov_TempY + (Mov_MoveDistance x (Sin(Unit_Avatarfacing))))
                  • Set Mov_TempX = (Mov_TempX + (Mov_MoveDistance x (Cos(Unit_Avatarfacing))))
                • Else - Actions
                  • -------- Set avatar move forward distance --------
                  • Set Mov_TempY = (Mov_TempY + (Mov_MoveDistance x (Sin(Unit_Avatarfacing))))
                  • Set Mov_TempX = (Mov_TempX + (Mov_MoveDistance x (Cos(Unit_Avatarfacing))))
          • If (Mov_TempY Greater than (Max Y of Movement area &lt;gen&gt;)) then do (Set Mov_TempY = (Max Y of Movement area &lt;gen&gt;)) else do (Do nothing)
          • If (Mov_TempY Less than (Min Y of Movement area &lt;gen&gt;)) then do (Set Mov_TempY = (Min Y of Movement area &lt;gen&gt;)) else do (Do nothing)
          • If (Mov_TempX Greater than (Max X of Movement area &lt;gen&gt;)) then do (Set Mov_TempX = (Max X of Movement area &lt;gen&gt;)) else do (Do nothing)
          • If (Mov_TempX Less than (Min X of Movement area &lt;gen&gt;)) then do (Set Mov_TempX = (Min X of Movement area &lt;gen&gt;)) else do (Do nothing)
          • Set Mov_TargetDest = (Point(Mov_TempX, Mov_TempY))
          • Unit - Order Unit_Avatar to Move To Mov_TargetDest
          • Custom script: call RemoveLocation (udg_Mov_TargetDest)


Movement area is a region pretty much the size of the map, with the if then else statements enforcing movement. Mov_KeyPress[] is a bolean array

Trigger:
  • Update camera values
    • Events
      • Time - Every 0.50 seconds of game time
    • Conditions
    • Actions
      • Set Cam_CameraRotation = Unit_Avatarfacing
      • Set Unit_Avatarfacing = (Facing of Unit_Avatar)
      • Camera - Set Player 1 (Red)&#039;s camera Rotation to Cam_CameraRotation over 0.50 seconds
      • Camera - Set Player 1 (Red)&#039;s camera Field of view to 135.00 over 0.50 seconds
and this last one to update the camera though it probably can be added to the main movement trigger
 

W!†A_cRaft

Ultra Cool Member
Reaction score
28
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top