change how the bouncing ball gets aligned to the surface, now it only changes the bonee transformation instead of the meshes node
This commit is contained in:
parent
15274ea71a
commit
5e9eb8b74e
|
@ -1,35 +0,0 @@
|
|||
[gd_scene load_steps=5 format=3 uid="uid://rdlvlyf0l1l"]
|
||||
|
||||
[ext_resource type="Script" path="res://Ball/ball.gd" id="1_oenn5"]
|
||||
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_b4pqe"]
|
||||
size = Vector3(0.5, 0.5, 0.5)
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_tdblm"]
|
||||
albedo_color = Color(0.117647, 0.427451, 0.611765, 1)
|
||||
roughness = 0.42
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_mq1q1"]
|
||||
radius = 0.3
|
||||
height = 0.6
|
||||
|
||||
[node name="Ball" type="RigidBody3D"]
|
||||
collision_layer = 4
|
||||
custom_integrator = true
|
||||
max_contacts_reported = 1
|
||||
contact_monitor = true
|
||||
can_sleep = false
|
||||
lock_rotation = true
|
||||
linear_damp_mode = 1
|
||||
angular_damp_mode = 1
|
||||
script = ExtResource("1_oenn5")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("BoxShape3D_b4pqe")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
material_override = SubResource("StandardMaterial3D_tdblm")
|
||||
mesh = SubResource("SphereMesh_mq1q1")
|
||||
|
||||
[node name="TimerCollision" type="Timer" parent="."]
|
||||
one_shot = true
|
|
@ -1,36 +0,0 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://rdlvlyf0l1l"]
|
||||
|
||||
[ext_resource type="Script" path="res://Ball/ball.gd" id="1_oenn5"]
|
||||
[ext_resource type="PackedScene" uid="uid://lge7m41oi6pn" path="res://Ball/Meshes/ball_bouncing.glb" id="2_ccq7m"]
|
||||
[ext_resource type="PackedScene" uid="uid://b1embyb2knvho" path="res://Ball/Meshes/ball_flying.glb" id="4_fh5j8"]
|
||||
[ext_resource type="Script" path="res://Ball/ball_meshes.gd" id="4_llldm"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_ogc07"]
|
||||
radius = 0.3
|
||||
|
||||
[node name="Ball" type="RigidBody3D"]
|
||||
collision_layer = 4
|
||||
custom_integrator = true
|
||||
max_contacts_reported = 1
|
||||
contact_monitor = true
|
||||
can_sleep = false
|
||||
lock_rotation = true
|
||||
linear_damp_mode = 1
|
||||
angular_damp_mode = 1
|
||||
script = ExtResource("1_oenn5")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_ogc07")
|
||||
|
||||
[node name="TimerCollision" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[node name="Meshes" type="Node3D" parent="."]
|
||||
script = ExtResource("4_llldm")
|
||||
|
||||
[node name="BallBouncingMesh" parent="Meshes" instance=ExtResource("2_ccq7m")]
|
||||
visible = false
|
||||
|
||||
[node name="BallFlyingMesh" parent="Meshes" instance=ExtResource("4_fh5j8")]
|
||||
|
||||
[node name="RotationNode" type="Node3D" parent="Meshes"]
|
|
@ -1,40 +0,0 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://rdlvlyf0l1l"]
|
||||
|
||||
[ext_resource type="Script" path="res://Ball/ball.gd" id="1_oenn5"]
|
||||
[ext_resource type="Shader" uid="uid://ny01m62ohegv" path="res://Ball/Meshes/ball_visual_shader.tres" id="2_wbu40"]
|
||||
[ext_resource type="PackedScene" uid="uid://dn8tw0i6t3701" path="res://Ball/ball_mesh_bouncing.tscn" id="3_3pvgr"]
|
||||
|
||||
[sub_resource type="SphereShape3D" id="SphereShape3D_ogc07"]
|
||||
radius = 0.3
|
||||
|
||||
[sub_resource type="ShaderMaterial" id="ShaderMaterial_qwhgq"]
|
||||
render_priority = 0
|
||||
shader = ExtResource("2_wbu40")
|
||||
|
||||
[sub_resource type="SphereMesh" id="SphereMesh_mq1q1"]
|
||||
radius = 0.3
|
||||
height = 0.6
|
||||
|
||||
[node name="Ball" type="RigidBody3D"]
|
||||
collision_layer = 4
|
||||
custom_integrator = true
|
||||
max_contacts_reported = 1
|
||||
contact_monitor = true
|
||||
can_sleep = false
|
||||
lock_rotation = true
|
||||
linear_damp_mode = 1
|
||||
angular_damp_mode = 1
|
||||
script = ExtResource("1_oenn5")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
|
||||
shape = SubResource("SphereShape3D_ogc07")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="."]
|
||||
visible = false
|
||||
material_override = SubResource("ShaderMaterial_qwhgq")
|
||||
mesh = SubResource("SphereMesh_mq1q1")
|
||||
|
||||
[node name="TimerCollision" type="Timer" parent="."]
|
||||
one_shot = true
|
||||
|
||||
[node name="BallBouncingMesh" parent="." instance=ExtResource("3_3pvgr")]
|
|
@ -27,6 +27,7 @@ func _physics_process(delta):
|
|||
queue_free()
|
||||
|
||||
|
||||
var collision_position : Vector3
|
||||
var collision_normal : Vector3
|
||||
var collision_angle_factor : float
|
||||
func _get_collision(delta):
|
||||
|
@ -37,6 +38,7 @@ func _get_collision(delta):
|
|||
# A collision happens
|
||||
if collision:
|
||||
# Get collision data stuff
|
||||
collision_position = collision.get_position()
|
||||
collision_normal = collision.get_normal()
|
||||
bounced_velocity = captured_velocity.bounce(collision_normal)
|
||||
# Get the dot product between the surface normal and the ball direction on hit
|
||||
|
|
|
@ -31,8 +31,9 @@ script = ExtResource("4_llldm")
|
|||
|
||||
[node name="DirectionNode" type="Node3D" parent="Meshes"]
|
||||
|
||||
[node name="RotationNode" type="Node3D" parent="Meshes"]
|
||||
|
||||
[node name="BallBouncingMesh" parent="Meshes" instance=ExtResource("2_ccq7m")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0.3)
|
||||
visible = false
|
||||
|
||||
[node name="BallFlyingMesh" parent="Meshes" instance=ExtResource("4_fh5j8")]
|
||||
|
|
|
@ -17,11 +17,11 @@ func _ready():
|
|||
|
||||
|
||||
func _process(delta):
|
||||
_align_mesh_to_direction()
|
||||
_align_flying_mesh_to_direction()
|
||||
_squish_animation()
|
||||
|
||||
|
||||
func _align_mesh_to_direction():
|
||||
func _align_flying_mesh_to_direction():
|
||||
# Align the DirectionNode to the movement direction
|
||||
$DirectionNode.look_at(ball.captured_velocity + ball.global_position, Utilities.LOOK_AT_OFFSET_FIX)
|
||||
|
||||
|
@ -39,17 +39,30 @@ func _on_collision():
|
|||
$BallBouncingMesh.visible = true
|
||||
is_bouncing = true
|
||||
|
||||
# Align the Meshes node to the surface normal so the bouncing mesh is properly aligned
|
||||
look_at(ball.collision_normal + ball.global_position, Utilities.LOOK_AT_OFFSET_FIX)
|
||||
_align_bouncing_mesh_to_surface()
|
||||
|
||||
|
||||
func _after_collision():
|
||||
$BallFlyingMesh.visible = true
|
||||
$BallBouncingMesh.visible = false
|
||||
is_bouncing = false
|
||||
|
||||
|
||||
func _align_bouncing_mesh_to_surface():
|
||||
# Align position to the surface
|
||||
var bone_position = ball.collision_position - ball.global_position
|
||||
skeleton_bouncing.set_bone_pose_position(1, bone_position)
|
||||
|
||||
# Reset the Meshes node rotation
|
||||
rotation = Vector3.ZERO
|
||||
# Align rotation to the surface normal
|
||||
$RotationNode.look_at(ball.collision_normal + ball.global_position, Utilities.LOOK_AT_OFFSET_FIX)
|
||||
|
||||
# Convert the rotation euler into a quaternion
|
||||
var euler_rotation = $RotationNode.rotation
|
||||
var quaternion_rotation : Quaternion
|
||||
quaternion_rotation = quaternion_rotation.from_euler(euler_rotation)
|
||||
|
||||
# Rotate the bone
|
||||
skeleton_bouncing.set_bone_pose_rotation(1, quaternion_rotation)
|
||||
|
||||
|
||||
func _squish_animation():
|
||||
|
|
|
@ -1,62 +0,0 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://b06nx3ofndgjy"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://onahsd5he406" path="res://64x64_orange_grey.png" id="1_4apc2"]
|
||||
[ext_resource type="PackedScene" uid="uid://ggl4tqcb5dbc" path="res://Player/player.tscn" id="1_n0nhi"]
|
||||
[ext_resource type="Script" path="res://Misc/debug_cone.gd" id="3_nsiny"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_bwr1w"]
|
||||
albedo_texture = ExtResource("1_4apc2")
|
||||
uv1_scale = Vector3(0.5, 0.5, 0.5)
|
||||
uv1_triplanar = true
|
||||
texture_filter = 2
|
||||
|
||||
[sub_resource type="PlaneMesh" id="PlaneMesh_6jpek"]
|
||||
size = Vector2(3, 8)
|
||||
|
||||
[sub_resource type="ConvexPolygonShape3D" id="ConvexPolygonShape3D_iauoa"]
|
||||
points = PackedVector3Array(1.5, 0, 4, -1.5, 0, 4, 1.5, 0, -4, -1.5, 0, -4)
|
||||
|
||||
[sub_resource type="CylinderMesh" id="CylinderMesh_modx0"]
|
||||
top_radius = 0.0
|
||||
bottom_radius = 0.3
|
||||
height = 0.6
|
||||
|
||||
[node name="World" type="Node3D"]
|
||||
|
||||
[node name="Level" type="Node3D" parent="."]
|
||||
|
||||
[node name="CSGBox3D" type="CSGBox3D" parent="Level"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 4, 0)
|
||||
material_override = SubResource("StandardMaterial3D_bwr1w")
|
||||
use_collision = true
|
||||
size = Vector3(12, 8, 12)
|
||||
|
||||
[node name="CSGBox3D2" type="CSGBox3D" parent="Level/CSGBox3D"]
|
||||
operation = 2
|
||||
size = Vector3(11.8, 7.8, 11.8)
|
||||
|
||||
[node name="DiagonalWall" type="StaticBody3D" parent="Level"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -5, 0, -5)
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="Level/DiagonalWall"]
|
||||
transform = Transform3D(0.707107, 0.707107, -3.09086e-08, 0, -4.37114e-08, -1, -0.707107, 0.707107, -3.09086e-08, 0, 4, 0)
|
||||
mesh = SubResource("PlaneMesh_6jpek")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Level/DiagonalWall"]
|
||||
transform = Transform3D(0.707107, 0.707107, -3.09086e-08, 0, -4.37114e-08, -1, -0.707107, 0.707107, -3.09086e-08, 0, 4, 0)
|
||||
shape = SubResource("ConvexPolygonShape3D_iauoa")
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_n0nhi")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.2, 0)
|
||||
|
||||
[node name="DirectionalLight3D" type="DirectionalLight3D" parent="."]
|
||||
transform = Transform3D(0.482579, -0.637736, -0.600342, 0, -0.685437, 0.728132, -0.875852, -0.351381, -0.330778, 0, 0, 0)
|
||||
|
||||
[node name="DebugCone" type="Node3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -4.5, 0.5, 4.5)
|
||||
script = ExtResource("3_nsiny")
|
||||
|
||||
[node name="DebugConeMesh" type="MeshInstance3D" parent="DebugCone"]
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 0, 0, 0)
|
||||
mesh = SubResource("CylinderMesh_modx0")
|
||||
skeleton = NodePath("../..")
|
Loading…
Reference in New Issue