+1 vote

Recently i´ve been coding a Player State A.I. to help reduce the effort when adding animations to my KinematicBody2D. Been checking the code and I don´t find any errors on it but everytime I run the main scene, KinematicBody.gd ( Player´s movement code ) is completely ignored resulting on my player not being able to do anything ( apart from animations ). Strangely my Input Events do work ( for example if I press up, jumping animation is displayed but action isn´t made (jump) . Parameters such as gravity are also not being applied.

Here´s my code for reference
```onready var animatedSprite = $Sprite
func _ready():
call_deferred("set_state", states.idle)*

func statelogic(delta):

func gettransition(delta):
match state:
if !parent.isonfloor():
if parent.motion.y < 0:
return states.jump
elif parent.motion.y > 0:
return states.fall
elif parent.motion.x != 0:
return states.run
if !parent.isonfloor():
if parent.motion.y < 0:
return states.jump
elif parent.motion.y > 0:
return states.fall
elif parent.motion.x == 0:
return states.idle
if parent.isonfloor():
return states.idle
elif parent.motion.y >= 0:
return states.fall
if parent.isonfloor():
return states.idle
elif parent.motion.y < 0:
return states.jump
return null

func enterstate(newstate, oldstate):
match new_state:

func exitstate(oldstate, newstate):

My node organization on the editor seems fine, no problems with it

in Engine by (13 points)

Well, If you could show the Player Script That would certanly help.
(Also as I see, we watched the same tutorial on statemachines XD)


```extends KinematicBody2D

****c****onst TARGETFPS = 60**
const ACC = 8
const MAX
SPEED = 64
const FRICTION = 12
const GRAVITY = 4
const JUMPFORCE = 135
const AIR

onready var animatedSprite = $Sprite
var motion = Vector2.ZERO

func physicsprocess(delta):
motion.y += GRAVITY * delta * TARGETFPS
motion = move
and_slide(motion, Vector2.UP)
func getplayer_input(delta):

var xinput = Input.getactionstrength("uiright") -Input.getactionstrength("ui_left")

if x_input != 0: 
    if is_on_floor(): 
        motion.x += x_input * ACC * delta * TARGET_FPS
        motion.x = clamp(motion.x, -MAX_SPEED, MAX_SPEED)  

    if is_on_floor():
        if x_input == 0:
            motion.x = lerp(motion.x, 0, FRICTION * delta) 

func inputjump():
if Input.isactionjustpressed("uiup"):
motion.y = -JUMP_FORCE

    if Input.is_action_just_released("ui_up") and motion.y <-JUMP_FORCE/2:
        motion.y = -JUMP_FORCE/2```

1 Answer

0 votes

OHHHH I get it now!! (been lokking at the code for a while XD)

The thing is: You're calling the physicsfrocess(delta) function inside of a physicsprocess(delta) function. You're calling a function wich calles itself automatically. (And since you're applying velocity (motion) there, if you mess up the function calls, it wouldn't move)

The solution is easy:
Just rename The physics_process() function in both the player script and the State Machine and it will just work fine :)

by (137 points)

Oh I see, big thanks!

Now that I got my computer back, the problem wasn’t solved by exchanging names idk why

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.