Hi!
I created a character (by a group of blocks) and I want to move it by its legs. I’m in situation that legs themselves are moving, but the goal is to make floor friction work, so legs stay in place and whole character moves. Any ideas how to get this thing working properly?
This is how it works now:
Details:
- Legs are children of the body cube
- Legs and body have colliders and rigidbodies (only body uses gravity)
- Legs are connected to body by fixed joint
Script for moving legs looks like this:
For each leg:
Disconnect body from joint
Move leg
Connect body to the joint
Legs and floor have material with friction, stabilizing collider at the bottom has no friction.
I know, that this approach can’t work, but I tried so many combinations, and none worked. Please, help me figure this out.
How do you move legs?
By Transform.position?
You shouldn’t be need to disconnect joints, if you need them.
Just use linear joints for example, with locked axis.
And probably you may don’t need joints at all and such complexity.
You could use simple character controller, unless you really need some semi realistic legs interaction.
But if you just want to move character, that can be done much simpler.
Thanks for replying!
Yes, I am currently using Transform.(local)position to move legs.
No, I want to use physics engine to move the player. In real world, in order to move, you have apply some torque on bones to change center of gravity and make a push against the floor, but of course in code it would be a pain in the neck. I wonder if I could make it only by changing position of the legs (or applying force) in a way, that floor will stop the leg (by friction) and all moving force made by this leg will be moved to the body. I think joints are essential to do this, but I also need to freely move legs (in code) in all axes and it doesn’t work well with joints.
In such case, ensure you joints are always connected.
Otherwise is bad design.
Then use RigidBody of legs AddForce, or add Velocity, what suites, instead of using Transform position. Transform Position ignores physics.