![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | r1diq |
Hello all…
What I want is a code in (C # or GDscript) to make the player move the same way as the yellow ball … Watch the video (https://youtu.be/swWtPulkuMw)
more clarification:
I want the player to move every time (dragging the phone screen or with the keyboard buttons) a continuous movement towards dragging or scrolling (up or down right or left) until it hits a wall or any other obstacle so I can move it again … It is a puzzle game
thank you all .
the movement could be done using acceleration and deceleration . the continuous movement , you could restrict accepting Input to the condition “if velocity.length() == 0:” accept Input . an area or RayCast could be used to signal the ball to decelerate to a stop shy of the wall.
ArthurER | 2020-10-04 06:14
like this:
func get_input():
velocity = Vector2()
if Input.is_action_pressed("ui_left"):
velocity.x -= 1
if Input.is_action_pressed("ui_right"):
velocity.x += 1
if Input.is_action_pressed("ui_up"):
velocity.y -= 1
if Input.is_action_pressed("ui_down"):
velocity.y += 1
if velocity.length() == 0:
velocity = velocity.normalized() * speed
r1diq | 2020-10-04 07:57