#Unity: `void OnCollisionEnter()` issue.

1 messages ยท Page 1 of 1 (latest)

lavish cargo
#
void OnCollisionEnter(UnityEngine.Collision coll)
    {
        Debug.Log("COLLIDED");
        if ( coll.gameObject.tag == "hazard" && coolD)
        {
            Debug.Log("DEDUCTED HP");
            PlayerRb.AddForce(new Vector2(100,100));
            Invoke("ResetCoolD", .4f);
         
        }
    }

i made some oncollisionenter code but whenever the condition is met it won't do what i tell it to do
is there anything wrong with the way i've set it out?

fathom fossil
#

unless thats some global variable

lavish cargo
#

how come

#

coolD is a global variable yes

#

boolean

fathom fossil
#

Alright. So what is it doing? What do you want it to do?

lavish cargo
#

As of now

#

It is doing nothing when the condition is met

#

condition is met (or supposed to be met) when the player interacts with an object of the tag "hazard" and if the coolD variable is true

#

when it is met i want it to launch the player in a specific direction

thorn hemlock
#

Well your addforce could be too little, your object could be missing a tag

#

Your player could be missing a rigidbody or collider

lavish cargo
lavish cargo
lavish cargo
#

oh

#

ill try that thanks!

#

might be it

humble tendon
#

Yep. It is the case (probably)

lavish cargo
#

nope it doesn't

#

oh wait nvm

#

it works