Entities.WithAll<HasSword>().ForEach((Entity e, int entityInQueryIndex, ref Translation translation) =>
{
var newEntity = ecb.Instantiate(entityInQueryIndex,Prefab);
ecb.AddComponent<RotationComponent>(entityInQueryIndex, newEntity);
float3 realDirection = mouseLocation - translation.Value;
ecb.SetComponent(entityInQueryIndex, newEntity, new RotationComponent
{
centerPoint = translation.Value,
centerDirection = realDirection,
speed = 50f
}) ;
ecb.SetComponent(entityInQueryIndex, newEntity, new Translation
{
Value = translation.Value
});
float centerAngle = calCenterAngle(realDirection.x, realDirection.y);
float halfLength = Mathf.PI / 3;
Debug.Log("initial angle "+(centerAngle + halfLength) * (180 / Mathf.PI));
Vector3 initialRV = new Vector3(Mathf.Cos(centerAngle + halfLength), Mathf.Sin(centerAngle + halfLength ),0);
Quaternion initialAngle = Quaternion.LookRotation(Vector3.forward, initialRV);
ecb.SetComponent(entityInQueryIndex, newEntity, new Rotation
{
Value = initialAngle
});
ecb.AddComponent<AgeComponent>(entityInQueryIndex, newEntity);
ecb.SetComponent<AgeComponent>(entityInQueryIndex, newEntity, new AgeComponent(10f));
ecb.AddComponent<PhysicsVelocity>(entityInQueryIndex, newEntity);
//ecb.SetComponent<PhysicsVelocity>(entityInQueryIndex, newEntity,new PhysicsVelocity { Angular = 50});
}).WithoutBurst().Run();
I have to use without burst here while I can use schedule mode for the following code:
Entities.WithAll<HasFireballTag>().ForEach((Entity e, int entityInQueryIndex, ref Translation translation) =>
{
var newEntity = ecb.Instantiate(entityInQueryIndex, fireballPrefab);
ecb.AddComponent<MovementComponent>(entityInQueryIndex, newEntity);
float3 realDirection = mouseLocation - translation.Value;
//Vector3 moveValue = new Vector3(realDirection.x, realDirection.y, realDirection.z);
//moveValue.Normalize();
//float3 movefValue = new float3(moveValue.x, moveValue.y, moveValue.z);
ecb.SetComponent(entityInQueryIndex, newEntity, new MovementComponent
{
direction = realDirection,
speed = 50
}) ;
ecb.SetComponent(entityInQueryIndex, newEntity, new Translation
{
Value = translation.Value
});
Quaternion rotation = Quaternion.LookRotation(Vector3.forward,realDirection);
ecb.SetComponent(entityInQueryIndex, newEntity, new Rotation
{
Value = rotation
});
ecb.AddComponent<FireballAgeComponent>(entityInQueryIndex, newEntity);
ecb.SetComponent<FireballAgeComponent>(entityInQueryIndex, newEntity, new FireballAgeComponent
{
age = 0,
maxAge = 2
});
ecb.AddComponent<PhysicsVelocity>(entityInQueryIndex, newEntity);
}).ScheduleParallel();
What’s the different?