update player rotation and adding move

This commit is contained in:
AleaJactaEst 2021-09-04 15:37:40 +02:00
parent 4919a117ab
commit a22e8db3fe

View file

@ -5,6 +5,7 @@ var rotation_speed_factor = 0.01
var orientation = 0.0
var direction = Vector3.ZERO
var velocity: = Vector3.ZERO
var rotatex = 0.0
export var gravity = -9.0
func search_animation( obj ) -> bool:
@ -94,20 +95,26 @@ func _process( delta ):
# $character.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 )
$creature.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
var forwards: Vector3 = $creature/camera_tps.global_transform.basis.z * input_direction.z
var right: Vector3 = $creature/camera_tps.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 = self.calculate_velocity(velocity, move_direction, delta)
Config.msg_info("move_direction X:" + str(move_direction.x) + " Y:" + str(move_direction.y) + " Z:" + str(move_direction.z))
Config.msg_info("velocity X:" + str(velocity.x) + " Y:" + str(velocity.y) + " Z:" + str(velocity.z))
velocity = $creature.move_and_slide(velocity, Vector3.UP, true)
# velocity = self.calculate_velocity(velocity, input_direction, delta)
#velocity = $creature.move_and_slide(velocity, Vector3.UP, true)
#Config.msg_info("X:" + str($creature.))
var pos : Vector3 = $creature.get_global_transform().origin
Config.msg_info("pos X:" + str(pos.x) + " Y:" + str(pos.y) + " Z:" + str(pos.z))
@ -122,7 +129,7 @@ func calculate_velocity(
velocity_new *= $creature.move_speed
if velocity_new.length() > $creature.max_speed:
velocity_new = velocity_new.normalized() * $creature.max_speed
velocity_new.y = velocity_current.y + gravity * delta
#velocity_new.y = velocity_current.y + gravity * delta
return velocity_new
@ -134,19 +141,21 @@ func _input( event ):
else:
self.orientation = 0.0
if event is InputEventMouseMotion and Input.is_mouse_button_pressed( 2 ):
self.rotate_y( event.relative.x *0.01 )
# self.rotate_y( event.relative.x *0.01 )
$creature.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 )
var sum = event.relative.y *0.01
rotatex += sum
$creature/camera_fps.rotate_x( sum )
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.rotate_x( - rotatex )
rotatex = 0.0
$creature/camera_fps.make_current()
else:
$creature/camera_tps.make_current()