Tag Info

Hot answers tagged

2

Refer the below site for some guidance: http://www.kilobolt.com/day-4-collision-detection-part-1.html It explains bounding shapes that will be used to check for collision. In the case of our robot, we will be using four bounding rectangles. I will suggest to give more specific requirement so that I can update my answer more helpfully.


2

Get information (dimensions, coordinates) of two imageviews, then use rectangle intersection condition. Assume that two rectangles A, B with coordinate of top-left and buttom-right as follow: Rectangle A: (Xa1, Ya1) ; (Xa2, Ya2) Rectangle B: (Xb1, Yb1) ; (Xb2, Yb2) Overlap condition: ((Xb1 - Xa2)(Xb2 - Xa1) <= 0) && ((Yb1 - Ya2)(Yb2 - Ya2) ...


2

The easiest way I found to do this was as follows: Make sure to configure your canvas to use screen space based on the camera. Drag and drop your camera into the render camera property Detect if the rectangle contains the mouse coordinates using RectTransformUtility.RectangleContainsScreenPoint() method. Pass in your rectTransform object, the current ...


2

No, but it will just be bad manners to write the same thing in every scripts and it can be a pain to debug if you have lots of function of collision detection in a lot of other scripts. You can use the method SendMessage() to communicate between scripts (or inside a script). You can read its documentation here e.g if(player.health == 0){ ...


2

Just rotate the point at an angle of -θ around the center of the rectangle. relx = x-cx rely = y-cy rotx = relx*cos(-theta) - rely*sin(-theta) roty = relx*sin(-theta) + rely*cos(-theta) dx = max(abs(rotx) - width / 2, 0); dy = max(abs(roty) - height / 2, 0); return dx * dx + dy * dy; Also, remember this is still the distance squared, so you need to take ...


2

This is an interesting problem. I can think of two mechanical (brute-force-ish) approximate approaches. My math-fu is not strong enough to opine if an analytic solution is practical here. I hope there is such an approach! But here’s my “just get it done” suggestions. By Gridded Area, approximate We only care about the blue area. Represent that to the ...


1

You have your thisMin and thisMax declarations reversed. Vector3f thisMin = new Vector3f(this.pos.x + this.w, this.pos.y + this.h, this.pos.z + this.d); Vector3f thisMax = new Vector3f(this.pos.x, this.pos.y, this.pos.z); should be: Vector3f thisMin = new Vector3f(this.pos.x, this.pos.y, this.pos.z); Vector3f thisMax = new Vector3f(this.pos.x + this.w, ...


1

In general you can check if any Intersection exist between your two polygon (even non-convex) as below. Problem: Given n line segments; Report all(as k in algorithms) Intersections. You can implement any of these two algorithm in your desire language and use them. they take your line segments as input and return if any intersection ( Collision in your ...


1

If in general clicking the unit has no other use than selecting the tile, you could simply put the units on the Ignore Raycast layer so you can select directly the tile, in this case you can also attach a script on the tiles with the OnMouseDown function. If you want to access, in that way, the unit, you could maintaing of structure describing the tiles (so ...


1

I updated the JSFiddle sample with the solution: Here's the updated version. It was just two lines of code: var sign = shapeA.id - shapeB.id > 0 ? 1 : -1; n.multScalar(sign);


1

Regarding your gravitation/acceleration physics, here's your code again with a bit of reformatting: function world.update(t) for k, v in pairs(world.objects) do if v.Static ~= true then v.Position.X = v.Position.X + v.Velocity.X if v.onGround == false then if v.Velocity.Y < world.Gravity then ...


1

To get the distance and the separation/collision normal you reduce the "circle to aabb" to a "point to plane" problem which can be easily solved. In detail: Get closest point from circle center to aabb Get distance from closest point to circle center Create a normalized version of this distance vector (Separation normal) Project the distance onto the ...



Only top voted, non community-wiki answers of a minimum length are eligible