0 votes

I dont know how to fix, theres an error near the bottem of the code when it says

if is_on_floor():
if Input.is_action_pressed("jump"):
    velocity.y = jump_impulse

This is the full on code:

extends KinematicBody

onready var anim_player =$AnimationPlayer
onready var camera = $Head/Camera
onready var raycast = $Head/Camera/RayCast

const GRAVITY = -30

export var camerasensitivity: float = 0.05
export var speed: float = 10.0
export var acceleration: float = 6.0
export var jump
impulse: float = 12.0
var velocity: Vector3 = Vector3.ZERO

onready var head: Spatial = $Head

func ready():

func physicsprocess(delta):
var movement = getmovementdirection()
velocity.x = lerp(velocity.x,movement.x * speed,acceleration * delta)
velocity.z = lerp(velocity.z,movement.z * speed,acceleration * delta)
velocity.y += GRAVITY * delta
velocity = move

func unhandledinput(event):
if event is InputEventMouseMotion:

func handlecamerarotation(event):
y(deg2rad(-event.relative.x * camerasensitivity))
x(deg2rad(-event.relative.y * camerasensitivity))
head.rotation.x = clamp(head.rotation.x, deg2rad(MIN

func getmovement_direction():
var direction = Vector3.DOWN

if Input.is_action_pressed("forward"):
    direction -= transform.basis.z
if Input.is_action_pressed("backwards"):
    direction += transform.basis.z
if Input.is_action_pressed("left"):
    direction -= transform.basis.x
if Input.is_action_pressed("right"):
    direction += transform.basis.x
if Input.is_action_just_pressed("jump"):
    velocity.y = jump_impulse

    if is_on_floor():
if Input.is_action_pressed("jump"):
    velocity.y = jump_impulse

return direction

If you guys find how to fix let me know plz :)

Godot version 3.1
in Engine by (14 points)

1 Answer

0 votes

What I would do is I would make an bool variable called isJumping (var isJumping = false)

Then add an elif like this: elif !is_on_floor():

In it set isJumping to equal to false

Then change the is_on_floor() to is_on_floor() and isJumping == false

Lastly at the top of that if statement, set isJumping equal to false

If that doesn't work, the answer is probably somewhere along those lines, hope this helps!

by (99 points)

Hi thanks for trying but now it is saying that the elif is misplaced and when it says

isjumping = false

then it says unexpected ident cation

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 Frequently asked questions and 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 [email protected] with your username.