This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
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

in Engine by (52 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 !!

by (300 points)
selected by

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 Frequently asked questions and 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 [email protected] with your username.