c# – Collision between two Images

I’m making a game. There is a turtle and lots of platforms it can walk on. It walks on its own and you can change the direction it is walking. However, some problems are occuring with the logic I implemented.

I had to make 2 classes (one for the turtle and one for the platforms).

class Turtle
{
    public Rect HitBox;
    public bool IsMoving;
    public bool IsDirectionForward;
    public double DistanceWalked;
    public double MetersFalled;
}

class Ground
{
    public Rect HitBox;
}

Then I created a virtual Rect that would simulate the right width and height of the ground and the turtle after using Inflate function, because as far I know the Image height and width can’t never be the same as turtle’s or ground’s –> Image is in fact a rectangle with a source in it, aren’t I right?

public MainWindow()
{
    InitializeComponent();

    ground1 = new Ground();
    ground1.HitBox = new Rect(groundImg1.Margin.Left, groundImg1.Margin.Top, groundImg1.Width, groundImg1.Height);
    ground1.HitBox.Inflate(0, -35);

    zelvicka = new Turtle();
    zelvicka.IsMoving = true;
    zelvicka.IsDirectionForward = true;

    timer = new DispatcherTimer();
    timer.Interval = TimeSpan.FromMilliseconds(20);
    timer.Tick += Update;
    timer.Start();
}

I must’ve done the same with the turtle, whose virtual Rect is updating every time it moves in Update function generated by DispatcherTimer so the virtual Rect is always up to date.

    private void Update(object sender, EventArgs e)
    {
        zelvicka.HitBox = new Rect(turtleImg.Margin.Left, turtleImg.Margin.Top, turtleImg.Width, turtleImg.Height);
        zelvicka.HitBox.Inflate(-110, -30);

        // ZELVICKA IS GOING FORWARD AND IS TOUCHING THE GROUND
        // ZELVICKA IS GOING BACKWARDS AND IS TOUCHING THE GROUND
        if (zelvicka.IsMoving && zelvicka.IsDirectionForward && zelvicka.HitBox.IntersectsWith(ground1.HitBox))
        {
            turtleImg.Margin = new Thickness(zelvicka.DistanceWalked += 3, zelvicka.MetersFalled, 0, 0);
        }
        else if (zelvicka.IsMoving && !zelvicka.IsDirectionForward && zelvicka.HitBox.IntersectsWith(ground1.HitBox))
        {
            turtleImg.Margin = new Thickness(zelvicka.DistanceWalked -= 3, zelvicka.MetersFalled, 0, 0);
        }
    }

Is this a good way of detecting collision? How do I improve it? If not, is there any way to detect only let’s say graphically filled area within the picture? Something that would ignore the transparent part of the Image area.

physics – OBB vs rectangle/quad/plane with bounds collision detection/response

I am able to resolve collision between an OBB and a plane but can’t get it to work when I introduce some bounds on the plane size. I want to have the plane of width and height dimensions defined by a normal and a position.

The code for detecting/resolving is fairly simple if the plane doesn’t have any bounds:

function obbIntersectsPlane( obb, plane ) {
  let r = obb.size.x / 2 * Math.abs( dot( obb.right, plane.normal ) ) + 
          obb.size.y / 2 * Math.abs( dot( obb.up, plane.normal ) ) +
          obb.size.z / 2 * Math.abs( dot( obb.forward, plane.normal ) );
  
  let s = dot( plane.normal, obb.position ) - dot( plane.normal, plane.position );

  if ( Math.abs( s ) < r ) {
    return {
      overlap: r - s,
      vector: plane.normal
    };
  }

  return false;
}

collision detection – Intersection of thick line with a grid

There is a popular paper, and numerous examples, on how to efficiently perform collision detection for a line with a grid. However, I’m drawing up blanks on how to do the same thing but with a line that has thickness.

In my game, I’m considering adding projectiles that are not infinitly thin (for example, a giant slow-moving plasma ball), and I need to figure out which cells along a grid that it collides with. Initially I thought it’d be as simple as just using the Minkowski Sum method of adding the width/height of the projectile to each cell of the grid, and then treating the projectile as infinity thin line along a bloated-overlapping-grid, but that doesn’t look like it’s going to work with the existing algorithm.

Are there any other papers/algorithms that describe how to accomplish this? Or is there a way to modify the existing algorithm to accomplish this? Or are there any tricks to implementing this indirectly?

Will the Bitcoin network discredit a transaction if you do a simple transfer on a multi-sig after you found the collision on that address?

Stack Exchange Network


Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

unity – Collision between player and ennemy units (2D-RTS)?

I am using a Rigidbody2D to handle collision between differents units. When the player’s units encounter one anothers they push each others because of the rigidbody physics (and that’s good for me). But when the player unit encounter an ennemy units he push it in the same way.

What are the solutions to make ennemy’s units unmovable by my units? (And my units unmovable for the ennemy?)

(I know I could use isKinematic but I want the player’s units to keep interacting with each others.)

security – What would happen if SHA256’s pre-image or collision resistance would be broken?

Preimage resistance and collision resistance are not absolute, they are just matters of amount of computation that is necessary to solve certain problems. For example, for an ideal hash function with 256-bit output, an order of 2256 evaluations are needed to find a preimage, and an order of 2128 evaluations are needed to find a collision. Anything less is considered an attack.

For example, if you can find collisions with just 2124 evaluations (and not because you are lucky, but because you use some approach specific to the function), this is an attack, but it is not practical because 2124 is still immensely large.

Moreover, for Bitcoin mining, you need to find only partial preimages, not full preimages. For example, to find a value such that first 50 bits of its hash are zeros, you need 250 hash evaluations, assuming the hash is ideal. And there is a problem: if the hash is not preimage-resistant (so you need, for example, just 2240 evaluations to find a preimage, rather than 2256), this doesn’t tell anything about resistance to finding partial preimages (so the above problem may still take 250 evaluations, but may take only 234). And lack of collision resistance doesn’t tell anything at all about the difficulty of finding partial preimages. However, Bitcoin depends on collision resistance of SHA256 in other places, so it is still important.

How do you use custom collision on a skeletal mesh in UE4?

I have a vehicle rig that is a skeletal mesh that imports fine in to unreal but I was wondering how to use a mesh for collision on it. Normally you can just name the collision mesh with UCX_ in front of the name to do it but with skeletal meshes it makes you use a system called phat and I only see cubes/spheres/capsules for collision with that.

Godot – Collision for character teleportation

I’m currently working on a little game to discover Godot game engine.

It’s a Top-Down game and I want my character to be able to teleport through walls.

I thought to dupplicate my character’s collision box and to set its position to the teleportation’s position but I didn’t find a way to check if there is a collision to this new position.

Any advise?

collision detection – Unity OnCollision() not working

Seem to have exhausted google looking for an answer to a VERY bullet simple code that should work.

void onCollisionEnter(Collision col) {
    print ("hit " + col.gameObject.name);
    Destroy (gameObject);
    }

Bullet object has the above script, SphereCollider (radius a lot bigger than object), RigidBody, not a trigger, not kinematic, is travelling slow. All checked during runtime.

When it hits a wall (Box collider), it just bounces off but no collisionEnter code is ran.

Debug console bubble is on.

physics engine – Collision response using the Minimum Translation Vector

I am trying to use the Minimum Translation Vector (MTV) returned from the SAT algorithm for simple collision response. Please see the example below.

enter image description here

By separating the colliding boxes by moving the black box along the MTV, the box is now colliding with the other green box below. Moving the black box along the MTV for the collision with this new box then brings the box back to colliding with the first box, and an infinite cycle of trying to separate the boxes begins.

Am I missing something, or is collision response not possible using the MTV?