Unity’s New Input System
Using UnityEngine.InputSystem;
Public class PlayerController : MonoBehaviour
{
[SerializeField] float torqueAmount = 1f;
InputAction moveAction;
Rigidbody2D myRigidbody2D;
Void Start()
{
//Basically we created a new variable in order to track the Move action
inside our Input Sytem
moveAction = InputSystem.actions.FindAction(“Move”);
//I’m taking this component and putting it inside myRigidbody2D variable
myRigidbody2D = GetComponent<Rigidbody2D>();
}
Void Update()
{
// I want moveVector to be whatever is inside of my moveAction
//Basically I´m just getting the Vector2 that is inside moveAction ans then
I´m putting it inside moveVector
Vector2 moveVector;
moveVector = moveAction.ReadValue<Vector2>();
if (moveVector.x <0)
{
myRigidbody2D.AddTorque(torqueAmount);
}
else if (moveVector.x >0)
{
myRigidbody2D.AddTorque(-torqueAmount);
}
}
}
Angular Damping to slow down the rotation of the player.
Eatty Mcdash
R scale
W rotate
Add collider to bump into things
Add rigidbody for physics
Turn Gravity Scale to 0 in the Rigidbody if your game doesn’t have gravity or it will fall
down.
At least 1 of the sprites have to have a rigidbody for them to interact with each other.
If only one has a rigidbody when they bump into each other the one without a rigidbody
wont move, it will be like a pillar. If you want to move it it will have to have a rigidbody as
well.
Public lass Collision : MonoBehaviour
{
Void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log(“Ouch”);
}
}
Este se pone en un nuevo script llamado Collisions y se arrastra al coche.
Para OnTriggerEnter se tiene que dar click en is trigger n el box collider.
Siempre usar el 2D en todo, si no unity usa el 3D y no funciona el código por que estoy
aprendiendo juegos 2D ahorita.
Void OnTriggerEnter2D(Collider2D collision)
{
Debug.Log(“What the heck was that?”;
}