I am working on an Air Hockey game; I tried making the movement physics-based, by doing this:
using UnityEngine;
public class Player : MonoBehaviour
{
private Rigidbody m_Rigidbody;
private float HorizontalInput;
private float VerticalInput;
public float Speed = 1.0f;
private void Start()
{
m_Rigidbody = GetComponent<Rigidbody>();
}
private void Update()
{
HorizontalInput = Input.GetAxisRaw("Horizontal");
VerticalInput = Input.GetAxisRaw("Vertical");
}
private void FixedUpdate()
{
m_Rigidbody.AddForce(new Vector3(VerticalInput * Speed, 0.0f, -HorizontalInput * Speed),ForceMode.VelocityChange);
}
}
and by adding a PhysicsMaterial
to the MeshCollider
attached to my player:
The movement should be quick and responsive, but it feels rather sloppy and unresponsive; I also tried using Input.GetAxisRaw(...)
, but the controls become quite clunky.
How can I improve on this? Is there a go-to way to do this type of movement in Unity?
(I would like the final version of the game to be played on controllers) [1]: https://i.sstatic.net/OTEHV.png