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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top