Improved rotation of player & AI

This commit is contained in:
Paul Black 2022-03-15 11:17:02 -06:00
parent 09c44ca20b
commit bc19901a1b
2 changed files with 3 additions and 3 deletions

View file

@ -44,8 +44,8 @@ func _physics_process(delta):
velocity = Vector3.ZERO
if ablewalk == 0:
_walk_towards_player()
$CollisionShapeBottom.rotation.y = lerp_angle($CollisionShapeBottom.rotation.y, atan2(velocity.x, velocity.z), delta * angular_acceleration)
_look_at_player()
$CollisionShapeBottom.rotation.y = lerp_angle($CollisionShapeBottom.rotation.y, atan2(velocity.x, velocity.z), delta * angular_acceleration)
func _bullet_fire():
if player != null:

View file

@ -26,6 +26,8 @@ func _physics_process(delta):
owner.add_child(b)
b.transform = $CollisionShapeTop/Top_tank/BulletGenerator.global_transform
b.velocity = -b.global_transform.basis.z * b.muzzle_velocity
if (Input.is_action_pressed("move_right") || Input.is_action_pressed("move_left") || Input.is_action_pressed("move_back") || Input.is_action_pressed("move_forward")):
$CollisionShapeBottom.rotation.y = lerp_angle($CollisionShapeBottom.rotation.y, atan2(direction.x, direction.z), delta * angular_acceleration)
var space_state = get_world().direct_space_state
var mouse_position = get_viewport().get_mouse_position()
@ -40,8 +42,6 @@ func _physics_process(delta):
direction = direction.normalized()
# $Pivot.look_at(translation + direction, Vector3.UP)
$CollisionShapeBottom.rotation.y = lerp_angle($CollisionShapeBottom.rotation.y, atan2(direction.x, direction.z), delta * angular_acceleration)
velocity.x = direction.x * speed
velocity.z = direction.z * speed
velocity.y -= gravity * delta