Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Why Isn't My Collision Script Working?

A topic by Gavin D.B. created Apr 03, 2021 Views: 303 Replies: 7
Viewing posts 1 to 9
Submitted

My Collision Script Isn't working, if any of you guys know what is wrong please help!

Below is my collision script:


    void OnCollisionEnter(Collision collisionInfo)

    {

        if (collisionInfo.collider.tag == "1")

        {

            transform.position = homeBase;

            local = 0;

        }

    }

Submitted (2 edits)

It Still Doesn't Work But Thanks For The Suggestion.

Is this unity? If so then instead of collisonInfo.collider.tag=="1", use collisionInfo.collider.gameObject.CompareTag("1")

Submitted

My thoughts are 1. If your game is 2d it should be OnCollisionEnter2D. 2. if your collider is a trigger(for either one I think) it should be OnTriggerEnter. Im not so sure about this but maybe it will help.

Submitted

Use collisionInfo.transform.tag, collider wont work.

Submitted

It's a 2D game

Submitted

Try this:

    void OnCollisionEnter2D(Collision collisionInfo)

    {

        if (collisionInfo.transform.tag == "1")

        {

            transform.position = homeBase;

            local = 0;

        }

    }

(1 edit)

In case you haven't fixed it yet. Make sure the object you want to collide with has the tag "1". And since your game is 2D you need to use OnCollisionEnter2D:

void OnCollisionEnter2D(Collision2D collisionInfo)

{

     if (collisionInfo.collider.tag == "1")

    {

        transform.position = homeBase;

         local = 0;

     }

}