#3D Rigidbodies falling through ground and acting buggy

24 messages · Page 1 of 1 (latest)

rugged crag
#

For some reason the rigidbodies in my game glitch around and phase through walls randomly? I'm pretty sure there's nothing in their code that would cause them to do this but I'll just post it here anyways

extends RigidBody3D

@export var carrying = false

var carrier : Node3D = null

@onready var offset = $CollisionShape3D

@onready var originalParent : Node

var carrySlotID : int = 0

func _ready() -> void:
    originalParent = get_parent()

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
    if(carrier != null && carrying):
        position = Vector3(0,1 + offset.scale.y * carrySlotID,-0.5)
        
        rotation = Vector3(0,0,0)
        
        linear_velocity = Vector3(0,0,0)
        
        if(Input.is_action_just_pressed("Drop")):
            reparent(originalParent)
            carrier.amountCarrying -= 1
            carrying = false
            carrier = null
    
    var touchers = $Area3D.get_overlapping_areas()
    for i in touchers:
        _check_area(i)


func _check_area(area: Area3D) -> void:
    if(area.is_in_group("Player") && area.get_parent().is_multiplayer_authority() && !carrying):
        if(Input.is_action_just_pressed("Depositing")):
            carrier = area.get_parent()
            carrying = true
            
            var modelPropNode = carrier.model.props
            
            reparent(modelPropNode,false)
            
            position = Vector3(0,1,-0.5)
            
            carrySlotID = carrier.amountCarrying
            
            carrier.amountCarrying += 1
            
            print(carrier.amountCarrying)

#

I should mention too the area is all a csgcombiner with collisions so if that causes issues that'd make sense

rugged crag
#

can someone help-

short spire
#

First, if you haven't already, open project setting, find physic 3d category and change physic engine from Default to Jolt

rugged crag
merry anchor
rugged crag
merry anchor
rugged crag
#

Ahh ok

#

Ill try it out and if thay doesn't fix it I'll use jolt3d

merry anchor
#

Ah, you should use jolt either way lol

rugged crag
#

So true

blazing hatch
# rugged crag For some reason the rigidbodies in my game glitch around and phase through walls...

I would either freeze the Rigidbody while you're carrying it so you can set position and rotation without any physics issues
Or use physics to keep that Rigidbody in position by constantly applying forces/setting velocity.
With the first solution the Object wont interact with the environment anymore, with the latter it will still collide with walls and such but is not really fixed to that carry offset position.

IntegrateForces has its uses but not really necessary here.

And absolutely switch to jolt before doing anything else 😉

rugged crag
rugged crag
pulsar grail
#

note that setting velocities directly in _integrate_forces is also fine

#

you just don't want to say the position and rotation directly if the body is not frozen

#

rigid bodies are controlled by the physics engine when they're not frozen

#

and for it to simulate them correctly, it needs to know their linear and angular velocity and move them based on that

pulsar grail
pulsar grail
#

the rigid body itself doesn't like to be scaled by anything

#

including parents

rugged crag
#

ok yeah it was the parent