Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | TheNewbie360 |
is_on_floor always returns the value False, even though its colliding with my floor.
Move_and_slide always returns the value (0, 0, 0) when the character stands still
Here the complete code of my Character:
extends KinematicBody
var velocity = Vector3()
var direction = Vector3()
var acceleration = 12
var mouse_sensity = 0.1
const SPEED = 6
const gradlol = 6
export var gravity = 70
export var jumpstrength = 20
var confirm = 0
onready var pivot = $Pivot
func _ready():
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event):
if Input.is_action_just_pressed(“ui_cancel”):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if event is InputEventMouseMotion:
rotate_y(deg2rad(-event.relative.x * mouse_sensity))
pivot.rotate_x(deg2rad(-event.relative.y * mouse_sensity))
pivot.rotation.x = clamp(pivot.rotation.x, deg2rad(-90), deg2rad(90))
func _physics_process(delta):
apply_gravity(delta)
jump()
velocity = move_and_slide(velocity, Vector3.UP)
if Input.is_action_pressed("ui_left") and Input.is_action_pressed("ui_right"):
direction.x = 0
elif Input.is_action_pressed("ui_right"):
direction = transform.basis.x
$MeshInstance.rotate_z(deg2rad(-gradlol))
elif Input.is_action_pressed("ui_left"):
direction -= transform.basis.x
$MeshInstance.rotate_z(deg2rad(gradlol))
else:
direction.x = 0
if Input.is_action_pressed("ui_up") and Input.is_action_pressed("ui_down"):
direction.z = 0
elif Input.is_action_pressed("ui_up"):
direction -= transform.basis.z
$MeshInstance.rotate_x(deg2rad(-gradlol))
elif Input.is_action_pressed("ui_down"):
direction = transform.basis.z
$MeshInstance.rotate_x(deg2rad(gradlol))
else:
direction.z = 0
direction = direction.normalized()
velocity = direction * SPEED
velocity.linear_interpolate(velocity, acceleration * delta)
print(move_and_slide(velocity))
func apply_gravity(delta):
velocity.y -= gravity
move_and_slide(velocity)
print(is_on_floor())
func jump():
if is_on_floor() and Input.is_action_pressed(“jump”):
velocity.y = jumpstrength
func _on_enemy_body_entered(body):
if body.name == “Character”:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
get_tree().change_scene(“res://Assets/Game Over.tscn”)