Having trouble to get my player to move, they are using an ECS, is there any problems with my code?
using UnityEngine;
using Unity.Entities;
using Unity.Burst;
using Unity.Transforms;
using Unity.Mathematics;
[BurstCompile]
public partial struct PlayerSystem : ISystem
{
//public void OnCreate(ref SystemState state){ }
//public void OnDestroy(ref SystemState state) { }
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
float horizontalInput = Input.GetAxisRaw("Horizontal");
float verticalInput = Input.GetAxisRaw("Vertical");
Vector2 movement2D = new Vector2(horizontalInput, verticalInput);
movement2D = movement2D.normalized;
float3 movement = new float3(movement2D.x, movement2D.y, 0);
foreach (var (player, localTransform) in SystemAPI.Query<RefRW<Player>, LocalTransform>())
{
movement = math.normalize(movement);
Entity playerEntity = player.ValueRW.Entity;
LocalTransform playerTransform = state.EntityManager.GetComponentData<LocalTransform>(playerEntity);
playerTransform.Position += movement * player.ValueRW.Speed;// * Time.deltaTime;
state.EntityManager.SetComponentData(player.ValueRW.Entity, localTransform);
state.EntityManager.SetComponentData(player.ValueRW.Entity, player.ValueRW);
}
}
}