#Need help with player movement
1 messages · Page 1 of 1 (latest)
Following these tips will increase your chance of getting good answers:
Helpers need to know as much as possible about your problem. Try answering the following questions:
- What are you trying to do? (show your node setup / code)
- What is the expected result?
- What is happening instead? (include any error messages)
- What have you tried so far?
Helpers often ask you questions to better understand your problem. Not answering them or saying "it's not relevant" is not helpful. Even if it is not directly relevant, there is a high chance the answer will give more context for the people that are helping you.
Please don't expect people to immediately help you. We all do this in our freetime. It may take some time until someone who can help you will answer.
Share your code that's currently in charge of the player movement?
line 23 is incomplete. should probably at least be $AnimatedSprite2D.play("walk_R")
However, I think there's a better way to handle player movement animations here. Gimme a sec
Wait... actually. I think this is mostly right, but I think line 23 is actually causing the issue here. You're telling the animated sprite to play in line 16, and 19. Those actions are getting overwritten by line 23. Delete that and see if it works better for you
it seems to be working better now, thanks!
but the player sprite isn't moving...how do I fix this?
Can you share the whole code?
When you surround some words with single backticks like `this`, it will be formatted as code.
You can also include code blocks by surrounding the code with three backticks. If you add "swift" then you will also get basic syntax highlighting:
```swift
print("hello world")
```
Discord will then show it as a code block like this:
print("hello world")
If your code snippet is rather long, you can upload it to a text paste site. One option that supports syntax highlighting for GDScript is https://bpa.st/
the screenshot I shared is the whole code
What does this script extend?
characterbody2D
Okay, perfect. Here's what you need to change:
#rename this to use physics:
func _physics_process(delta) -> void:
# rename this variable We already have velocity in the class.
var direction = Vector2.ZERO
if Input.is_action_just_pressed("move_R"):
direction.x = 1
$Anim.... #this line is fine. keep it as is
if Input.is_action_just_pressed("move_L"):
direction.x = -1
$Anim... #this line is fine. keep it as is
if direction:
velocity = (direction * SPEED).normalized()
else:
velocity.x = move_toward(velocity.x, 0, delta)
velocity.y = move_toward(velocity.y, 0, delta)
# check if we're moving
if not velocity:
$AnimatedSprite2D.play("idle_R")
This should be a good start. Do you need me to go more in depth on what's going on?