godot_recipes
godot_recipes copied to clipboard
[Discussion] 2D: Top-down movement
Discussion for http://godotrecipes.com/2d/topdown_movement/
Would it be possible to create another recipe for twin stick analogue shooter games? There's a whole bunch of tutorials that do a look_at with a mouse, but I can't find, or manage to get the same functionality out of the right analogue stick of a controller.
On Option 2: Rotate and Move, I believe the axis are wrong. when going up or down should use the y axis? Also the +/- signs reversed.
@M-Tieleman Yes there is. Make the movement be controlled by the left stick, but set the rotation to be controlled by the right stick. Times the rotation of the player by the action strength and by a variable called: "Rot speed". This should work.
So to put it simply, let's say you have this in your 'process' function:
velocity.x -= 1 takes away 1 from the existing value of velocity.x. So if x = 0, then what this will do is it will take away 1 from 0 which will give you -1, which in this case, will make you move left.
velocity.x = -1 snaps the existing value of velocity.x to -1 e.g. if velocity.x = 0, then it will just become -1, which again, makes you move left
y = 1
|
|
|
y = 0.5
|
|
|
x = -1 ----------------------- x = -0.5 ------------------------x/y = 0 --------------------------- x = 0.5 ----------------------- x = 1
|
|
|
y = -0.5
|
|
|
y = -1
The reason why it works fine for you (I assume you mean 'velocity = -1') is because they both do the same job depending on how you use them. Therefore, this whole rant was useless but at least you learnt the difference.
So yes, they both work the same way but one takes away and the other doesn't.
I hope this makes sense and msg back if u need more help
On Mon, 15 Aug 2022 at 11:42, Griiim24 @.***> wrote:
I am a bit confused on to why do you increment or decrement 1 depending on the direction of the action like velocity.x -= 1. Won't velocity.x = -1 works the same? I've been using it and it works just fine. Tnx
— Reply to this email directly, view it on GitHub https://github.com/kidscancode/godot_recipes/issues/20#issuecomment-1214875321, or unsubscribe https://github.com/notifications/unsubscribe-auth/AT6L7HGHAXAKA4ZCR4TBXLTVZINJRANCNFSM4XAAFFSQ . You are receiving this because you commented.Message ID: @.***>
Thank you for replying, i did test both codes again after i posted the question and found out that although both performed the same actions, the one i use doesn't stop when both left and right(up and down) keys are pressed at the same time, instead it continued to move towards a positive direction.