update player rotation

This commit is contained in:
AleaJactaEst 2021-09-04 13:37:09 +02:00
parent c9340d55d6
commit 4919a117ab

View file

@ -4,6 +4,7 @@ var animation_object:AnimationPlayer = null
var rotation_speed_factor = 0.01
var orientation = 0.0
var direction = Vector3.ZERO
var velocity: = Vector3.ZERO
export var gravity = -9.0
func search_animation( obj ) -> bool:
@ -89,14 +90,25 @@ static func get_input_direction() -> Vector3:
func _process( delta ):
Config.msg_info( Input.get_action_strength("move_backward") )
Config.msg_info( Input.get_action_strength("move_forward") )
#Config.msg_info( "B:" + str(Input.get_action_strength("move_backward")) + " F:" + str(Input.get_action_strength("move_forward") ))
# $character.direction = self.get_input_direction()
#self.direction = self.get_input_direction()
self.direction = self.get_input_direction()
#self.direction = self.get_input_direction()
self.rotate_y( self.rotation_speed_factor * self.orientation )
var input_direction: = self.get_input_direction()
# var forwards: Vector3 = self.camera.global_transform.basis.z * input_direction.z
# var right: Vector3 = self.camera.global_transform.basis.x * input_direction.x
# var move_direction: = forwards + right
# if move_direction.length() > 1.0:
# move_direction = move_direction.normalized()
# move_direction.y = 0
# Movement
#velocity = self.calculate_velocity(velocity, input_direction, delta)
#velocity = $creature.move_and_slide(velocity, Vector3.UP, true)
#Config.msg_info("X:" + str($creature.))
func calculate_velocity(
@ -122,5 +134,19 @@ func _input( event ):
else:
self.orientation = 0.0
if event is InputEventMouseMotion and Input.is_mouse_button_pressed( 2 ):
if $creature:
self.rotate_y( event.relative.x *0.01 )
self.rotate_y( event.relative.x *0.01 )
if $creature/camera_fps.current:
# On FPS - we can move head to see up or down
var current = $creature/camera_fps.get_rotation()
# Config.msg_info("X:" + str(current.x) + " v:" + str(event.relative.y))
if (event.relative.y > 0.0 and current.x > -1.4) or (event.relative.y < 0.0 and current.x < 1.4) :
$creature/camera_fps.rotate_x( event.relative.y *0.01 )
elif event.is_action_pressed( "camera_switch" ):
if $creature/camera_tps.current:
# Reset angle X for camera
var current = $creature/camera_fps.get_rotation()
current.x = 0.0
$creature/camera_fps.set_rotation(current)
$creature/camera_fps.make_current()
else:
$creature/camera_tps.make_current()