3d – Triangle vs Sphere collision detection

I am working on collision detection for my 3D game, and I don’t really know how to approach this problem. I have an ellipsoid that i use for my player’s collision shape.

My idea is that I transform the vertex data in such a way that my ellipsoid can be represented as a sphere, which would make intersection testing easier. But the thing is, how would I know if there is a collision happening if the plane intersects with the sphere, but none of the vertices do?

I want a simple solution to this problem. No velocity vectors or predictions, just a static test to see if there is an intersection.

collision detection – How to make googly eyes

I want to make googly eyes in Game Maker Studio 2 and I’m kind of close to what I want.

I have a white circle object and a black circle object. When my black circle is colliding with the white circle its vspeed is positive, but it stops moving before it leaves the white circle.

I want the googly eyes to be attached to my player and enemies, but react randomly to walking, jumping, falling, etc.

physics – 3D collision response advice for complex meshes

I am trying to use my own collision detection system in Unity to speed up my game. My problem is that when rigid bodies sit on top of static bodies, they will balance unrealistically on one edge or a corner. I really just need a better way of fixing this issue, but I will explain further.

I have tried adding a force to the point of collision to try and “settle” the rigid body into place, and this sort of works, it’s just that once it has settled, it vibrates wildly just sitting on top of a static mesh… I can get it to either slowly float down into a settled position or it does it fast but vibrates wildly after settling on a static mesh.

I would appreciate any ideas at all, even if they are bad ones. Thank you.

Character controller collision edge cases

Im trying to implement a basic 3d character controller. The way i currently do collision is; i check wether or not the character is inside any geometry before movement. If this is the case, i find the closest point of this geometry, and subtract the vector from the character to the point from the characters velocity. This works for some surfaces, but of course has a lot of issues. There are two that i am trying to figure out right now.

  1. If the character moves into a wall and the floor at the same time, it will be moved out in two frames, because they are seperate objects. One way to fix this is to do the check two times, but this amount increases by one for every object the character moves into, and i do not know the amount beforehand.

  2. If the character moves into a v shape, it will bounce back and forth between the two side each frame, because the collision detection moves it into the other side.

Does anyone know how these are commonly handeled?

collision detection – Godot raycast colliding too high

I am making an fps that uses a raycast for shooting. I used some suggestions taken from a few reddit pages, but it’s mostly my own code. It was working properly, until I noticed that when you shot up above the enemy, it still registered as a hit. Does anyone know why this might be happening? code:

func use_weapon():
Raycast.force_raycast_update()
if Raycast.is_colliding():
    var collider = Raycast.get_collider()
    if collider:
        if collider.has_method("takedamage"):
            collider.takedamage(10)

Regarding static collision resolution between two circles

I have some code that resolves the positions of two circles when they collide:

float fDist = sqrtf((c2->m_pos.x - c1->m_pos.x) * (c2->m_pos.x - c1->m_pos.x) + (c2->m_pos.y - c1->m_pos.y) * (c2->m_pos.y - c1->m_pos.y));
float fOverlap = 0.5f * (fDist - c1->m_radius - c2->m_radius);
   
c1->m_pos.x -= fOverlap * (c1->m_pos.x - c2->m_pos.x) / fDist;
c1->m_pos.y -= fOverlap * (c1->m_pos.y - c2->m_pos.y) / fDist;

c2->m_pos.x += fOverlap * (c1->m_pos.x - c2->m_pos.x) / fDist;
c2->m_pos.y += fOverlap * (c1->m_pos.y - c2->m_pos.y) / fDist;

However, I’m having the issue that, on large numbers of simulated circles, as the program “detection rate” slows down, fDist approaches (or even becomes) 0. As a result, the circles in question are blasted off into infinity, rather than “glide” apart from each other as I intend on doing. Is there an alternative method of achieving this effect? Or does my simulation simply run too slowly?

For more context, I am following javidx9’s tutorial on circle collisions.

collision detection – Cannot decide between using a MessageBus and entities for events in my ECS game

For example, let’s say that the player walks into an enemy and in response, a chain of events should occur (such as: his score goes up, the enemy dies, a cinematic starts, etc.)

I see two “proper” ways of accomplishing this:

Method 1:

There exists a global message bus in the game. Any system can emit events to it, and any other system can listen for some events from it. For example, the system handling the players score would look like this:

messageBus.listen("playerhitsenemy", e => {
  score += e.monsterType;
});

and the collision system may look like this:

messageBus.emit("playerhitsenemy", { monsterType: 5 });

Similarly, other systems can listen for the same event, such that when something happens, the CPU immediately moves from processing the current system to the other system processing this event. That is, the emit call is basically just a list of callbacks that are immediately invoked and sent the message.

Method 2:

The second method, instead, is to encode events / messages as entities themselves. That is, when an event occurs (such as the player hitting something in the collision detection system), this would happen:

let newEntity = new Entity();
newEntity.components.push(new MessageComponent());
newEntity.components.push(new MessagePlayerHitsEnemyComponent(5));
entityAdmin.spawnNewEntitiy(newEntity);

That is, a new “message” entity is created, and it is given the generic Message component and the concrete event component type as well, MessagePlayerHitsEnemy.

Then, all systems interested in these messages would have something like this in their execute function:

for (let entity of entityAdmin.query(MessagePlayerHitsEnemyComponent) {
  let monsterType = entity.getComponent<MessagePlayerHitsEnemyComponent>();
 
  score += monsterType;
}

And then at the end of the frame there would be a system whose responsibility was deleting all messages, like so:

for (let entity of entityAdmin.query(MessageComponent) {
  entityAdmin.remove(entity);
}

I cannot decide which is better. The first method seems simpler and probably more efficient in Javascript, considering it’s just immediately invoking all the requested functions. However, the second one seems more “correct”, in each system is iteratively processed. That is, first the collision system runs in its entirety, then the scoring system, etc. There is no “jumping around” from system to system during execution. Each system processes everything in its entirety, and then the second system processes everything it’s interested in, etc.

So, in essence, the first method seems simpler and more efficient, while the latter method seems more “correct”, pure, verbose, debuggable, and extendable. Which one should I pick?

c# – Unity Physics collision metrix doesn’t work on ParticleCollisions

I have this Physics collision metrix(1).
I have Player layer on the ship and PlayerShells on Particles whitch’s my shooting.

The problem:
When I shoot, OnParticleCollision on my shells collides with player, but as you can see on the picture it shouldn’t happen.

Proofing my theory, I testet it: (2) and (3) screenshoots;

My “collision” code:

private void OnParticleCollision(GameObject other)
        {
            SetDamage(other.GetComponent<ISetDamage>());
            
            //Creating hit effect
            _mainParticles.GetCollisionEvents(other, _collEvent);
            Vector3 pos = _collEvent(0).intersection;   //hit posotion
            Quaternion newRot =
               Quaternion.Euler(transform.rotation.x, -transform.rotation.y, transform.rotation.z);
               //Tryed to rotate effect like opposite from bullet, but it doesn't work for now

            switch (other.GetComponent<Stats>().GetMatter)
            {
                case Matter.Steel:
                    Instantiate(_hitSteel, pos, newRot);
                    break;
                case Matter.Wood:
                    Instantiate(_hitWood, pos, newRot);
                    break;
                case Matter.Flesh:
                    Instantiate(_hitFlesh, pos, newRot);
                    break;
                case Matter.Dirt:
                    Instantiate(_hitDirt, pos, newRot);
                    break;
                case Matter.Stone:
                    Instantiate(_hitStone, pos, newRot);
                    break;
            }
        }

Physics collision metrix
enter image description here
enter image description here
enter image description here

What am I doing wrong?? 🙁

c# – Unity- Collision Checker Debugger Error

Im fairly new to coding and unity and I stumbled upon a problem that I could not fix.

In visual studio 2019 for Mac, when I use the code Debug.log(collisionInfo.collider.name); I get the error message. What should happen is in unity, when my obstacle is hit it should display the name of the obstacle hit in the console. It ends up giving me a error message.

Heres a picture of my script!
enter image description here

Please help!
Thanks!

java – Swept AABB: finding collision normal in 3D?

I was following this tutorial which explains how to detect and resolve a 2d swept aabb collisions. I got the detection part working on 3d, but know I need a way to properly make a response, like sliding on the face because right now my player just get stuck on the wall. To do that, I need the surface normal, but I couldn’t correctly translate the normal calculation in the tutorial from 2d to 3d. Here is the code, written in Java, but you can always check the tutorial:

private float sweptAABB(Vector3f velocity, float x, float y, float z, float minTime){
    // find the distance between the objects on the near and far sides for both x, y and z
    // and find time of collision and time of leaving for each axis
    if (velocity.x > 0.0f) {
        invEntry.x = x - maxI.x;
        entry.x = invEntry.x / velocity.x;
        invExit.x = x + 1 - minI.x;
        exit.x = invExit.x / velocity.x;
    } else if (velocity.x < 0.0f){
        invEntry.x = x + 1 - minI.x;
        entry.x = invEntry.x / velocity.x;
        invExit.x = x - maxI.x;
        exit.x = invExit.x / velocity.x;
    } else {
        invEntry.x = x + 1 - minI.x;
        invExit.x = x - maxI.x;
        entry.x = -Float.MAX_VALUE;
        exit.x = Float.MAX_VALUE;
    }

    if (velocity.y > 0.0f) {
        invEntry.y = y - maxI.y;
        entry.y = invEntry.y / velocity.y;
        invExit.y = y + 1 - minI.y;
        exit.y = invExit.y / velocity.y;
    } else if (velocity.y < 0.0f){
        invEntry.y = y + 1 - minI.y;
        entry.y = invEntry.y / velocity.y;
        invExit.y = y - maxI.y;
        exit.y = invExit.y / velocity.y;
    } else {
        invEntry.y = y + 1 - minI.y;
        invExit.y = y - maxI.y;
        entry.y = -Float.MAX_VALUE;
        exit.y = Float.MAX_VALUE;
    }

    if (velocity.z > 0.0f) {
        invEntry.z = z - maxI.z;
        entry.z = invEntry.z / velocity.z;
        invExit.z = z + 1 - minI.z;
        exit.z = invExit.z / velocity.z;
    } else if (velocity.z < 0.0f){
        invEntry.z = z + 1 - minI.z;
        entry.z = invEntry.z / velocity.z;
        invExit.z = z - maxI.z;
        exit.z = invExit.z / velocity.z;
    } else {
        invEntry.z = z + 1 - minI.z;
        invExit.z = z - maxI.z;
        entry.z = -Float.MAX_VALUE;
        exit.z = Float.MAX_VALUE;
    }
    // find the earliest/latest times of collision
    if (entry.y > 1.0f) entry.y = -Float.MAX_VALUE;
    if (entry.x > 1.0f) entry.x = -Float.MAX_VALUE;
    if (entry.z > 1.0f) entry.z = -Float.MAX_VALUE;

    float entryTime = Math.max(Math.max(entry.x,entry.z),entry.y);

    if(entryTime >= minTime) return 1.0f;

    float exitTime = Math.min(Math.min(exit.x,exit.z),exit.y);

    if(entry.x < 0.0f && entry.y < 0.0f && entry.z < 0.0f) // equals to entryTime < 0.0f
        return 1.0f;

    if (entryTime > exitTime) return 1.0f;

    if(entry.x > 1.0f) {
        if(max.x < x || min.x > x + 1)
            return 1.0f;
    }

    if(entry.y > 1.0f){
        if(max.y < y || min.y > y + 1)
            return 1.0f;
    }

    if(entry.z > 1.0f){
        if(max.z < z || min.z > z + 1)
            return 1.0f;
    }
    return entryTime;

Basically, in the tutorial, to get normals, they do a test on the entry values, here is how I tried to translate this to 3d:

if (entry.x > entry.y) {
        if(entry.x > entry.z){
            if (invEntry.x < 0.0f)
                normal.x = 1.0f;
            else
                normal.x = -1.0f;

            normal.y = 0.0f;
            normal.z = 0.0f;
        }else{
            if (invEntry.z < 0.0f)
                normal.z = 1.0f;
            else
                normal.z = -1.0f;

            normal.x = 0.0f;
            normal.y = 0.0f;
        }
    } else {
        if (entry.y > entry.z) {
            if (invEntry.y < 0.0f)
                normal.y = 1.0f;
            else
                normal.y = -1.0f;

            normal.x = 0.0f;
            normal.z = 0.0f;

        } else {
            if (invEntry.z < 0.0f)
                normal.z = 1.0f;
            else
                normal.z = -1.0f;

            normal.x = 0.0f;
            normal.y = 0.0f;
        }
    }

I’m getting correct directions, but the values are always negative and I have trouble picturing the maths behind the normal testing.
My question is: how can I correctly calculate the normals based on the code from the tutorial?

Thanks!