-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerControl.cs
More file actions
50 lines (39 loc) · 1.16 KB
/
PlayerControl.cs
File metadata and controls
50 lines (39 loc) · 1.16 KB
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
50
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerControl : MonoBehaviour
{
[System.Serializable]
public class MovementSettings{
public static float forwardVelocity = 0;
}
public Animator anim;
public MovementSettings movementSettings = new MovementSettings();
public Transform player;
private Vector3 _velocity;
private Rigidbody _rigidbody;
private Vector3 _target = Vector3.zero;
// Start is called before the first frame update
void Start()
{
_rigidbody = GetComponent<Rigidbody>();
_velocity = Vector3.zero;
anim = GetComponent<Animator>();
}
// Update is called once per frame
void FixedUpdate()
{
Run();
_rigidbody.velocity = _velocity;
_target = new Vector3(player.position.x, 0.4f, player.position.z);
transform.position = Vector3.Lerp(transform.position, _target, 1f);
}
void Update()
{
anim.SetFloat("speed", PlayerControl.MovementSettings.forwardVelocity);
}
void Run()
{
_velocity.z = -1*MovementSettings.forwardVelocity;
}
}