37 lines
852 B
GDScript3
Raw Normal View History

extends RigidBody
class_name BodyBase
export(int) var player_id
var ingame : bool = false
var ground : Spatial
var current_angle : float
func on_ingame():
ground = get_parent().get_node("Arena").get_node("ground")
ingame = true
axis_lock_linear_x = true
func _physics_process(delta):
if ingame:
current_angle = ((-transform.basis.z).angle_to(ground.transform.basis.y))
var rot_vector = (-transform.basis.z).cross(ground.transform.basis.y)
2020-02-02 14:36:16 +01:00
var _should_fix_torque = false
2020-02-02 12:59:47 +01:00
for body in get_colliding_bodies():
if body.name == "StaticBody":
2020-02-02 14:36:16 +01:00
_should_fix_torque = true
if _should_fix_torque:
if current_angle > 0.3:
apply_torque_impulse(rot_vector * current_angle * 7)
apply_impulse(transform.basis.xform(Vector3.ZERO), -(transform.basis.y) * 0.05)
# if current_angle < 0.1:
# angular_velocity.x = 0