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"]
|
Loading…
Add table
Add a link
Reference in a new issue