In my project, I have cubes that a player can grab using a physics handle. My requirement is that I want the grabbed object to not affect other physics objects or other cubes (objects with simulate physics enabled). I want this because, let’s say the player has stacked 2 cubes and now he has grabbed another one, I don’t want the grabbed cube to affect the already stacked cubes so that player can stack the 3rd one as well without disturbing others.
I will now describe what all I have already tried.
Approach 1
Adjust mass of the grabbed object so that it does not affect others. This does not work. Looks like physics handle ignores the mass of the held object. Check out this video by someone else facing the same issue.
Approach 2
Play around with simulate physics settings for objects based on whether they are grabbed or not grabbed.
Disable physics for the grabbed object: Physics handle isn’t able to move the grabbed object.
Disable physics for non grabbed objects: If I try to disable physics simulation for all cubes by default and enable it only for the grabbed one, then as soon as I let go of it, I disable physics simulation and it gets stuck in the air.
Same as 2. but also add checks for velocity and ground before disabling physics for grabbed object: This works fine in isolation, but if I grab another object before the old grabbed object has settled down, I can still yeet the older grabbed object by pushing it with the new grabbed object.
Disable physics only for the non grabbed objects that are in contact with the grabbed object: Again, works in isolation but this makes it possible to just hit a falling object in mid air and disable its physics, essentially holding it in-air.
Approach 3
Use physics constraint instead of physics handle. This causes a lot of erratic physics behaviour for me. If I hold a cube and go near another cube, they start doing some going in circles around each other like som planets of equal mass. The grabbed object sometimes vibrates in air even when it is not around any other physics object.
Not sure what I can do to fix this issue. I found a similar question on forum but no solution there. Please suggest how I can tweak the physics handle itself to achieve the result I want, I would prefer using that because I already have it in a stable state.
Change the grabbed object’s collision type to the one the other physically simulating objects ignore - for as long as it’s being held. Essentially, rather than manipulating how the held object interacts with the environment, alter what it can interact with.
@Everynone, in that case my grabbed object will go through the other non-grabbed objects, right? I did try something like that, setting some collision setting to ignore but then the grabbed object was going through (overlapping) others. I want it to behave with other cubes like how it behaves with walls in the environment (the deault level with get with First Person template), i.e. get blocked.
I want the grabbed object to not affect other physics objects or other cubes (objects with simulate physics enabled)
both cubes have the same settings - they ignore this new object channel. But since their Object Type is currently set to Physics Body, they can interact with one another and everything else in the world:
I do not want them to overlap, I just want the grabbed object to not exert any force or affect other objects in any way.
For example, see this video. I want the grabbed cube to behave with other cubes like it does with the environment. The other objects should simulate physics, but not receive force from grabbed object. Like when I grabbed the bottom one from the 2 stacked cubes, the top one should fall down as usual because it is simulating physics, I just don’t want it to react to being hit by the grabbed one.
@Everynone, the problem with that approach is that when 2 cubes are stacked vertically and I grab the bottom one, the top one will not fall down.
That’s why I was hoping if there was a way to stop exerting force by grabbed object. The mass is not doing anything for objects grabbed by physics handle.
@Everynone, I already had it disabled because I did not want my character to affect those cubes as well. Sadly, this setting is part of the character movement, so it only affects the player character, not what it is holding with physics handle.
I also tried tweaking the interpolation speed of the handle, but it only slows down the interpolation of the grabbed object, which reduces the force but doesn’t remove it.
Not sure if there’s a native way of handling this. The only thing that comes to mind at this point is to sweep a collider that is slightly larger than the held item and stop updating control rotation as soon as the sweep hits another physically simulating object. Could work but seems janky at best:
I have solved the issue by adding an extra cube, two collision channels and playing around with collision, simulate physics and collision channel settings.
Collision Channels
I added 2 new collision layers: InvisibleCollider, GrabbedObject
Grabbable Cube BP:
1. ParentCollider
This is the main parent of the BP. It is a box collider with collision object type as InvisibleCollider and it is set to “Ignore” any InvisibleCollider.
This has simulate physics enabled.
2. VisualCube
This is a cube that is child of the ParentCollider component.
This is the cube that is visible by default for all grabbable cubes.
This one has simulate physics off so that any grabbed object will not affect it.
Auto weld is disabled.
3. GrabCube
This is the cube that the character will use for grabbing.
Collision is set to false by default and visibility is off.
Collision object type is GrabbedObject
Auto weld is disabled.
Events
1. Grab object
Enable physics, visiblity an simulate physics for GrabCube
Disable collisions for the ParentCollider and VisualCube
Disable visibility of VisualCube
Disable simulate physics for ParentCollider
Grabbed object: Because of the settings above, the visual cube and its parent collider will not work now in the grabbed cube.
Other objects: Even though the ParentCollider has physics enabled, it also has ignore for grabbed object, so the grabbed cube will not affect it. The VisualCube on the other hand has simulate physics disabled, so that will also not be affected by the grabbed object. Setting auto weld to disabled makes sure that it does not start simulating along with its parent, the ParentCollider.
2. Drop object
Mostly just the opposite of grab object with one extra step - Copy the location and rotation from GrabCube and assign to VisualCube.