0 votes

I cant seem to rotate my player, I think its because I am not using transforms, but I am sure there is a way to rotate to the player, this way.

Code:

extends KinematicBody

var directions = Vector2.ZERO
var gravity_vec = Vector3.ZERO
var motion = Vector3.ZERO
var fin_motion = Vector3.ZERO
var on_floor = false
const FPS : int = 60
const GRAVITY : float = 1.98
var speed : float = 30
var accel : float = 10
var jump_power : int = 35
var friction : int = 15
var air_rist : int = 5

var mouse_sens : float = 0.1
onready var camera = get_node("Camera")

func _ready():
    Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _input(event):
    if event is InputEventMouseMotion:
        rotate_y(deg2rad(-event.relative.x*mouse_sens))
        camera.rotate_x(deg2rad(-event.relative.y*mouse_sens))
        camera.rotation_degrees.x = clamp(camera.rotation_degrees.x,-89,89)

func _physics_process(delta):
    if Input.is_action_just_pressed("ui_cancel"):
        get_tree().quit()

    directions.x = (Input.get_action_strength("right") - Input.get_action_strength("left"))
    directions.y = (Input.get_action_strength("down") - Input.get_action_strength("up"))

    if directions.x != 0:
        motion.x += directions.x * accel * delta * FPS
        motion.x = clamp(motion.x,-speed,speed)

    if directions.y != 0:
        motion.z += directions.y * accel * delta * FPS
        motion.z = clamp(motion.z,-speed,speed)

    if is_on_floor():
        if directions.x == 0:   # If not moving apply friction
            motion.x = lerp(motion.x,0,friction * delta)

        if directions.y == 0:
            motion.z = lerp(motion.z,0,friction * delta)

    else:
        if directions.x == 0:   # If not moving apply air_rist
            motion.x = lerp(motion.x,0,air_rist * delta)

        if directions.y == 0:
            motion.z = lerp(motion.z,0,air_rist * delta)

    if is_on_floor():   #Having a seperate vector stops false alarms for is_on_floor()
        gravity_vec = -get_floor_normal() * 5 # If on a angle, stops sliding off it
        on_floor = true
    else:
        if on_floor:
            gravity_vec = Vector3.ZERO
            on_floor = false
        else:
            gravity_vec += Vector3.DOWN * GRAVITY   # Apply gravity

    if Input.is_action_just_pressed("jump") and is_on_floor():
        gravity_vec = Vector3.UP * jump_power
        on_floor = false

    directions = directions.normalized()    #Stops moving faster when two keys are pressed

    # I add all the vectors together to get a perfect player controller
    fin_motion.x = motion.x + gravity_vec.x
    fin_motion.y = gravity_vec.y
    fin_motion.z = motion.z + gravity_vec.z

    fin_motion = move_and_slide(fin_motion,Vector3.UP)
Godot version 3.3
in Engine by (152 points)

Could be the angle being too small to notice, try removing the deg2rad() in order to get a bigger value for rotation.

Please log in or register to answer this question.

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.