So, I’m not having a problem but I’m curious about something.
public class RubyController : MonoBehaviour
{
Rigidbody2D rigidbody2D;
float horizontal;
float vertical;
// Start is called before the first frame update
void Start()
{
rigidbody2D = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
vertical = Input.GetAxis("Vertical");
horizontal = Input.GetAxis("Horizontal");
}
private void FixedUpdate()
{
Vector2 position = transform.position;
position.y = position.y + (3.0f * vertical * Time.deltaTime);
position.x = position.x + (3.0f * horizontal * Time.deltaTime);
rigidbody2D.MovePosition(position);
}
}
The above works for what I need it to do - keep in mind I’m doing the 2D Beginner Tutorial Ruby’s Adventure.
But the code below causes Ruby to move extremely slow, and I’m curious why that’s the case.
public class RubyController : MonoBehaviour
{
Rigidbody2D rigidbody2D;
float horizontal;
float vertical;
// Start is called before the first frame update
void Start()
{
rigidbody2D = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
vertical = Input.GetAxis("Vertical");
horizontal = Input.GetAxis("Horizontal");
Vector2 position = transform.position;
position.y = position.y + (3.0f * vertical * Time.deltaTime);
position.x = position.x + (3.0f * horizontal * Time.deltaTime);
rigidbody2D.MovePosition(position);
}
}