Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
using Unity.Entities;
using Unity.Jobs;
using Unity.Collections;
using Unity.Burst;
using Unity.Transforms;
using Unity.Mathematics;
public class FollowTargetSystem : JobComponentSystem
protected override JobHandle OnUpdate(JobHandle inputDeps)
inputDeps = new LookTargetJob {
positionFromEntity = GetComponentDataFromEntity<Position>(true)
}.Schedule(this, inputDeps);
return inputDeps;
private struct LookTargetJob : IJobProcessComponentData<Target, Position, Rotation>
[ReadOnly] public ComponentDataFromEntity<Position> positionFromEntity;
public void Execute([ReadOnly] ref Target target, [ReadOnly] ref Position pos, [WriteOnly] ref Rotation rot)
if (!positionFromEntity.Exists(target.Value))
var targetPos = positionFromEntity[target.Value];
var diff = targetPos.Value - pos.Value;
rot.Value = quaternion.LookRotationSafe(diff, new float3(0, 1, 0));
using UnityEngine;
using Unity.Entities;
public class TargetComponent : ComponentDataWrapper<Target>{}
public struct Target : IComponentData
public Entity Value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.