0 votes

This is my code and it is not working properly:


extends KinematicBody

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

const MINCAMERAANGLE = -75
const MAXCAMERAANGLE = 80
const GRAVITY = -100

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():
Input.set
mousemode(Input.MOUSEMODE_CAPTURED)

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
and_slide(velocity)

func unhandledinput(event):
if event is InputEventMouseMotion:
handlecamera_rotation(event)

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

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




return direction

Anyone know how to fix it??

Godot version 3.1
in Engine by (14 points)

It's difficult to parse your code, but are you checking that the player is on the ground when they jump?

1 Answer

0 votes

You should check if the player is on floor. And the method is is_on_floor()

Replace jump code with:

if is_on_floor():
    if Input.is_action_pressed("jump"):
        velocity.y = jump_impulse
by (654 points)
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.