#How do I remove the turning lock and

1 messages · Page 1 of 1 (latest)

coarse socket
#

Unless you are moving the legs separately you only need a rigidbody on the root object of the cow and apply movement there. You should also use force functions to make changes to physics objects. Use AddForce to move it and AddTorque to apply rotation. You may also need to set the center of gravity to be much lower as if there is a large weight high up it will naturally want to topple over. Removing friction might help there too.

elfin coral
#

I have no physic materials

coarse socket
#

Any colliders will have a physics material and if an object has a rigidbody then it will use the physics material to decide how to react when touching them. All will have a default material. You can just create a new one and assign it to the bottom parts of the cow

elfin coral
#

I have found a fix for turning, but the cow shakes when I'm turning

Cube_rb3.MoveRotation(Cube_rb3.rotation * deltaRotation_left);
Cube_rb4.MoveRotation(Cube_rb4.rotation * deltaRotation_left);
coarse socket
#

Yeah, MoveRotation is fine too

elfin coral
#

I can rotate the cow without any limits now

#

also

#

I use only a, w, d here

#

no s

#

for controlling

coarse socket
#

The wobble could be because you look to have a rigidbody on all cubes. If you have only one on the root object of the cow then all the other colliders will be combined into one and you will have a rigid cow. Currently you can see the legs wobbling, probably because they are separate. Or do you need them separate?

elfin coral
#

what do you mean legs separate?

coarse socket
#

Do the leg cubes have rigidbodies?

elfin coral
#

Yes

coarse socket
#

Normally for a character there should only be one rigidbody and you apply the motion there. When you have child rigidbodies things get more complicated. If you really need that you will probably need to use joints to connect them. I would recommend having a single root object that has one rigidbody and the legs are just colliders as children of it. All the colliders in that hierarchy will be bound together into one shape that is controlled by the root rigidbody

elfin coral
#

well, I want to apply force exactly to legs, because when I tried applying it to body things got bad

#

well, I mean Cube as a body

#

maybe with Cow it would be ok

coarse socket
#

That was the right approach. Just need to ensure theres only one rb

elfin coral
#

but how would I apply force to legs if there will be one rigidbody?

#

that's possible to?

coarse socket
#

Why do you want to apply force to the legs? You would normally have a single object that you move around and the legs are handled by just animation. Unless essential for a game feature the legs should be cosmetic

elfin coral
#

tho I know that it still doesn't move fully logical

#

I just want to make sure the controls wouldn't be something of sort of drifting on ice

coarse socket
#

Sure. I would think of it more like a single cube that you are moving. You can have friction on that however you like to get the feel of it. Applying forces will be from its centre and so will move it forward etc. The legs are then just cosmetic and can even not have colliders. Just have a single cube at the root object with the rb. You are basically driving around a cube

#

Or, you can put 4 spheres at the base of the cube if you need to round out the movement

#

This is what could work. Just a single rb on the root object. The legs are then cosmetic

elfin coral
#

@coarse socket How can I move into a direction but not direction of some exact local or world position?

#

the way in my code it moves on a direction when I press w key is wrong

#

because it moves on an exact local or world position

#

meaning if I rotate cow it will move by it's back to the position

elfin coral
#

So I fixed it with a bad way

#

now because I made one Rigidbody there's a problem

coarse socket
#

So are you doing AddForce(transform.forward * forwardSpeed) for forward motion?

elfin coral
#

yes

#

I have added a weight but that doesn't do any effect

#

the only thing what it can do is to make a different gravity of the whole object

coarse socket
#

You shouldn't directly modify the velocity but rather use forces or the MovePosition function

elfin coral
#

isn't moveposition for instantly moving?

coarse socket
#

No, it is for moving using physics. Teleporting is when you just set the position directly. Perhaps try rb.MovePosition(transform.foward*forwardSpeed);

#

The MovePosition will set a force/velocity that will get to the target point by the next update (or as far as it can depending on collisions)

elfin coral
coarse socket
#

The problem with that is that a continuous force will accelerate it. The MovePosition option will keep to a fixed speed - if that's what you want

elfin coral
#

what is a fixed speed?

coarse socket
#

Oh, the tranform right would strafe it right

elfin coral
coarse socket
#

Like a car, a force is like holding the accelerator. Keeping it on will make you go faster and faster.

#

Try the MovePosition I suggested above with the transform.forward vector. Get forward working first

elfin coral
#

can you give me the line?

coarse socket
#

rb.MovePosition(transform.foward*forwardSpeed);

#

To be more precise: rb.MovePosition(transform.foward * forwardSpeed * Time.deltaTime);

#

Actually if you are in Update just use deltaTime

#

But this should really be done in FixedUpdate

elfin coral
#

why should I use time thing?

#
if (Input.GetKey(KeyCode.W))
        {
            Cube_rb.MovePosition(transform.forward * speed);
        }
#

idk why but it spins and goes under the ground

#

on any speed

coarse socket
#

The MovePosition defines where you want it in the next FixedUpdate, so to be "correct" you need to make it a fraction of the fixedDeltaTime if you want the speed to be units per second. Not essential but correct. This will basically divide it by 50 for the 50 frames per second the physics system normally updates

#

Try a very low speed and check that the cows forward direction is in its Z axis. Make sure the Scene view is showing local and look at the axis when it is selected

elfin coral
#

that one was due to moveposition

#

Cube_rb.MovePosition(transform.right * speed);

#

when I press w it tps me under the ground

#

and then when I continue press w I get stuck going up to the floor

coarse socket
#

Check the axis of the cow. The blue Z axis should be facing forward and the green Y should be up

elfin coral
#

how can I check it?

coarse socket
#

Select it in the scene view and check that the scene view top left settings are like the other image I posted

#

Set to Local

elfin coral
#

yeah

#

it's on local

#

already

coarse socket
#

Ok so are the axes like my pic?

elfin coral
coarse socket
#

Ok, so your forward is -ve X for that setup. Is good practice to have the forward along the Z axis. That way transform.forward matches the forward of the object

#

transform.right would push it along the red axis there