Inverted Collider Response

With the bug of exiting the map, the scorer only adds when you collide from the outside-in. When you hit the wall from the inside of the map, it doesn’t function properly.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class scorer : MonoBehaviour
{
    double hits = 0;

    void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.tag != "Hit")
        {
            hits++;
            Debug.Log("You have bumped into a wall " + hits + " many times.");
        }
        
    }
}

Hi,

Welcome to our community! :slight_smile:

What do you mean by “from the inside of the map”?

Since we are using the OnCollisionEnter method, our code block gets executed only in the frame when two colliders touch each other for the first time in the entire collision event. If they are already touching, the method won’t get called because no collider enters another one. Could that be the reason for the behaviour? Check all colliders in your scene.

The map or arena is the platform the player (Dodgy) can be on. On one of the course videos, we learned about having colliding with an obstacle impacting the score only once. This made it so when we hit a wall, it will turn red and only add 1 point to the score. By pressing on one of the sides of the arena, you are able to glitch Dodgy out of the map without adding a collision point. When you glitch back in is when the point is added.

I understand that I haven’t explained the above issues very clearly so will it be easier if I send you my Unity project as well as course references? If so, I will do so at noon.

Thanks for elaborating on the problem further. I think I know what you mean. :slight_smile:

The enabled colliders can always collide with one another. Unless we implement a restriction which ensures that the score increases only once per collision, the score will always increase.

Being able to move dodgy beyond the area does not have anything to do with the score. It’s another problem, and this is where you could start debugging the project by adding Debug.Logs to figure out what is going on in the scene during runtime. A lot is happening in the physics simulation, and it is not always possible to see everything.

Also try to decrease the speed of your dodgy for testing purposes. Since Unity’s physics simulation is highly optimised, it does not check everything every frame. If the problem occurs only if the dodgy moves fast, you could, for example, increase a few values in the Physic Settings.

And you could also try to remove the current solution (transform.position) with AddRelativeForce or AddForce (see the examples in the API). That’s not “impossible” but could be a bit challenging.

I tried both methods but with no luck was it working. I am going to just drop the issue for now as it is just a bug and I have understood all aspects of what Section II was teaching. The issue could be an error somewhere else in the code, but I feel debugging and rewatching the course is just a waste of time as I have already learnt the concepts.

Thank you for your help and concern over this topic!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms