- Home /
(2D) MovePosition slows falling
private void FixedUpdate()
{
rb.MovePosition(rb.transform.position + Vector3.right * runSpeed * Time.fixedDeltaTime);
if (Input.GetButtonDown("Jump"))
{
RaycastHit2D hit = Physics2D.Raycast(rb.transform.position, Vector2.down, jumpSensitivity);
if (hit == true)
rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
}
}
This is my code. When my script is on, my character moves to the right at the appropriate speed. However, he falls too slowly (he spawns midair). I placed a cube next to him to test the falling speed, and he takes several times longer. When my script is off, however, they fall and hit the ground at the same time.
Anybody know what's causing this? Thanks!
Answer by maormenashe · Feb 14, 2020 at 11:01 PM
I believe both the cube and the character have dynamic rigidbody with the same gravity and that's why you're surprised of the character falling slower than the cube.
Since you're using rigidbody.MovePosition you disrupt the ability of the accelerated velocity by the gravity.
If you'll run a little test you'll see your rigidbody.velocity is set to 0.
I think you'll have to add extra velocity calculation by the gravity on your own and add it to your target position for the MovePosition.
I do hope there's a better way to do it, but not that i know of.
Hope this helps.
Your answer
Follow this Question
Related Questions
Physic function doesn't work in different resoultions 0 Answers
Rotate a weapon in a circle around player 1 Answer
physics Material 2D not working !!!! 1 Answer
[Solved] How to touch/activate 2D objects? 1 Answer
How do you detect if two specific objects are touching each other without collision. 3 Answers