0 votes

In short, when I move my rigidbody away from X = 0 and Z = 0,(y doesn't matter,and least i dont think it does..) it starts to break and just flip out like crazy :(
Scene tree:

  • Rigidbody

    • Collision
    • raycasts (script is attched to 4 raycasts, one at each corner)


extends RayCast

onready var physbod = get_parent()
export var dampness = 0.025
export var stiffness = 0.25
export var relaxedlength = -1
var prev_compression = 0
var y_force = 0

func _ready():
    cast_to.y = relaxedlength

func _physics_process(delta):
    if is_colliding():
        #calculate the compression ratio -0 means spring is fully relaxed, 1 means its fully compressed
        var compression = 1 - (global_transform.origin.distance_to(get_collision_point()) / abs(relaxedlength))

        #calculate forces and apply them
        y_force = stiffness * compression * abs(relaxedlength)
        y_force += dampness * (compression - prev_compression) / delta

        physbod.apply_impulse(get_collision_point() , transform.basis.y * y_force)
        prev_compression = compression

        prev_compression = 0
Godot version 3.3.2 Stable
in Engine by (26 points)

1 Answer

+1 vote
Best answer

have your read this in the RigidBody docs?

The position uses the rotation of the global coordinate system, but is centered at the object's origin.

So i think when the "physbod" leaves the worlds zero coordinate the force isn't applied properly.

by (3,932 points)
selected by

can't believe I missed this!
tysm its fixed now :)

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.