Facepunch / sbox-issues

176 stars 12 forks source link

Add the ability to re-define physics shapes after they've been created #2215

Closed ShadowBrian closed 9 months ago

ShadowBrian commented 2 years ago

For?

S&Box

What can't you do?

Currently I'm unable to change a physics body's physics shapes after they've been created, this seems like a bit of an arbitrary limitation since you can update a physics body's physics shape if it's a mesh one.

How would you like it to work?

I'd want some way to get and alter a physics body's physics shape, either by getting its reference from inside the list of shapes or by some other function directly on the physicsbody, say, PhysicsBody.RedefineShape or something? This'd allow for the player's physics bounds to change while they're crouched, which applies to every gamemode really, including my VR one which kind of requires arbitrary sized capsule shapes for collision checks from bullets coming in.

What have you tried?

I've tried getting PhysicsBody.Shapes references but the API has no way to update those other than re-defining mesh shapes, it seems like it should be able to redefine boxes, capsules and spheres just fine too. Feels like a gap in the API.

Additional context

No response

yuberee commented 2 years ago

Our current solution is destroying the old physics body and creating a new one, so yea, less than ideal.

aylaylay commented 2 years ago

I will see if I can do this in a way that makes sense but recreating the physics body isn't as bad as you think

ShadowBrian commented 2 years ago

I feel like recreating the physics body over and over is bad practice though... Also seems like it should be possible to adjust parameters of a shape (or shape replacements) if you can do full mesh replacements with mesh physics shapes. Thanks for giving it a look regardless though!

PolSpock commented 1 year ago

Hello i found a case that recreating Physics Hull wheras update it can be anonying : For example then my player crouching, i have to recreate his Physics Hull for giving the possibility to jump on another player.

(So basically call SetupPhysicsFromAABB( PhysicsMotionType.Keyframed, new Vector3( x, y, z ), new Vector3( x, y, z) ); for each situation)

However by doing that, it's gonna recall my Player.StartTouch() and also my BaseTrigger.StartTouch() who already trigger something I think it could be cool to prevent that situation by updating the PhysicsShapes

https://user-images.githubusercontent.com/5229571/219653696-77ac79d9-1d04-445a-a581-c35456eecb86.mp4