2020-02-02 10:28:45 +01:00
|
|
|
extends RigidBody
|
2020-02-01 12:02:39 +01:00
|
|
|
class_name BodyBase
|
2020-02-01 11:31:24 +01:00
|
|
|
|
2020-02-01 13:00:25 +01:00
|
|
|
|
|
|
|
export(int) var player_id
|
2020-02-02 10:28:45 +01:00
|
|
|
var ingame : bool = false
|
|
|
|
var ground : Spatial
|
|
|
|
var current_angle : float
|
2020-02-01 13:00:25 +01:00
|
|
|
|
2020-02-01 11:31:24 +01:00
|
|
|
|
2020-02-02 10:28:45 +01:00
|
|
|
func on_ingame():
|
|
|
|
ground = get_parent().get_node("Arena").get_node("ground")
|
|
|
|
ingame = true
|
2020-02-02 11:27:37 +01:00
|
|
|
axis_lock_linear_x = true
|
2020-02-02 10:28:45 +01:00
|
|
|
|
2020-02-01 11:31:24 +01:00
|
|
|
|
2020-02-02 12:51:45 +01:00
|
|
|
func _physics_process(delta):
|
2020-02-02 10:28:45 +01:00
|
|
|
if ingame:
|
2020-02-02 11:27:37 +01:00
|
|
|
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)
|
|
|
|
|
2020-02-02 15:14:35 +01:00
|
|
|
# if current_angle < 0.1:
|
|
|
|
# angular_velocity.x = 0
|
|
|
|
|