Last active
June 27, 2020 02:12
-
-
Save niiicolai/46c09c018e270f396bf37793b3fede88 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class Movement : MonoBehaviour | |
{ | |
private Rigidbody rigidbody; | |
[SerializeField] | |
private float speed; | |
[SerializeField] | |
private ForceMode forceMode; | |
// Start is called before the first frame update | |
void Start() | |
{ | |
rigidbody = GetComponent<Rigidbody>(); | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
// EXAMPLE 1 | |
float h = Input.GetAxis("Horizontal"); | |
float v = Input.GetAxis("Vertical"); | |
Vector3 velocity = new Vector3(0, 0, v); | |
velocity *= speed; | |
velocity -= rigidbody.velocity; | |
rigidbody.AddForce(velocity, forceMode); | |
/* EXAMPLE 2 | |
float h = Input.GetAxis("Horizontal"); | |
float v = Input.GetAxis("Vertical"); | |
Vector3 velocity = new Vector3(0, 0, v); | |
velocity = transform.TransformDirection(velocity); | |
velocity *= speed; | |
velocity -= rigidbody.velocity; | |
rigidbody.AddForce(velocity, forceMode); | |
transform.Rotate(new Vector3(0, h, 0)); | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment