playMaker

Author Topic: Clamp the Y axis on a RigidBody object?  (Read 1252 times)

curb47

  • Sr. Member
  • ****
  • Posts: 256
Clamp the Y axis on a RigidBody object?
« on: August 28, 2020, 10:59:52 AM »
This is more of a general Unity question, I think...

Can I clamp my rigid body object so that it never goes below 0 (or any defined float) on the Y axis?

It would save me a lot of hassle. I don't want to add transform/physics clashes as this seems to mess with updates/fixed updates etc. I'd like a pure physics based solution, even with a bounce back or something.

Possible?

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Clamp the Y axis on a RigidBody object?
« Reply #1 on: August 28, 2020, 12:33:54 PM »
Yes, the code version is called vector clamp magnitude. Maybe there is an action for this here or on the ecosystem.

If you want to freeze it on the Y (or any) axis, it’s probably better to use the constraints on the rigidbody component (this can be set by code, too).
« Last Edit: August 28, 2020, 12:35:26 PM by Thore »

curb47

  • Sr. Member
  • ****
  • Posts: 256
Re: Clamp the Y axis on a RigidBody object?
« Reply #2 on: August 28, 2020, 01:11:13 PM »
Thanks Thore,

I'll check that out and see if I can bodge together a C# script.

Cheers.