#Help triggering a beginner simple collision

1 messages Β· Page 1 of 1 (latest)

ashen trail
#

Hi I'm new to unity, and I'm trying to detect a simple colllision but for some reaosn it's not tirggering:

I have two objects:

  1. A "Sword" which has its translation attached to the Player's translation (so it moves with him).
    This has a Box Colider with IsTrigger checked,
    ||if it matters: this object also has an animation attached to it so that when I press space it slashes aross the screen and comes back to it's original position.||
  2. an "Enemy" which has a rigid body and box colider component, as well as a script with the following:
public class EnemyDie : MonoBehaviour
{
    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnTriggerEnter(Collider other)
    {
        Console.Write(gameObject.name + "has collided with " + other.gameObject.name);
    }
}

For some reason the trigger isn't triggering and I never get the message in the console.

urban silo
#

Is it 2d or 3d

ashen trail
urban silo
#

Ah okay, otherwise I would have found the error :D sorry

ashen trail
ashen trail
urban silo
#

It has a rigidbody right

ashen trail
#

(red)

urban silo
#

and purple

#

Or whatever the collider is

ashen trail
#

well yes, but the purple (player) isn't a detecting/relevant object

#

the detection is between the enemy (red) and the sword (white)

urban silo
#

Does white have a rigidbody

ashen trail
#

no

#

only a box colider with IsTrigger

urban silo
#

have you tried giving it a rigidbody

ashen trail
#

lemme try

urban silo
#

ok

ashen trail
#

(I think I did but ill try agai)

#

still nothing :/

#

could it have anything to do with the fact that the sword has an animation?

urban silo
#

I don't know sorry

ashen trail
sudden surge
#

https://unity.huh.how/physics-messages
It's likely a problem with how you're moving these objects. A moving collider should have a rigidbody, if it's being moved by its transform (eg. animation) it needs to be kinematic.
The enemy should also be moved via rigidbody forces, or it too needs to be kinematic.

ashen trail
#

Hi @sudden surge, The Enemy(red) has a rigid body and collider, so does the sword(white) but the sword's collider has IsTrigger
I'm a little confused as what you're hinting at since I seem to have already been following your instructions πŸ€”

sudden surge
#

is the sword's marked as kinematic?

#

and how do you move the enemy?

ashen trail
ashen trail
#

oh wait

#

I miss said something

#

the sword is NOT a rigid body

#

only a collider

#

since I don't want it to.. well fall on the ground xD

sudden surge
#

add a kinematic rigidbody

ashen trail
#

also it seems to malfunction a lot when I make the sword rigid

#

alright lemme try mess around and get back to you, thing is my sword really hates being a rigid body since its translation is not a function of physics

#

hi @sudden surge, so my "sword" movement is simply just a result of it being the child of the "Player" object, so it copies its translation changes.. If I make it a Rigid body in any way then it stops following the player and becomes its own detached entity.

Do you have any suggestions on how to remedy this problem, or a difference course of action that you recommend?

sudden surge
#

Are you continually ignoring the word kinematic?

ashen trail
#

no I

#

OH

#

WAIT

#

OMG

#

I'M SO SORRY @sudden surge i've been doinig a horrendously silly mistake

#

ok

#

it's kinematic

#

πŸ˜… πŸ˜… πŸ˜… πŸ˜…

#

so um, it still not detecting tho πŸ˜“

#

so sorry about that is kinematic stupidity of mine

sudden surge
#

I'm not sure what else it would be, just make sure there's no compilation errors, the script is attached to the object you expect it to, you've not changed some extra settings while debugging, the collision layers intereract in the layer collision matrix. Perhaps go through the resource I linked and make sure everything makes sense

ashen trail
sudden surge
#

It doesn't matter which one its on, as long as it's on the object that has the rigidbody

steel heart
#

You'll need to share some more info if you still have the issue: screenshots of inspectors of the sword and the enemy, as well as a screenshot of the console after they are supposed to have collided at runtime(maybe even a screenshot of the whole editor window with the console open).
Also, just to be safe use Debug.Log instead of Console to log messages.