forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayerMovementSystem.cs
More file actions
40 lines (35 loc) · 1.24 KB
/
Copy pathPlayerMovementSystem.cs
File metadata and controls
40 lines (35 loc) · 1.24 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
using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
using Unity.NetCode;
using Unity.Transforms;
namespace KickBall
{
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
public partial struct PlayerMovementSystem : ISystem
{
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<PlayerConfig>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var playerConfig = SystemAPI.GetSingleton<PlayerConfig>();
var speed = SystemAPI.Time.DeltaTime * playerConfig.Speed;
foreach (var (playerTransform, input) in
SystemAPI.Query<RefRW<LocalTransform>, RefRO<PlayerInput>>()
.WithAll<Player, Simulate>())
{
if (input.ValueRO.Horizontal == 0 && input.ValueRO.Vertical == 0)
{
continue;
}
// ... todo disallow player from walking through obstacles
var move = new float3(input.ValueRO.Horizontal, 0, input.ValueRO.Vertical) * speed;
playerTransform.ValueRW.Position += move;
}
}
}
}