#Duplicated nodes work. Original ones do not.

1 messages · Page 1 of 1 (latest)

frosty panther
#

I'm having a super weird effect with a Crate I'm trying to make for my 3D game.
The basic idea is that among other things, I can pickup crates, place them, and stand on top of them to move. If I stand on top of them, I want to disable both the ability to grab them and also their physics with the player so they don't go flying.

For that (at the beginning of the video) I have a FloorCheckComponent on the player's feet which checks whatever is in contact and interacts with it. Whenever it detects an object, it disables its physics and etc. However, the collision has a weird effect:
It glitches in and out of collision (between the FloorChecker and the crate) IF and ONLY IF the Crate is the original scene I dragged from the FileSystem onto the current scene. If I duplicate the Crate subscene, they work fine, as shown in the video, it's just the original one that does this glitch. Does anyone know why is this happening? Really feels like magic to me.

#

Heres the FloorCheckComponent code that runs:

func expand():
    if owner is Player: print("PLAYER 0.5")
    $CollisionShape3D.shape.radius = 0.5
    
func unexpand():
    if owner is Player: print("PLAYER 0.1")
    $CollisionShape3D.shape.radius = 0.1


func _on_body_entered(body):
    if is_instance_valid(body.owner):
        # If body that contacted FloorCheckComponent is Crate
        if body != node_to_move and body.owner is BaseObject and body.owner.rigidbody:
            print(body.owner)
            # To the Object that is being stepped over, add that this player is stepping in it
            body.owner.add_character_stepping(self, owner)
            # Save on the FloorCheckComponent which objects are being stepped over
            stepping_on_objects.push_back(body.owner)

func _on_body_exited(body):
    if is_instance_valid(body.owner):
        # If body that left FloorCheckComponent is Crate
        if body != node_to_move and body.owner is BaseObject and body.owner.rigidbody:
            # Tell the Object that this player stopped stepping over it
            # The Object will later run "stopped_stepping" defined below
            body.owner.remove_character_stepping(self, owner)
    else:
        stopped_stepping(body.owner)

func stopped_stepping(object):
    # Remove from local array of objects being stepped over and unexpand collider if array empty
    stepping_on_objects.remove_at(stepping_on_objects.find(object))
    if len(stepping_on_objects) == 0:
        unexpand()
#

Here's the code on the BaseObject (Crate):


func add_character_stepping(floor_check, stepper):
    # Expand the player FloorCheckComponent to detect in a larger area
    floor_check.expand()
    # Save to array the stepper
    characters_stepping.push_back(stepper)
    # Freeze physics only if player is stepper
    if stepper is Player:
        $RigidBody3D/CrateGizmo.show()
        player_is_stepping = true
        if is_instance_valid(rigidbody):
            rigidbody.freeze = true
        freeze_pushing = true
    
func remove_character_stepping(floor_check, stepper):
    await get_tree().create_timer(0.2).timeout
    # Tell player FloorCheckComponent to remove this object as being stepped over
    if is_instance_valid(floor_check):
        floor_check.stopped_stepping(self)
    # Remove stepped from local array
    characters_stepping.remove_at(characters_stepping.find(stepper))
    # Un-Freeze physics only if player left stepping
    if stepper is Player:
        $RigidBody3D/CrateGizmo.hide()
        player_is_stepping = false
        if is_instance_valid(rigidbody):
            rigidbody.freeze = false
            freeze_pushing = false