New answers tagged

1

Edit-> Project Setting-> physics-> Default Contact Offset to 0.0001 made it for me


0

Thanks to what DMGregory pointed out, I was able to solve my issue. I had to use Physics.SyncTransforms (Unity Docs) before the first time I called OverlapBox(). It turns out that the OverlapBox wasn't incredibly large, but that the transforms needed to be updated manually since everything was happening in one frame. As a result, the OverlapBox was the ...


1

The two options are: 1.) NPCs run away from the player. With this one you just need to take the vector going from the player to the NPC, normalize it and set the NPCs velocity to this vector 2.) NPCs run perpendicular to the player's direction. To achieve this, you need to take the direction of the player and rotate it 90 degrees. Since there are two ...


2

There's actually a third option: storing AABBs as mins and maxs. That is, a Vector2 as the minimum x and minimum y, and another as the maximum x and maximum y values that the AABB occupies. This allows for the representation of the AABB as a pure math concept and to not be dependent on how the screen or world space is set up. It's more flexible but can ...


1

Efficiency of both depends on how do you use AABBs. Center/half-size pros: Easy and fast retrieval of AABB's position Collision detection may be easier to understand Easier to understand calculation of AABB's border position Center/half-size cons: Each collision detection will have more operations (subtraction/addition) Multiplication when retrieving AABB'...


2

After calculating the rope, save the points it bends at relative to the objects, that cause that bend and the rotational direction (whether the rope bent in the right or the left direction). You can use these relative positions to reposition the rope during gameplay, but there will be 3 different interactions you need to pay attention to: 1.) An object hit ...


0

After much trial and error, I've found a solution that works. Rather than having a central function that loops through the groups to find collisions, I split it out so each object checks for and detects it's own collisions. It then calls the explosion animation function before deleting itself. The extra scoreboard updates have remained behind and are updated ...


-1

You have at least 3 basic options. 1) Overlap check (suffers from tunneling) 2) Sweep test (needs collision extraction) 3) Intercept test (finds exact intercept time) Which one is right for you depends on a few things. One is how often you want to update your collision detection. Using 1) with high logic rates or low velocities is often acceptable. 2) ...


0

Advice I give to Unity developers is please never look up or compare GameObjects by name. It's a very brittle way to work and we have better options available to us. In this case, your cube objects are not named "cube" or "Cube". They're named "Cube(Clone)" as we can see in your screenshot, so comparing the name to "cube" returns false and you always skip ...


0

When you instantiate an object then the name of the object will be "Object Name+(Clone)" for example in your case the object name you want to instantiate is "cube" but after the instantiation the name will be "cube(Clone)" so you have to compare with "cube(Clone)" instead of "cube". void OnTriggerEnter(Collider other) { if (other.gameObject.name == "...


1

I assume you’re handling either OnTriggerEnter or OnCollisionEnter. Try capturing RigidBody.velocity in there, then set a flag to set the RigidBody.velocity to the captured Vector3 in the next FixedUpdate.


1

In physics engines, "kinematic" means "I'll handle steering this object around collisions myself — so engine, don't do any collision resolution on my behalf" It's often useful for things like moving platforms, which should absolutely never stray from their assigned path — even if it goes through a solid floor — or get jostled when something lands on them. ...


Top 50 recent answers are included