Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class MovimientoReal : MonoBehaviour
- {
- Rigidbody2D rb; // variable que va a tener nuestras físicas
- public float velocidad; // velocidad con la que se mueve el persona
- float horizontal; // input del jugador para mover
- void Start()
- {
- rb = GetComponent<Rigidbody2D>(); // obtenemos el Rigibody2D
- }
- void Update()
- {
- horizontal = Input.GetAxis("Horizontal") * velocidad; // a: -1 d: 1 (o flechas)
- }
- void FixedUpdate()
- {
- //rb.AddForce(new Vector2(horizontal, 0f) * velocidad); // Este aplica fuerza
- rb.velocity = new Vector2(horizontal, rb.velocity.y); //Este modifica la velocidad
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement