implement physics props
This commit is contained in:
parent
1be53bf7bb
commit
6e783e0e57
9 changed files with 159 additions and 4 deletions
14
Scripts/Player/PropPusher.gd
Normal file
14
Scripts/Player/PropPusher.gd
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
extends Node
|
||||
|
||||
@export var controller : CharacterBody3D
|
||||
@export_range(0.0, 500.0, 0.1) var force : float = 1
|
||||
@export var enabled : bool = false
|
||||
|
||||
func _physics_process(_delta: float) -> void:
|
||||
if enabled and controller.get_slide_collision_count() > 0:
|
||||
var collision = controller.get_last_slide_collision()
|
||||
if collision.get_collider() is RigidBody3D:
|
||||
var direction = -collision.get_normal()
|
||||
var speed = clamp(controller.velocity.length(), 1.0, 10.0)
|
||||
var impulse_position = collision.get_position() - collision.get_collider().global_position
|
||||
collision.get_collider().apply_impulse(direction * speed * force, impulse_position)
|
||||
Loading…
Add table
Add a link
Reference in a new issue