friction and sand pit
This commit is contained in:
parent
08712cf22c
commit
77ef1dee48
5 changed files with 81 additions and 35 deletions
|
@ -11,6 +11,8 @@ extends CharacterBody3D
|
|||
@export_group("Movement")
|
||||
@export var gravity: float
|
||||
@export var friction: float
|
||||
@export var friction_coef: float
|
||||
@export var friction_pow: float
|
||||
@export var stop_threshold: float
|
||||
|
||||
@export_group("Camera", "camera_")
|
||||
|
@ -101,13 +103,18 @@ func _apply_gravity(delta: float) -> void:
|
|||
|
||||
func _slow_to_stop(delta: float) -> void:
|
||||
if is_on_floor():
|
||||
var new_velocity = velocity
|
||||
new_velocity.y = 0.0
|
||||
var new_velocity = velocity * Vector3(1.0, 0.0, 1.0)
|
||||
|
||||
#new_velocity = lerp(new_velocity, Vector3.ZERO, friction_coef * delta)
|
||||
#new_velocity = lerp(
|
||||
#new_velocity, Vector3.ZERO,
|
||||
#power_scale * pow(friction_coef / new_velocity.length(), friction_pow * delta)
|
||||
#)
|
||||
new_velocity = new_velocity.move_toward(Vector3.ZERO, friction * delta)
|
||||
if new_velocity.length_squared() <= stop_threshold * stop_threshold:
|
||||
new_velocity = Vector3.ZERO
|
||||
new_velocity.y = velocity.y
|
||||
velocity = new_velocity
|
||||
velocity.x = new_velocity.x
|
||||
velocity.z = new_velocity.z
|
||||
|
||||
func _bounce_on_walls(delta: float = 0.0) -> void:
|
||||
var h_vel = (prev_velocity * Vector3(1.0, 0.0, 1.0))
|
||||
|
|
|
@ -45,7 +45,9 @@ power_scale = 20.0
|
|||
power_sensitivity = 0.01
|
||||
power_threshold = 0.2
|
||||
gravity = 10.0
|
||||
friction = 5.0
|
||||
friction = 10.0
|
||||
friction_coef = 0.01
|
||||
friction_pow = 60.0
|
||||
stop_threshold = 0.1
|
||||
camera_low_angle = 0.349066
|
||||
camera_high_angle = 1.0472
|
||||
|
|
30
objects/sand_pit.gd
Normal file
30
objects/sand_pit.gd
Normal file
|
@ -0,0 +1,30 @@
|
|||
extends CSGPolygon3D
|
||||
|
||||
|
||||
@export var friction: float
|
||||
|
||||
@export_group("Node References")
|
||||
@export var collision_polygon: CollisionPolygon3D
|
||||
|
||||
|
||||
var _players: Array[Player] = []
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
collision_polygon.polygon = polygon
|
||||
collision_polygon.depth = depth
|
||||
|
||||
|
||||
func _physics_process(delta: float) -> void:
|
||||
for player in _players:
|
||||
player.velocity = lerp(player.velocity, Vector3.ZERO, friction * delta)
|
||||
|
||||
|
||||
func _on_body_entered(body: Node3D) -> void:
|
||||
if body is Player:
|
||||
_players.append(body)
|
||||
|
||||
|
||||
func _on_body_exited(body: Node3D) -> void:
|
||||
if body is Player:
|
||||
_players.erase(body)
|
31
objects/sand_pit.tscn
Normal file
31
objects/sand_pit.tscn
Normal file
|
@ -0,0 +1,31 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://bfic5n608nc5j"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://djx2x3jjn01w2" path="res://assets/textures/world/sand.png" id="1_yg8om"]
|
||||
[ext_resource type="Script" path="res://objects/sand_pit.gd" id="2_vtyum"]
|
||||
|
||||
[sub_resource type="StandardMaterial3D" id="StandardMaterial3D_r0cip"]
|
||||
shading_mode = 2
|
||||
specular_mode = 2
|
||||
albedo_texture = ExtResource("1_yg8om")
|
||||
metallic_specular = 0.0
|
||||
uv1_triplanar = true
|
||||
uv1_world_triplanar = true
|
||||
texture_filter = 0
|
||||
|
||||
[node name="SandPit" type="CSGPolygon3D" node_paths=PackedStringArray("collision_polygon")]
|
||||
process_physics_priority = 100
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0, 0)
|
||||
depth = 0.03
|
||||
material = SubResource("StandardMaterial3D_r0cip")
|
||||
script = ExtResource("2_vtyum")
|
||||
friction = 9.0
|
||||
collision_polygon = NodePath("Area3D/CollisionPolygon3D")
|
||||
|
||||
[node name="Area3D" type="Area3D" parent="."]
|
||||
collision_layer = 0
|
||||
collision_mask = 16
|
||||
|
||||
[node name="CollisionPolygon3D" type="CollisionPolygon3D" parent="Area3D"]
|
||||
|
||||
[connection signal="body_entered" from="Area3D" to="." method="_on_body_entered"]
|
||||
[connection signal="body_exited" from="Area3D" to="." method="_on_body_exited"]
|
|
@ -1,9 +1,10 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://dllug6vijj18o"]
|
||||
[gd_scene load_steps=9 format=3 uid="uid://dllug6vijj18o"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cybm74xwbsivx" path="res://objects/canny_cat.tscn" id="1_8qiqb"]
|
||||
[ext_resource type="MeshLibrary" uid="uid://cbs170roel08g" path="res://assets/mesh_libraries/w1/w1_floors.meshlib" id="2_ohutf"]
|
||||
[ext_resource type="MeshLibrary" uid="uid://bqxgr3arh0i7f" path="res://assets/mesh_libraries/w1/w1_walls.meshlib" id="3_k3r2h"]
|
||||
[ext_resource type="PackedScene" uid="uid://cdpgby3r6xe4n" path="res://objects/goal_post.tscn" id="4_71ems"]
|
||||
[ext_resource type="PackedScene" uid="uid://bfic5n608nc5j" path="res://objects/sand_pit.tscn" id="5_7n16u"]
|
||||
|
||||
[sub_resource type="ProceduralSkyMaterial" id="ProceduralSkyMaterial_akirf"]
|
||||
|
||||
|
@ -26,18 +27,7 @@ mesh_library = ExtResource("2_ohutf")
|
|||
cell_size = Vector3(1, 1, 1)
|
||||
cell_center_y = false
|
||||
data = {
|
||||
"cells": PackedInt32Array(0, 0, 0, 0, 65535, 0, 65535, 65535, 0, 65535, 0, 0, 65534, 0, 0, 65534, 65535, 0, 65534, 65534, 0, 65535, 65534, 0, 0, 65534, 0, 1, 65534, 0, 1, 65535, 0, 1, 0, 0, 0, 1, 0, 65535, 1, 0, 65534, 1, 0, 1, 1, 0, 1, 2, 0, 0, 2, 0, 65535, 2, 0, 65534, 2, 0, 65533, 2, 0, 65533, 1, 0, 65533, 0, 0, 65533, 65535, 0, 65533, 65534, 0, 65533, 65533, 0, 65534, 65533, 0, 0, 65533, 0, 65535, 65533, 0, 2, 0, 0, 2, 1, 0, 3, 2, 0, 3, 1, 0, 0, 65532, 0, 65535, 65532, 0, 65534, 65532, 0, 65533, 65532, 0, 65532, 65532, 0, 65532, 65533, 0, 65532, 65534, 0, 65532, 65535, 0, 65532, 1, 0, 65532, 0, 0, 65532, 2, 0, 65532, 3, 0, 65533, 3, 0, 65534, 3, 0, 65535, 3, 0, 1, 3, 0, 2, 3, 0, 3, 3, 0, 0, 3, 0, 4, 3, 0, 4, 2, 0, 4, 1, 0, 2, 2, 0, 5, 4, 0, 4, 4, 0, 3, 4, 0, 2, 4, 0, 1, 4, 0, 0, 4, 0, 0, 5, 0, 65535, 5, 0, 65534, 5, 0, 65533, 5, 0, 65533, 4, 0, 65532, 4, 0, 65534, 4, 0, 65535, 4, 0, 3, 5, 0, 4, 5, 0, 5, 5, 0, 2, 5, 0, 1, 5, 0, 65532, 5, 0, 65531, 5, 0, 65531, 4, 0, 65531, 3, 0, 65531, 2, 0, 65531, 1, 0, 65530, 1, 0, 65530, 0, 0, 65530, 65535, 0, 65530, 65534, 0, 65530, 65533, 0, 65531, 65534, 0, 65531, 65535, 0, 65531, 0, 0, 65531, 65533, 0, 65531, 65532, 0, 65531, 65531, 0, 65532, 65531, 0, 65533, 65531, 0, 65534, 65531, 0, 65535, 65531, 0, 0, 65531, 0, 6, 65531, 0, 5, 1, 0, 5, 2, 0, 5, 3, 0, 6, 0, 0, 6, 65535, 0, 6, 65534, 0, 5, 0, 0, 7, 65535, 0, 7, 65534, 0, 8, 65533, 0, 8, 65534, 0, 7, 0, 0, 6, 1, 0, 6, 2, 0, 6, 4, 0, 6, 3, 0, 7, 2, 0, 7, 1, 0, 8, 1, 0, 8, 0, 0)
|
||||
}
|
||||
metadata/_editor_floor_ = Vector3(0, 0, 0)
|
||||
|
||||
[node name="FrictionFloor" type="GridMap" parent="." groups=["friction_floor"]]
|
||||
mesh_library = ExtResource("2_ohutf")
|
||||
cell_size = Vector3(1, 1, 1)
|
||||
cell_center_y = false
|
||||
collision_layer = 2
|
||||
collision_mask = 0
|
||||
data = {
|
||||
"cells": PackedInt32Array(4, 0, 1, 3, 0, 1, 3, 65535, 1, 2, 65535, 1, 2, 65534, 1, 2, 65533, 1, 1, 65533, 1, 1, 65532, 1, 1, 65531, 1, 2, 65531, 1, 2, 65530, 1, 3, 65530, 1, 3, 65531, 1, 3, 65532, 1, 2, 65532, 1, 4, 65532, 1, 4, 65531, 1, 5, 65531, 1, 5, 65532, 1, 5, 65533, 1, 6, 65532, 1, 6, 65533, 1, 4, 65533, 1, 3, 65533, 1, 3, 65534, 1, 4, 65534, 1, 5, 65534, 1, 5, 65535, 1, 4, 65535, 1)
|
||||
"cells": PackedInt32Array(0, 65535, 0, 65535, 65535, 0, 65535, 0, 1441792, 65534, 0, 0, 65534, 65535, 0, 65534, 65534, 0, 65535, 65534, 0, 0, 65534, 0, 1, 65534, 0, 1, 65535, 0, 1, 0, 1441792, 65535, 1, 0, 65534, 1, 0, 1, 2, 0, 0, 2, 0, 65535, 2, 0, 65534, 2, 0, 65533, 2, 0, 65533, 1, 0, 65533, 0, 0, 65533, 65535, 0, 65533, 65534, 0, 65533, 65533, 0, 65534, 65533, 0, 0, 65533, 0, 65535, 65533, 0, 2, 1, 1441792, 3, 2, 0, 3, 1, 0, 0, 65532, 0, 65535, 65532, 0, 65534, 65532, 0, 65533, 65532, 0, 65532, 65532, 0, 65532, 65533, 0, 65532, 65534, 0, 65532, 65535, 0, 65532, 1, 0, 65532, 0, 0, 65532, 2, 0, 65532, 3, 0, 65533, 3, 0, 65534, 3, 0, 65535, 3, 0, 1, 3, 0, 2, 3, 0, 3, 3, 0, 0, 3, 0, 4, 3, 0, 4, 2, 0, 4, 1, 0, 2, 2, 0, 5, 4, 0, 4, 4, 0, 3, 4, 0, 2, 4, 0, 1, 4, 0, 0, 4, 0, 0, 5, 0, 65535, 5, 0, 65534, 5, 0, 65533, 5, 0, 65533, 4, 0, 65532, 4, 0, 65534, 4, 0, 65535, 4, 0, 3, 5, 0, 4, 5, 0, 5, 5, 0, 2, 5, 0, 1, 5, 0, 65532, 5, 0, 65531, 5, 0, 65531, 4, 0, 65531, 3, 0, 65531, 2, 0, 65531, 1, 0, 65530, 1, 0, 65530, 0, 0, 65530, 65535, 0, 65530, 65534, 0, 65530, 65533, 0, 65531, 65534, 0, 65531, 65535, 0, 65531, 0, 0, 65531, 65533, 0, 65531, 65532, 0, 65531, 65531, 0, 65532, 65531, 0, 65533, 65531, 0, 65534, 65531, 0, 65535, 65531, 0, 0, 65531, 0, 6, 65531, 0, 5, 1, 0, 5, 2, 0, 5, 3, 0, 6, 0, 0, 6, 65535, 0, 6, 65534, 0, 5, 0, 0, 7, 65535, 0, 7, 65534, 0, 8, 65533, 0, 8, 65534, 0, 7, 0, 0, 6, 1, 0, 6, 2, 0, 6, 4, 0, 6, 3, 0, 7, 2, 0, 7, 1, 0, 8, 1, 0, 8, 0, 0, 1, 1, 1441792, 0, 1, 1441792, 3, 0, 1441792, 4, 0, 1441792, 4, 65535, 1441792, 3, 65535, 1441792, 2, 65534, 1441792, 2, 65533, 1441792, 1, 65533, 1441792, 1, 65532, 1441792, 1, 65531, 1441792, 2, 65531, 1441792, 2, 65530, 1441792, 3, 65530, 1441792, 3, 65531, 1441792, 2, 65532, 1441792, 4, 65532, 1441792, 4, 65531, 1441792, 5, 65531, 1441792, 5, 65532, 1441792, 5, 65533, 1441792, 5, 65534, 1441792, 5, 65535, 1441792, 4, 65534, 1441792, 4, 65533, 1441792, 6, 65533, 1441792, 6, 65532, 1441792, 3, 65532, 1441792, 3, 65533, 1441792, 3, 65534, 1441792, 2, 65535, 1441792, 2, 0, 1441792, 0, 0, 1441792)
|
||||
}
|
||||
metadata/_editor_floor_ = Vector3(0, 0, 0)
|
||||
|
||||
|
@ -59,20 +49,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.926551, 3.63641)
|
|||
[node name="GoalPost" parent="." instance=ExtResource("4_71ems")]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -2, -2.38419e-07, -4)
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="SubViewportContainer" type="SubViewportContainer" parent="CanvasLayer"]
|
||||
custom_minimum_size = Vector2(128, 128)
|
||||
stretch = true
|
||||
|
||||
[node name="s" type="SubViewport" parent="CanvasLayer/SubViewportContainer"]
|
||||
transparent_bg = true
|
||||
handle_input_locally = false
|
||||
size = Vector2i(128, 128)
|
||||
render_target_update_mode = 4
|
||||
|
||||
[node name="Camera3D" type="Camera3D" parent="CanvasLayer/SubViewportContainer/s"]
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 2.545, 10, 0)
|
||||
projection = 1
|
||||
current = true
|
||||
size = 20.0
|
||||
[node name="CSGPolygon3D" parent="." instance=ExtResource("5_7n16u")]
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 2, 0, -4)
|
||||
polygon = PackedVector2Array(0, -1, 1, -1, 3, 0, 3, 2, 2, 3, -1, 2, -2, 0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue