so i forgot to add my jump animation into the script so today i decided to add it into the script wwich already had the defult and running animation in it(they both work fine) but when i add the jump animation script it either stays stuck as the first frame of the jumping animation or removes both animations and its just my character frozen
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
sprite2d.animation = "jumping"
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
et the gravity from the project settings to be synced with RigidBody nodes.
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
func _physics_process(delta):
# Animations
if is_on_floor():
if (velocity.x > 1 || velocity.x < -1):
sprite2d.animation = running
else:
sprite2d.animation = defult
else:
sprite2d.animation = “jumping”
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis(“ui_left”, “ui_right”)
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, 10)
move_and_slide()
var isleft = velocity.x < 0
sprite2d.flip_h = isleft
If you wait 2 days then I can create a simple and easy tutorial on it, I search it on YouTube but not found a better ones
Note: I will do it with animation tree and animated sprite for smooth animation transition
Example Video:
Not exact that, just the player controller tutorial I will create.
no thank you but i do have a problem when i added the code you gave me it gave me an error that i cant find a way to fix check the other reply i sent you it has my the script with what error im having
Paste code between three ticks, you can do this by clicking the </> button on a new line or pressing ctrl+e then pasting your code. like so
```
type or paste code here
```
An indentation error is probably from directly copying code from the forum or elsewhere, check the affected lines and replace spaces with tabs. chances are your editor shows little ⇥ symbols for tabs and nothing for spaces.
uuuuhh turns out it doesnt play the animation when im not on the floor lol when im on the floor it plays the jump animation and not the idle and animation and it also doesnt flip when go in a diff direction (the running is okay its just the jumping i have difficulty with now) heres the script i didnt copy n paste from you and wrote it all
if not is_on_floor():
velocity.y += gravity * delta
Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, 10)
move_and_slide()
var isleft = velocity.x < 0
sprite2d.flip_h = isleft
…theres nothing wrong with what i wrote i fixed the errors i got after i wrote everything but just one line of code also btw it makes it easier for me if u put like a number before every line of code to see how many tabs i have to put
else: #Second
thats the line of code that has a problem and the error is “expected statement but found “else” instead”
i did that wich made another error wich i quickly fixed by adding one tab to if(velocity.x > 1 || velocity.x < -1):
sprite2d.animation = “running”
but that didnt solve my current error wich ive been asking for a solution for “expected statement found “else” instead” ive been terrorized by this error everytime i sleep this error shows up in my nightmares