my jump animation wont work.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By yellowJUSTice

my jump animation wont work for my game. heres my code ive tryed to search for videos on this subject but nothing has come up, tends KinematicBody2D
class_name player

var velocity = Vector2.ZERO

export (Resource) var moveData
func _physics_process(_delta):

apply_gravity()
var input = Vector2.ZERO


input.x = Input.get_action_strength("ui_right")- Input.get_action_strength("ui_left")
if input.x == 0:
	apply_friction() 
	$AnimatedSprite.animation = "idle"
else:
	apply_acceleration(input.x)
	$AnimatedSprite.animation = "run"
	if input.x > 0:
		 $AnimatedSprite.flip_h = true
	elif input.x < 0:
		$AnimatedSprite.flip_h = false
if is_on_floor():
	if Input.is_action_pressed("ui_up"):
		velocity.y = moveData.JUMP_FORCE
else:
	if Input.is_action_just_released("ui_up") and velocity.y < moveData.JUMP_RELEASE_FORCE:
		velocity.y = moveData.JUMP_RELEASE_FORCE
	$AnimatedSprite.animation = "jump"
	if velocity.y > 0:
		velocity.y += moveData.ADDITIONAL_FALL_GRAVITY
		
	
	
velocity = move_and_slide(velocity, Vector2.UP)

func apply_gravity():
velocity.y += moveData.GRAVITY

func apply_friction():
velocity.x = move_toward(velocity.x,0,moveData.FRICTION)

func apply_acceleration(ammount):
velocity.x = move_toward(velocity.x, moveData.MAX_SPEED * ammount, moveData.ACCELERATION)
pass

func _on_AnimatedSprite_frame_changed():
pass # Replace with function body.

:bust_in_silhouette: Reply From: exuin

I’m guessing another animation is overriding it. Put the logic for animation all together at the end.

What do i type to do that? (Sorry for the questions im pretty new on this stuff)

yellowJUSTice | 2023-02-28 13:00

if is_on_floor():
  if input.x == 0:
      $AnimatedSprite.animation = "idle"
  else:
      $AnimatedSprite.animation = "run"
      if input.x > 0:
           $AnimatedSprite.flip_h = true
      elif input.x < 0:
          $AnimatedSprite.flip_h = false
  else:
      $AnimatedSprite.animation = "jump"

exuin | 2023-02-28 14:42

after input’s value is set

exuin | 2023-02-28 21:43

it says unexpected token?

yellowJUSTice | 2023-03-01 00:35

Then you didn’t put it in correctly or I got something wrong

exuin | 2023-03-01 01:43

Argh im still confused on where to put it i thought i put it in the right place

yellowJUSTice | 2023-03-01 03:10

ok question i think i figured it out, where is inputs value in the script

yellowJUSTice | 2023-03-02 00:32

It’s the second line you posted

exuin | 2023-03-02 00:57

alright, i put it under the second line of script and its not working.

yellowJUSTice | 2023-03-02 03:44

I said to put it at the end

exuin | 2023-03-02 03:45

something like this?
cause its still not working

extends KinematicBody2D
class_name player

var velocity = Vector2.ZERO

export (Resource) var moveData

func _physics_process(_delta):

apply_gravity()
var input = Vector2.ZERO


input.x = Input.get_action_strength("ui_right")- Input.get_action_strength("ui_left")
if input.x == 0:
	apply_friction() 
	$AnimatedSprite.animation = "idle"
else:
	apply_acceleration(input.x)
	$AnimatedSprite.animation = "run"
	if input.x == 0:
		apply_friction()
	if input.x > 0:
		 $AnimatedSprite.flip_h = true
	elif input.x < 0:
		$AnimatedSprite.flip_h = false
if is_on_floor():
	if Input.is_action_pressed("ui_up"):
		velocity.y = moveData.JUMP_FORCE
else:
	if Input.is_action_just_released("ui_up") and velocity.y < moveData.JUMP_RELEASE_FORCE:
		velocity.y = moveData.JUMP_RELEASE_FORCE
	$AnimatedSprite.animation = "jump"
	if is_on_floor():
		if input.x == 0:
      $AnimatedSprite.animation = "idle"

else:
$AnimatedSprite.animation = “run”
if input.x > 0:
$AnimatedSprite.flip_h = true
elif input.x < 0:
$AnimatedSprite.flip_h = false
else:
$AnimatedSprite.animation = “jump”
if velocity.y > 0:
velocity.y += moveData.ADDITIONAL_FALL_GRAVITY

velocity = move_and_slide(velocity, Vector2.UP)

func apply_gravity():
velocity.y += moveData.GRAVITY

func apply_friction():
velocity.x = move_toward(velocity.x,0,moveData.FRICTION)

func apply_acceleration(ammount):
velocity.x = move_toward(velocity.x, moveData.MAX_SPEED * ammount, moveData.ACCELERATION)
pass

func _on_AnimatedSprite_frame_changed():
pass # Replace with function body.

yellowJUSTice | 2023-03-02 03:50

everytime i place it in the spots your telling me too its not working or its just me confused with the spot your talking about

yellowJUSTice | 2023-03-02 03:51

You need to remove all the other animated sprite references. Only have them at the bottom.

exuin | 2023-03-02 03:53

Did what you said still say’s its not working

yellowJUSTice | 2023-03-02 03:57

You need to be more specific than that. It’s not working doesn’t tell me anything

exuin | 2023-03-02 03:59

Alright Alright, Your Right Its Still Saying Unexpected Token If: I deleted all refrences to the animated sprite and pasted your code under the pass #replace with function body code

yellowJUSTice | 2023-03-02 04:01

I can’t really help you with syntax if you don’t paste the code here properly. You need to put four spaces before each line to make it a code block

exuin | 2023-03-02 04:04

Im trying to do that rn its saying mixed tabs and spaces on indenation i spaced it 4 times?

yellowJUSTice | 2023-03-02 04:08

No, I’m talking about pasting the code here, not in Godot. Also, replace the 4 spaces with tabs in Godot since it uses tabs.

exuin | 2023-03-02 04:18