-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovement.cs
49 lines (41 loc) · 1.38 KB
/
Movement.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public Rigidbody rb;
public float wMovement;
public float rotating;
public float rotationRate;
public float turnRotationSeekSpeed;
public Transform tr;
private float groundAngelVelocity;
private float rotationVelocity;
void Start()
{
Debug.Log("Works");
}
void FixedUpdate()
{
//This rotates the car at Y axis
Vector3 turnSmooth = Vector3.up * rotationRate * Input.GetAxis("Horizontal");
turnSmooth = turnSmooth * Time.deltaTime * rb.mass;
rb.AddTorque(turnSmooth);
//This makes a illusion of the rotation it only rotates the car but Z axis
Vector3 newRotation = transform.eulerAngles;
newRotation.z = Mathf.SmoothDampAngle(newRotation.z, Input.GetAxis("Horizontal") * -rotating, ref rotationVelocity, turnRotationSeekSpeed);
transform.eulerAngles = newRotation;
if (Input.GetKey("w"))
{
rb.AddForce(transform.forward * wMovement * 3);
}
if (Input.GetKey("s"))
{
rb.AddForce(transform.forward * wMovement * -3);
}
if (Input.GetKey("space"))
{
transform.Rotate(new Vector3(-1, 0, 0) * 2f);
}
}
}