# How do I rotate my 3D player?

Attention Topic was automatically imported from the old Question2Answer platform.

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

Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)

func _input(event):
if event is InputEventMouseMotion:
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)

``````

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

Coxcopi | 2021-05-31 21:33