0 votes

A rigidbody projectile is supposed to be deleted when it hits the enemy. Instead, it starts to calculate and preform what it would do if it weren't deleted, as in it starts to visibly bounce off the target. I don't understand why this happens because the deletion happens in a single tick of the physics process function. Additionally, when aiming straight down, the projectile goes into the ground a little bit and then gets pushed back up. These two errors become more apparent the less powerful the platform is. I don't know what is going on here and the Godot discord doesn't seem to either.

This is my script for the projectile in question:

extends RigidBody

var weilder; #holds the player so the bullet remembers who shot it out

func instance_ready(): #custom function since using _ready would trigger before an instance has been created, during preload.
    translation = weilder.get_node("Head").global_transform.origin;
    rotation = weilder.get_node("Head").global_transform.basis.get_euler();
    set_linear_velocity(weilder.get_node("Head").global_transform.basis.z*-25);
    set_contact_monitor(true)
    set_max_contacts_reported(1)

func _physics_process(delta):
    var bodies = get_colliding_bodies();
    if (bodies.size() != 0):
        var target = bodies[0];
        #get_node("explosive_pill").visible = false;
        if (target.get_filename() == "res://PlayerData/player.tscn"):

            #sleeping = true;
            #get_node("explosive_pill").visible = false;
            #self.get_node("CollisionShape").disabled = true;

            print("Hit detected @ ", target.name, " @ time = ", OS.get_time());
            target.health -= 20;
            queue_free()
            print(target.health)
            if (target.health <= 0):
                target.kill();

Source code

Video of the issue

asked Jun 25 in Engine by Gamepro5 (46 points)

1 Answer

0 votes
Best answer

from the docs:

Array getcollidingbodies ( ) const

Returns a list of the bodies colliding with this one. Use contactsreported to set the maximum number reported. You must also set contactmonitor to true.

Note: The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead.

use Body_entered Signal !!

answered Jun 26 by brainbug (268 points)
selected Jun 29 by Gamepro5

It works but the body entered signal does not detect when a player walks into the body while it's laying on the ground.

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.