Set velocity of kinematic rigidbody appropriately
Asked Answered
B

3

0

So I’m moving kinematic rigidbodies via scripting and I want their velocity to be set appropriately as they move. Right now, if they touch other physics objects, they should influence them after touching/give them momentum, but I can’t get it to work.

When I try to set the velocity value in the script that moves the object, I get the following error:

Actor::setLinearVelocity: Actor must be (non-kinematic) dynamic!

Which seems to be a PhysX error, but also kind of bullshit, since the only other understandable solution to this issue (kinematic rigidbodies automatically adjust their velocity with changes in position) doesn’t seem to be the case.

I can think of other ways to get around this issue, but by far the BEST solution would be to just have the rigidbody’s velocity value work correctly.

How can I get this to work?

Babb answered 26/1 at 22:12 Comment(1)

I have been trying to accomplish something similar. The traditional definition of kinematic is an object with a inverse inertia tensor of 0 (i.e. infinite mass). This is fairly easy to implement in a physics solver, and velocity can be trivially taken into account. Emulating it with a very heavy object whose position and velocity are set in fixed update should be a possibility, but for me this seems to kill performance. David Wu

Photogram
H
0

Kinematic rigidbodies are unaffected by physics, so they cannot have a velocity because that is in the realm of physics. Use transform.Translate instead.

Hartle answered 6/6, 2023 at 2:26 Comment(1)

Kinematic rigidbodies can collide with physics objects/stop their collisions, no? That's not exactly true that they're unaffected by physics. Since they can affect other things, using their velocity to apply impulses seems to be an obvious use of isKinematic to me.

Babb
S
0

Really old result, but was the first that showed up on google so if anyone else has the same question, you probably want to use

rigidbody.MovePosition( newPosition );
Skulk answered 26/1 at 22:15 Comment(0)
P
0

Move your kinematic rigidbody exclusively with Rigidbody.MovePosition from FixedUpdate at the precise velocity you want:

rb.MovePosition(rb.position + velocity * Time.deltaTime);

with velocity being a Vector3 in the direction and magnitude (in m/s) of the movement.

When done like this, reading Rigidbody.velocity returns the same velocity vector you’re applying.

This also works for angular velocity. Use Rigidbody.MoveRotation in the same way for rotating at a specific rate.

Prescott answered 27/1 at 8:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.