collision detection – if touching line renderer (do something)

LineRenderer is not your friend here. While you can somehow make it work (you would need to dynamically create and update the colliders by code), that is not something you want to do. (As reference https://answers.unity.com/questions/470943/collider-for-line-renderer.html)

If you want to use your laser to kill something, it is just a bunch of stretched shiny bullet packed together. All you need to do is create a small laser prefab with an image of your laser and you spawn them in quick succession. Each of those laser bullets can have their own collider and therefore your collision/ die/ kill etc call.

With a bullet prefab, you can for example easily move your ship, continue shooting and you don’t care about already shot bullets. The line renderer would just stay where it is. You will have a really hard time to update it to match your movement pattern of the ship.

  1. instantiate a prefab should have no influence on your ships movement, if it does, you do it wrong. That would be a different problem and can only be helped if you post your implementation of it.
  2. You don’t enable/ disable bullet prefabs. You instantiate them and usually have an offscreen collider that destroys them. Upgraded version is a pool manager for them but for starters offscreen destroyer will do.
  3. If you really want to use a linerenderer, you could take a look at raycasting and if that is an option for you. If the raycast hits, so should your laser if you use the same direction of it.

What will happen when a collision in SHA256 be found?

Would the protocol migrate to another Hash Algorithm inmediatly?
What would be the next? SHA3 or BLAKE 2?

Reading collision force between two bodies in a 3D physics simulation engine (ODE?)

I want to detect collision and read the collision force vector between two bodies in a 3D physics engine like ODE. Could someone please tell me how to achieve this?

#include "ode/ode.h"     
#include "drawstuff/drawstuff.h"  
#define NUM 4         

dWorldID    world;       
dBodyID     link(NUM);    
dJointID      joint(NUM);  
static double THETA(NUM) = { 0.0, 0.0, 0.0, 0.0 }; 
static double l(NUM) = { 0.10, 0.90, 1.00, 1.00 };  
static double r(NUM) = { 0.20, 0.04, 0.04, 0.04 };  
//static dWorldID world;
static dSpaceID space;
static dGeomID  ground;
static dJointGroupID contactgroup;
//dsFunctions fn;
static void nearCallback(void* data, dGeomID o1, dGeomID o2)
{
const int N = 10;
dContact contact(N);

int isGround = ((ground == o1) || (ground == o2));

int n = dCollide(o1, o2, N, &contact(0).geom, sizeof(dContact));
if (isGround) {
    for (int i = 0; i < n; i++) {
        contact(i).surface.mode = dContactBounce;
        contact(i).surface.bounce = 0.1; // (0.0~1.0) restitution parameter
        contact(i).surface.bounce_vel = 0.1; // minimum incoming velocity for bounce 
        dJointID c = dJointCreateContact(world, contactgroup, &contact(i));
        dJointAttach(c, dGeomGetBody(contact(i).geom.g1),
            dGeomGetBody(contact(i).geom.g2));
        //if (contact(i).geom.depth > 0.000001)
        {
            printf("Collision points %d , force %fn", n, contact(i).geom.depth);
        }
    }
}
}

void control() {  
static int step = 0;     
double k1 = 10.0, fMax = 100.0; 
printf("r%6d:", step++);
for (int j = 1; j < NUM; j++) {
    double tmpAngle = dJointGetHingeAngle(joint(j));  
    double z = THETA(j) - tmpAngle;  
    dJointSetHingeParam(joint(j), dParamVel, k1 * z); 
    dJointSetHingeParam(joint(j), dParamFMax, fMax); 
}

}

void start() {
float xyz(3) = { 3.04, 1.28, 0.76 };
float hpr(3) = { -160.0, 4.50, 0.00 };
dsSetViewpoint(xyz, hpr);
}

void command(int cmd) {
switch (cmd) {
case ‘j’: THETA(1) += 0.05; break;
case ‘f’: THETA(1) -= 0.05; break;
case ‘k’: THETA(2) += 0.05; break;
case ‘d’: THETA(2) -= 0.05; break;
case ‘l’: THETA(3) += 0.05; break;
case ‘s’: THETA(3) -= 0.05; break;
}

if (THETA(1) < -M_PI)   THETA(1) = -M_PI; 
if (THETA(1) > M_PI)    THETA(1) = M_PI;
if (THETA(2) < -2 * M_PI / 3)  THETA(2) = -2 * M_PI / 3;
if (THETA(2) > 2 * M_PI / 3)  THETA(2) = 2 * M_PI / 3;
if (THETA(3) < -2 * M_PI / 3)  THETA(3) = -2 * M_PI / 3;
if (THETA(3) > 2 * M_PI / 3)  THETA(3) = 2 * M_PI / 3;

}

void simLoop(int pause) {
control();
dWorldStep(world, 0.02);
dSpaceCollide(space, 0, &nearCallback);
dsSetColor(1.0, 1.0, 1.0);
for (int i = 0; i < NUM; i++)
dsDrawCapsuleD(dBodyGetPosition(link(i)), dBodyGetRotation(link(i)), l(i), r(i));
}

int main(int argc, char* argv()) {
dsFunctions fn;
dMass mass;
double x(NUM) = { 0.00 }, y(NUM) = { 0.00 };
double z(NUM) = { 0.05, 0.50, 1.50, 2.55 };
double m(NUM) = { 10.00, 2.00, 2.00, 2.00 };
double anchor_x(NUM) = { 0.00 }, anchor_y(NUM) = { 0.00 };
double anchor_z(NUM) = { 0.00, 0.10, 1.00, 2.00 };
double axis_x(NUM) = { 0.00, 0.00, 0.00, 0.00 };
double axis_y(NUM) = { 0.00, 0.00, 1.00, 1.00 };
double axis_z(NUM) = { 1.00, 1.00, 0.00, 0.00 };
dInitODE2(0);
fn.version = DS_VERSION; fn.start = &start;
fn.step = &simLoop; fn.command = &command;
fn.path_to_textures = “../../drawstuff/textures”;

dInitODE();  
world = dWorldCreate();  
dWorldSetGravity(world, 0, 0, -9.8);     

//world = dWorldCreate();
space = dHashSpaceCreate(0);
contactgroup = dJointGroupCreate(0);
dJointGroupEmpty(contactgroup);
//dWorldSetGravity(world, 0, 0, -0.5);

// Create a ground
ground = dCreatePlane(space, 0, 0, 1, 0);
for (int i = 0; i < NUM; i++) {       
    link(i) = dBodyCreate(world);     
    dBodySetPosition(link(i), x(i), y(i), z(i)); 
    dMassSetZero(&mass);      
    dMassSetCappedCylinderTotal(&mass, m(i), 3, r(i), l(i));  
    dBodySetMass(link(i), &mass);  
}

joint(0) = dJointCreateFixed(world, 0); 
dJointAttach(joint(0), link(0), 0);    
dJointSetFixed(joint(0));               
for (int j = 1; j < NUM; j++) {
    joint(j) = dJointCreateHinge(world, 0); 
    dJointAttach(joint(j), link(j - 1), link(j)); 
    dJointSetHingeAnchor(joint(j), anchor_x(j), anchor_y(j), anchor_z(j)); 
    dJointSetHingeAxis(joint(j), axis_x(j), axis_y(j), axis_z(j)); 
}
dsSimulationLoop(argc, argv, 640, 570, &fn);
dCloseODE();
return 0;

}

design patterns – Preventing name collision between user-defined modules within a framework

I’m a contributor to a framework that’s designed for producing synthetic data. The system allows the end-user to create custom data generators and load them into the framework. Currently we store the available generators in a dictionary. We then look-up the generator by name, and return the value generated by that to the user.

There are also a few generators that come ‘out-of-the-box’ with the framework. I’ve run into a problem, however: how can I prevent the end-user from overloading a method in the framework? Given that we are using a dictionary, overloading would be done simply by calling the generator the same thing. What are some options that I could explore here to prevent this name collision?

How to do collision detection in Unity between Character Controller, Rigidbody Collider and a NavmeshAgent?

I would like to know more about how collision detection works in Unity especially when character controllers and NavmeshAgents get involved.

For example, how can I detect collision between NavmeshAgent and a CharacterController?
I have added a sphere collider to my NavmeshAgent, but it doesn’t seem to detect a collision unless I set it to “IsTrigger”.
I have tried OnCollisionEnter(), OnControllerColliderHit() and OnTriggerEnter().
OnTriggerEnter() seems to be the only one that works and only when I enable “IsTrigger”.

How come the other two don’t work? Shouldn’t they? What if I didn’t want to make the collider a trigger?

collision detection – How can I position a large amount of boxes to prevent overlap efficiently

I’ve been working on a asset to position labels like they do in diablo or PoE but I’m having trouble finding an alghoritm to position the labels efficiently.

Currently I just boxcast in each of the 4 directions untill there is no overlap, compare their distances and take the smallest value to place it but this just seems too much hassle and too slow with a big number of labels.

Especially when you look at this video clip from Path of Exile without loot filter.
There’s just no way they can iterate over that amount of labels and place it instantly.

So I’m thinking they keep some kind of array that sais “There are X open spots for this label group currently, select the nearest one or any” and update it when a label gets placed.

I know this question has been asked and I know about automatic label placement etc but I don’t think it really applies in this case. At a certain point it doesn’t really matter where the labels get positioned, they just need to be positioned as fast as possible without overlap.

So basically I’m looking for a way to save occupied/unoccupied space and retrieve that value somehow.

collision detection and normals from rigidbody

Until now I’ve been developing my player character using a Character Controller, but have since decided to switch to rigidbody due to the controller’s limitations. In order for my movement code to run as expected I need to know when the player is colliding with anything, and the normal of the surface it’s colliding with. This is easy with a Character Controller, but is there a simple way to do it with a rigidbody?

Here is a stripped down version of the script I’m using for collisions.

 // Used in other scripts (Necessary)
    public GameObject ground = null;
    public Vector3 groundNormal;
    public bool onGround;

    // Used internally
    public bool isColliding;
    public float slopeLimit;

    // Character Controller
    public CharacterController controller;

    void Start()
    {
        controller = GetComponent<CharacterController>();
    }

    void Update()
    {
        // Check if the player is colliding with anything (Character Controller)
        if (controller.collisionFlags == CollisionFlags.None)
        {
            isColliding = false;
        }
        else
        {
            isColliding = true;
        }

        // Check if the player is standing on the ground
        if (isColliding && groundNormal != Vector3.zero)
        {
            onGround = true;
        }
        else
        {
            onGround = false;
        }
    }

    void OnControllerColliderHit(ControllerColliderHit hit)
    {
        // Check for floor
        if (Vector3.Angle(transform.up, hit.normal) <= slopeLimit)
        {
            // Store floor object data
            ground = hit.gameObject;
            // Store ground surface normal
            groundNormal = Vector3.Normalize(hit.normal);
        }
        else
        {
            // reset variables
            ground = null;
            groundNormal = Vector3.zero;
        }
    }

slopeLimit is a static value. Additionally, getting the ground object isn’t actually necessary atm, but I plan on using it later.

Edit:
Currently I’m using controller.collisionFlags to detect when the player is colliding with something and haven’t been able to find a similar alternative. Setting the isColliding bool to true using Rigidbody.OnCollisionStay would be simple, but setting it to false without use of another void function seems difficult. is that possible at all?

collision detection – A problem regarding 2D ray casting

I wanted to post this on stack overflow, but I feel that this SE is more appropriate.

I am extremely naive in the world of ray casting technology so I’m trying to create one out of my own knowledge about how it works. Currently, I have a 2D raycaster that solves a bunch of linear equations to look for collisions of rays and shapes; my shapes are defined by a set of linear equations.

However, the lines that make up a shape are independent of one another and therefore the ray casts “through” the object and detects a collision on its far interior side. I want my program to remove these sorts of detections somehow. Any suggestions?

Again, I’m new raycasting and programming in general, so any level of help is much appreciated!

collision detection – Best option to narrow a known set of triangles?

I am building collision detection and response in a custom engine. This routine happens between the moving player, and static entities on the map.

In the first phase, the broad phase I am moving the player and looking for any new AABB to AABB collisions between the player and static entities.

In the second phase, the narrow phase. I then do a swept-spehere to triangle detection. I move the players collision sphere through the triangles in the colliding AABB.This phase can be expensive because the colliding AABB may have complicated geometry with many triangles.

I ways to narrow down the set of triangles being detected. Some solutions I have in mind are:

  • Get the “overlap box” the space where both AABB’s overlap in the broad phase.

    Then do a pass on all the triangles in the colliding AABB and return just the ones in the overlap box.
    My understanding here is I’ll have to use a SAT algorithm to detect if the AABB and triangles collide or not and I’ll still have to iterate over all the triangles in the colliding AABB. I’m not sure if this is any more performant.

  • Sort the triangles by distance to the AABB collision

    If I sort the triangles by their distance to the AABB collision I will be able to exit from the narrow phase before the entire set of triangles has been processed.
    I’m not sure what the performance implications of resorting the triangles each frame would be. I’m thinking not great…

  • Use a spatial partitioning data structure OctTree or quadTree to narrow down the triangles.

    It may be extensive work to build one of these structures together for my engine and populate it with all the entities triangles. I’m not sure if they will give me any improved granularity. Will they be more precise than the AABB overlap?

I wanted to ask for help first before I start building one these solutions and reviewing the performance. Any other ideas are greatly appreciated.

tilemap – Collision quadrant in godot appears

I am learning to use godot following this video:
Collisions with Autotiles

The problem is that when I create the collision for the cliffs using tilemap, it appears me a blue quadrant indicating the collision. What should I do for what these “quadrants” do not appear?

Game image

As you can see, all the cliffs are blue for indicate me the collision, but I have no idea about what to do for hide them.