Skip to content

Commit 4ac459e

Browse files
committed
New movement for characters
1 parent 16b9209 commit 4ac459e

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

Assets/Prefabs/Entities/Character.prefab

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,8 @@ MonoBehaviour:
253253
m_Script: {fileID: 11500000, guid: f2b08ea5885206b4fa8b7705d2cea470, type: 3}
254254
m_Name:
255255
m_EditorClassIdentifier:
256-
_stopDistance: 1
256+
_controller: {fileID: 7741969963255743558}
257+
_stopDistance: 1.25
257258
--- !u!114 &1412476411330839976
258259
MonoBehaviour:
259260
m_ObjectHideFlags: 0
@@ -314,7 +315,7 @@ CharacterController:
314315
m_Enabled: 1
315316
serializedVersion: 2
316317
m_Height: 2
317-
m_Radius: 0.5
318+
m_Radius: 0.4
318319
m_SlopeLimit: 45
319320
m_StepOffset: 0.3
320321
m_SkinWidth: 0.08
@@ -346,7 +347,7 @@ CapsuleCollider:
346347
m_Material: {fileID: 0}
347348
m_IsTrigger: 0
348349
m_Enabled: 1
349-
m_Radius: 0.5
350+
m_Radius: 0.4
350351
m_Height: 2
351352
m_Direction: 1
352353
m_Center: {x: 0, y: 1, z: 0}

Assets/Prefabs/Entities/FastEnemy.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2142,7 +2142,7 @@ NavMeshAgent:
21422142
m_GameObject: {fileID: 8462756137193698166}
21432143
m_Enabled: 1
21442144
m_AgentTypeID: 0
2145-
m_Radius: 0.5
2145+
m_Radius: 0.4
21462146
m_Speed: 3.5
21472147
m_Acceleration: 8
21482148
avoidancePriority: 50

Assets/Prefabs/Entities/SlowEnemy.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1460,7 +1460,7 @@ NavMeshAgent:
14601460
m_GameObject: {fileID: 6279035074604445379}
14611461
m_Enabled: 1
14621462
m_AgentTypeID: 0
1463-
m_Radius: 0.5
1463+
m_Radius: 0.4
14641464
m_Speed: 3.5
14651465
m_Acceleration: 8
14661466
avoidancePriority: 50

Assets/Prefabs/Entities/VerySlowEnemy.prefab

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ NavMeshAgent:
13071307
m_GameObject: {fileID: 5640901391711308156}
13081308
m_Enabled: 1
13091309
m_AgentTypeID: 0
1310-
m_Radius: 0.5
1310+
m_Radius: 0.4
13111311
m_Speed: 3.5
13121312
m_Acceleration: 8
13131313
avoidancePriority: 50

Assets/Scripts/Entities/Character/Behaviors/CharacterMovement.cs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace ZombieRun.Entities.Characters
44
{
5-
using Utils;
6-
75
public class CharacterMovement : CharacterBehaviorBase
86
{
9-
[Range(1f, 3f)]
10-
[SerializeField] private float _stopDistance = 1f;
7+
[SerializeField] private CharacterController _controller = null;
8+
[Range(1f, 2f)]
9+
[SerializeField] private float _stopDistance = 1.25f;
1110

1211
private MovementSettings _settings;
1312
private float _turnSmoothVelocity;
@@ -17,13 +16,6 @@ public class CharacterMovement : CharacterBehaviorBase
1716

1817
private void Update()
1918
{
20-
if (_target == null)
21-
return;
22-
23-
Debug.Log(transform.GetDistanceTo(_target));
24-
if (transform.GetDistanceTo(_target) < _stopDistance)
25-
return;
26-
2719
Move();
2820
}
2921

@@ -50,8 +42,15 @@ private void Rotate(Vector3 direction)
5042

5143
private void Move()
5244
{
53-
var step = _settings.moveSpeed.value * Time.deltaTime;
54-
transform.position = Vector3.MoveTowards(transform.position, _target.position, step);
45+
if (_target == null)
46+
return;
47+
48+
var offset = _target.position - transform.position;
49+
if (offset.magnitude < _stopDistance)
50+
return;
51+
52+
var motion = offset.normalized * _settings.moveSpeed.value * Time.deltaTime;
53+
_controller.Move(motion);
5554
}
5655

5756
private void OnTargetChanged(Transform target)

0 commit comments

Comments
 (0)