41 lines
1.1 KiB
GDScript
41 lines
1.1 KiB
GDScript
class_name Platform extends RigidBody3D
|
|
|
|
#angular_velocity = (
|
|
#basis.x.cross(target_basis.x) +
|
|
#basis.y.cross(target_basis.y) +
|
|
#basis.z.cross(target_basis.z)
|
|
#)*TURNING_LERP_WEIGHT/body_state.step
|
|
|
|
const BASE_LINEAR_SPRING: float = 100.0
|
|
const BASE_ANGULAR_SPRING: float = 1000.0
|
|
const BASE_LINEAR_DAMP: float = 10.0
|
|
const BASE_ANGULAR_DAMP: float = 100.0
|
|
|
|
@export var spring: float = 1.0
|
|
|
|
@onready var _origin := global_position
|
|
@onready var _angular_origin := global_basis
|
|
|
|
func _ready() -> void:
|
|
linear_damp = BASE_LINEAR_DAMP*spring
|
|
angular_damp = BASE_ANGULAR_DAMP*spring
|
|
|
|
func _locus() -> Vector3:
|
|
return _origin
|
|
|
|
func _angular_locus() -> Basis:
|
|
return _angular_origin
|
|
|
|
func _integrate_forces(state: PhysicsDirectBodyState3D) -> void:
|
|
state.apply_central_force(
|
|
(_locus() - global_position) *
|
|
BASE_LINEAR_SPRING*spring /
|
|
state.inverse_mass
|
|
)
|
|
var angular_locus := _angular_locus()
|
|
state.apply_torque((
|
|
global_basis.x.cross(angular_locus.x) +
|
|
global_basis.y.cross(angular_locus.y) +
|
|
global_basis.z.cross(angular_locus.z)
|
|
)*BASE_ANGULAR_SPRING*spring/state.inverse_inertia)
|