![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | tdhslayer |
Hi, I am learning Godot by following the tutorial to make a Platformer. I have a simple KinematicBody2D on top of StaticBody2D, however, I am not able to move the player in the X direction. The player is able to successfully jump in the Y direction but is unable to move in the X direction.
Below is the code for Player
extends KinematicBody2D
var velocity = Vector2.ZERO
func _physics_process(delta):
velocity.y += 2
if Input.is_action_pressed("ui_right"):
velocity.x += 40
elif Input.is_action_pressed("ui_left"):
velocity.x += -40
else:
velocity.x = 0
if Input.is_action_just_pressed("ui_up"):
velocity.y = -10
move_and_collide(velocity)
Link to the tutorial : https://www.youtube.com/watch?v=f3WGFwCduY0
Below is how my scene looks like
Help is much appreciated
Link to Project : godotOne.zip - Google Drive
Link to Simulation Video
Have you verified that the Input Map for the ui_right
and ui_left
actions are properly assigned? What happens if you add a print()
statement inside each of the if
blocks for those actions? Do you see them printed in the console when the keys are pressed?
jgodfrey | 2022-11-06 15:18
Hi jgodfrey,
Thank you for replying. I have checked the console and the velocity is printed correctly in the debugger.
However, it appears that there is unnecessary friction applied when trying to move KinematicBody2D on the StaticBody2D.
You can find the simulation and project link as below:
Link to Project : godotOne.zip - Google Drive
Link to Simulation Video
godot_move_recording.mov - Google Drive
tdhslayer | 2022-11-07 03:47