Rigidbody2D doesn't fall correctly when using MovePosition to move it horizontally
I am trying to create a simple character controller where I add a Rigidbody2D component to a square and add the following script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour {
public float horizontal_speed;
private Rigidbody2D rb;
private Vector2 horizontal_velocity;
// Use this for initialization
void Start () {
rb = GetComponent<Rigidbody2D> ();
}
// Update is called once per frame
void Update () {
Vector2 movement = new Vector2 (Input.GetAxisRaw ("Horizontal"), 0);
horizontal_velocity = movement * horizontal_speed;
}
void FixedUpdate() {
rb.MovePosition (rb.position + horizontal_velocity * Time.fixedDeltaTime);
}
}
Before adding the script, the box would fall normally, but afterwards it would fall extremely slowly and at a constant rate, but I could move it left and right as I made it able to. My Rigidbody2D is dynamic and has all default settings, except I set Interpolate on.
I'm not exactly sure what's going on here, could I have an explanation as to what rb.MovePosition really does please?
Your answer
Follow this Question
Related Questions
HELP! RigidBody2D position is acting incredibly goofy!! 0 Answers
How to use Rigidbody2D.MovePosition to move a kinematic object around looping waypoints? 1 Answer
Rigidbody2D.MovePosition acting a bit strange 0 Answers
rotate a transform relative to parent rigidbody speed vector 1 Answer
How do I keep enemies (rigidbodies) from pushing each other? 1 Answer