Skip to content

Instantly share code, notes, and snippets.

@SenpaiRar
Created May 5, 2020 01:53
Show Gist options
  • Save SenpaiRar/c2d9354f03a4ccd2e9eaaa4d00b7ce00 to your computer and use it in GitHub Desktop.
Save SenpaiRar/c2d9354f03a4ccd2e9eaaa4d00b7ce00 to your computer and use it in GitHub Desktop.
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