Created
May 5, 2020 01:53
-
-
Save SenpaiRar/c2d9354f03a4ccd2e9eaaa4d00b7ce00 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 System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class PlayerMovement : MonoBehaviour | |
{ | |
public Rigidbody PlayerBody; | |
public float Speed; | |
public float FrictionalForce; | |
public Camera PlayerCam; | |
private void FixedUpdate() | |
{ | |
Vector3 RotVec = new Vector3(PlayerCam.ScreenToWorldPoint(Input.mousePosition).x, 0, PlayerCam.ScreenToWorldPoint(Input.mousePosition).z); | |
transform.LookAt(RotVec); | |
Vector3 x = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); | |
PlayerBody.AddForce((x*Speed)); | |
PlayerBody.AddForce(-PlayerBody.velocity*PlayerBody.velocity.magnitude*FrictionalForce); | |
PlayerBody.position = new Vector3(transform.position.x, 0, transform.position.z); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment