Best way to go about programming a physics wheelchair script?

Working on a project where the character is in a wheelchair, But I’m not quite sure what to do.

I have a simple system that the player can turn, accelerate and decelerate using a rigidbody.addforce, but while you are moving forwards, the wheelchair starts moving slightly to the left and right. Also I have to restrict rotation on the x axis, or else the thing flips over when you start moving. I need to keep this unchecked so that you can go up ramps etc.

How would I get this working with the proper physics?

I would think that this would be very simple to do, but I am new to programming physics stuff with unity.

Hah. Sounds like a prototype I worked on many years ago when mucking about with Havoc. The wheelchair eventually turned in to a unicycle because wheelchairs were not politically correct. :wink:

I recall for the unicycle I had to make it work like a motorcycle with a spring joint situated above the unicycle to keep it keep it upright. For the wheelchair I just treated the physics as a sphere rolling around without any lateral forces accumulating, and the visual representation was kept separate from the physical representation. You might also be able to get away with making your wheelchair a motorcycle given that motorcycle physics have come a long way in the past eight years.

turn down the angular drag so it doesnt flip over. you could try using a cube collider so the chair is always resting on the ground, but it might result in unstable behavior when you travel up ramps. i would personally use a capsule collider, and raycast the ground every frame to get the contact normal, and set the chairs transform.up to that normal

keep track of two velocities, one for each wheel. rotate the wheelchair if one wheel velocity is larger than the other. set the rigidbody velocity each frame to velocity1+velocity2.

Yep, that’s pretty much what my “sphere wheelchair” did. The sphere permitted bumping up kerbs and ramps without any problem. Capsule would work too, and would probably be better. Capsules in Havoc a decade ago were troublesome. :slight_smile:

Not sure the summing of the two velocities would work the way you think it would. What would be the purpose? You might be able to do the greater of the two velocities for forward velocity with the turn radius equal to the delta between the two velocities some hysteresis or a low pass filter would prevent the chair from zig zagging too much when moving forward if the two wheel velocities are just slightly off.

umm… English please? heheh.

I don’t quite understand. here is what i have gathered from the posts:

-Turn down angular drag
-get the normal, whatever that is, I am guessing the up facing position or something, and then make the wheelchairs rotation the same as the up normal so that it is facing up in its own local axis… I dont know i just confused myself
-use a capsule collider

I am a bit confused on normals, and I am a bit confused on the whole velocity on each wheel thing :L

sorry, i should have said ‘speed’ instead of velocity. a seperate speed modifier for each wheel, always applied to the wheelchair’s forward direction, which is rotated based on the difference between wheel speeds. i have implemented this and the behaviour could definitely fit a wheelchair.

the contact normal is just the direction perpendicular to the contact surface (i.e. the ground as a contact surface nas a normal pointing in the up direction)

a normal is just a unit vector with total magnitude 1. it is basically meant to represent direction.

Thanks, clears things up.

I will try and implement this and get back to you guys.

Okay, that makes sense now. :slight_smile:

use car wheel colliders. if both wheels move forwards it’ll go forwards. if one goes forwards at higher speed, it’ll turn. if they go opposite directions, it’ll turn on the spot.

I smashed my knee up a few times so i know how these things work lol

Sorry, I understand how to use the wheel colliders and such but once I have a wheel collider and a wheel, how do I get it to move?

Would I just use AddForce and it will automaticly make it rotate and move like a wheel?

bump

Rather than talking about your post and then bumping it when you don’t get a reply in 12 hours, why don’t you actually try doing some of the work yourself. Some very knowledgeable people have given you a massive amount of advice on how to implement this feature. I think it is up to you at this point to actually do some of the work now.