- Home /
The character velocity changes while the rigidbody is kinematic
In the Walk function, the velocity changes although the rigidbody is kinematic. I am changing the rigidbody to non-kinematic after the setting the velocity.
In the Jump function, the velocity changes after setting the rigidbody to non-kinematic. I know the Jump function is the correct way to do so but how in the Walk function it's working?
Shouldn't the velocity change only when the body is non-kinematic?
public virtual void Walk(float value) {
var targetVelocity = new Vector2(speed * value, body.velocity.y);
body.velocity = Vector3.SmoothDamp(body.velocity, targetVelocity,
ref _velocity, m_MovementSmoothing);
if (body.isKinematic) { body.isKinematic = false; }
}
public virtual void Jump() {
if (body.isKinematic) { body.isKinematic = false; }
body.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
}
Answer by xxmariofer · Mar 29, 2019 at 01:04 PM
I imagine thats just how gets coded, you cant add a force to a rigidbody that is set to kinematic, inside the addforce method there will be an if making sure the body is not kinematic, but the velocity is a property, and inside the property there is no if checking the body kinematic, so you can set the velocity and as long as in the next physics cicle isnt set to kinematic it will work, it seems logic to me.
Since remember that changing the rigidbody propertys in the fixedupdate will not get "Updated" untill the next physics cicle
Your answer
Follow this Question
Related Questions
Rigidbody2d.addforce in the direction of mouse problem 1 Answer
How do I Spawn an Object on a Seafloor Randomly? 0 Answers
,Rotate a gameobject around another while being attracted by its gravity 1 Answer
Interpolation issue, some items not being interpolated correctly. 0 Answers
Unity 2D Physics .AddForce 1 Answer