Godot Version
3
How to create this game movement mechanic in godot ?I have no idea.
Do you mean the ball movement, or the hands movement?
For the hands movement, I think he just made 2 different characters and bound the movement of each one to different buttons (probably A / D for the left hand and ← / → for the right hand)
I’m 99% sure that with minor tweaks to the default movement provided by Godot you could make both hands move
#the default movement code you find inside the characterBody2D node
var direction = Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
You would only need to make sure to change the “ui_left” and “ui_right” with the buttons you want
(go into project > project settings > input map to add your custom controls) and make them not move over a certain threshold so they don’t overlap or go in the wrong side of the map.
For the ball, I’d simply put 4 area 2D on each side of the ball, and based on if the ball hits vertically or horizontally, it just reverses the direction from which it was hit.
I’m not sure if that was understandable, so I’ll make an example:
The ball is flying towards the right wall and hits it, then the horizontal speed has to reverse.
If the ball flies towards the top wall, then the vertical speed has to reverse.
You could literally do something like
#not a working code, just showing trying to show how the reasoning works
if(ball_hits_topWall or ball_hits_bottomWall):
velocity.y = -velocity.y
if(ball_hits_rightWall or ball_hits_leftWall):
velocity.x = -velocity.x
Thanks for replying, i was thinking about that 2 buttons but i think it would be not to comfortable to use any other variants ?Wow and thanks for ball i only wanted only my cats mechanic but thanks for ball too.But we need to use 4 area 2d?I have created when i press A key my left paw goes to the left then when i release it goes back but i think it difficult too, maybe make my 2 cats pawn together ?
For the paws, make 2 different characterBody2D, and bind the movement of the left one only to A, and the movement of the right one only to D.
Inside the script, make it so that when there isn’t any input for that paw, it goes in the opposite direction of the direction it goes when holding the button.
Put the part where you don’t hold any button inside an if that makes sure that the paw doesn’t go outside the limits.
Sorry if it’s a messy explanation, but I couldn’t do better.
No problem i understand you, thank you very much !
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.