Advertisement
MoscosoMaximiliano

Movimiento Personaje

May 19th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MovimientoReal : MonoBehaviour
  6. {
  7.     Rigidbody2D rb; // variable que va a tener nuestras físicas
  8.  
  9.     public float velocidad; // velocidad con la que se mueve el persona
  10.  
  11.     float horizontal; // input del jugador para mover
  12.  
  13.     void Start()
  14.     {
  15.         rb = GetComponent<Rigidbody2D>(); // obtenemos el Rigibody2D
  16.     }
  17.  
  18.    
  19.     void Update()
  20.     {
  21.         horizontal = Input.GetAxis("Horizontal")  * velocidad; // a: -1 d: 1 (o flechas)
  22.     }
  23.  
  24.     void FixedUpdate()
  25.     {
  26.         //rb.AddForce(new Vector2(horizontal, 0f) * velocidad); // Este aplica fuerza
  27.         rb.velocity = new Vector2(horizontal, rb.velocity.y); //Este modifica la velocidad
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement