Browse Source

smoothPlayerRotation

Henrik
Desaru 3 months ago
parent
commit
1ad9f49665
3 changed files with 30 additions and 8 deletions
  1. BIN
     
  2. +1
    -1
      scenes/Ship.tscn
  3. +29
    -7
      scenes/sub_scenes/player.tscn

BIN
View File


+ 1
- 1
scenes/Ship.tscn View File

@@ -388,7 +388,7 @@ transform = Transform( 1, 0, 0, 0, -0.416456, -0.909156, 0, 0.909156, -0.416456,
light_energy = 0.2

[node name="SeagullOrbit" type="Spatial" parent="."]
transform = Transform( -0.0668715, 0, 0.997759, 0, 1, 0, -0.997759, 0, -0.0668715, 0, 30, 0 )
transform = Transform( -0.963966, 0, 0.266016, 0, 1, 0, -0.266016, 0, -0.963966, 0, 30, 0 )
script = SubResource( 26 )
speed = 0.5



+ 29
- 7
scenes/sub_scenes/player.tscn View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=8 format=2]
[gd_scene load_steps=11 format=2]

[ext_resource path="res://addons/randomAudioStreamPlayer/random_audio_stream_player_3D.gd" type="Script" id=1]
[ext_resource path="res://assets/sound/Steps/Metal_Footstep_02_mono.ogg" type="AudioStream" id=2]
@@ -27,16 +27,19 @@ func _physics_process(_delta):
var input = Vector3()
if Input.is_action_pressed(\"MovingForward\"):
input.z -= 1
smoothRotating(180.0)
input.z -= 1
if Input.is_action_pressed(\"MovingBackward\"):
smoothRotating(0.0)
input.z += 1
if Input.is_action_pressed(\"MovingRight\"):
smoothRotating(90.0)
input.x += 1
if Input.is_action_pressed(\"MovingLeft\"):
smoothRotating(270.0)
input.x -= 1

if Input.is_action_just_pressed(\"Jump\") && is_on_floor():
@@ -49,7 +52,6 @@ func _physics_process(_delta):
input.x *= sprintFactor
input.z *= sprintFactor


vel += Vector3(input.x, 0, input.z)*moveSpeed
vel.y += input.y * jumpForce
@@ -65,12 +67,27 @@ func _physics_process(_delta):

func _on_Timer_timeout():
audio.play()


func smoothRotating(rot : float):
print_debug(deg2rad(rotation_degrees.y) as String + \"to\" + deg2rad(rot) as String)
var targetRotation = lerp_angle(deg2rad(rotation_degrees.y), deg2rad(rot), 0.2)
rotation_degrees.y = rad2deg(targetRotation)
"

[sub_resource type="CapsuleMesh" id=2]
mid_height = 2.0

[sub_resource type="CapsuleShape" id=3]
[sub_resource type="SpatialMaterial" id=3]
albedo_color = Color( 0.760784, 0.576471, 0.4, 1 )

[sub_resource type="SphereMesh" id=4]

[sub_resource type="SpatialMaterial" id=5]
albedo_color = Color( 0.968627, 0.282353, 0.282353, 1 )

[sub_resource type="CapsuleShape" id=6]
height = 2.0

[node name="Player" type="KinematicBody"]
@@ -82,11 +99,16 @@ __meta__ = {
[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 )
mesh = SubResource( 2 )
material/0 = null
material/0 = SubResource( 3 )

[node name="MeshInstance" type="MeshInstance" parent="MeshInstance"]
transform = Transform( 0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, 1.08105, -0.750059 )
mesh = SubResource( 4 )
material/0 = SubResource( 5 )

[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, -1.62921e-07, -1, 0, 1, -1.62921e-07, 0, 0, 0 )
shape = SubResource( 3 )
shape = SubResource( 6 )

[node name="Listener" type="Listener" parent="."]
current = true


Loading…
Cancel
Save