Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | zakjohn |
i am following garbaj third person controller and is on floor is 80% returns false and randomly returns true when on ground. i checked everyhting i watched the video 5 times. nothing works. help.
example of debug:
(0, -70.904762, 0)False
(0, -70.904762, 0)True
(0, -71.068092, 0)False
(0, -71.231422, 0)False
extends KinematicBody
onready var gun_pivot: Spatial = $GunPivot
onready var pivot: Spatial = $Pivot
export var gravity = .98
export var jump = 5
var capncrunch = Vector3()
var direction = Vector3()
var speed = 10
var velocity = Vector3()
var acceleration = 5
var mouse_sensitivity = .1
func _ready() -> void:
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
func _input(event: InputEvent) -> void:
if Input.is_action_just_pressed('ui_cancel'):
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if Input.is_action_just_pressed('shoot'):
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
if event is InputEventMouseMotion:
rotate_y(deg2rad(-event.relative.x * mouse_sensitivity))
pivot.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
pivot.rotation.x = clamp(pivot.rotation.x, deg2rad(-90), deg2rad(90))
gun_pivot.rotate_x(deg2rad(-event.relative.y * mouse_sensitivity))
gun_pivot.rotation.x = clamp(pivot.rotation.x, deg2rad(-90), deg2rad(90))
func _process(delta: float) -> void:
direction = Vector3()
if Input.is_action_pressed('move_forward'):
direction -= transform.basis.z
elif Input.is_action_pressed('move_backwards'):
direction += transform.basis.z
if Input.is_action_pressed('move_left'):
direction -= transform.basis.x
elif Input.is_action_pressed('move_right'):
direction += transform.basis.x
apply_gravity(delta)
jump()
print(capncrunch ,is_on_floor())
move_and_slide(capncrunch, Vector3.UP)
direction = direction.normalized()
velocity = direction * speed
velocity.linear_interpolate(velocity, acceleration * delta)
move_and_slide(velocity, Vector3.UP)
func apply_gravity(delta):
if not is_on_floor():
capncrunch.y -= gravity * delta
func jump():
if Input.is_action_just_pressed('jump') and is_on_floor():
capncrunch.y = jump
print('jumped')