Obi Official Forum

Full Version: Odd collision detection behaviour for objects at non 90 degree angle
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello

I'm trying to use a script to detect when the gameobject the player gameobject has collided with and then run another line of code once detected.

The issue I am having is the player detects the other gameobject without physically touching it if the other gameobject is rotated at an angle that is not a multiple of 90. What seems to be happening is the other gameobject has an area around it with a rotation of 0-degrees. When the player enters this area it detects the other gameobject. In the screenshot below the white cube is the object I want to detect rotated to a 45-degree angle and the red cube is the area the player is detecting rotated 0-degrees.

[attachment=1606]

I've also included a screenshot of the white cube's collider setup.

[attachment=1607]

I want to fix this issue so the player only detects the other gameobject when physically colliding with it.

I'm not an experienced programmer and am at a loss for what to do so any help would be greatly appreciated. 

Thank you.

Below is the code I'm using to detect the object the player is colliding with.
Code:
private void Solver_OnCollision(ObiSolver solver, ObiSolver.ObiCollisionEventArgs e)
    {    
        foreach (Oni.Contact contact in e.contacts)
        {
            ObiColliderBase collider = ObiColliderWorld.GetInstance().colliderHandles[contact.bodyB].owner;

            print(collider.transform.gameObject);
(20-12-2022, 06:34 PM)Moon_Hermit Wrote: [ -> ]Hello

I'm trying to use a script to detect when the gameobject the player gameobject has collided with and then run another line of code once detected.

The issue I am having is the player detects the other gameobject without physically touching it if the other gameobject is rotated at an angle that is not a multiple of 90. What seems to be happening is the other gameobject has an area around it with a rotation of 0-degrees. When the player enters this area it detects the other gameobject. In the screenshot below the white cube is the object I want to detect rotated to a 45-degree angle and the red cube is the area the player is detecting rotated 0-degrees.



I've also included a screenshot of the white cube's collider setup.



I want to fix this issue so the player only detects the other gameobject when physically colliding with it.

I'm not an experienced programmer and am at a loss for what to do so any help would be greatly appreciated. 

Thank you.

Below is the code I'm using to detect the object the player is colliding with.
Code:
private void Solver_OnCollision(ObiSolver solver, ObiSolver.ObiCollisionEventArgs e)
    {    
        foreach (Oni.Contact contact in e.contacts)
        {
            ObiColliderBase collider = ObiColliderWorld.GetInstance().colliderHandles[contact.bodyB].owner;

            print(collider.transform.gameObject);

Hi!

Obi's CCD scheme uses speculative contacts, which means some contacts do not progress to actual collisions. To discard speculative contacts, check the contact distance. See the example at the end of the following page:

http://obi.virtualmethodstudio.com/manua...sions.html

kind regards,
Thank you! 

This has solved my problem everything is working as it should be.