My question is - how can I set up a forward vector for my Entity via SetComponentData. I want to get transform.forward vector from an object on the scene and make my Entity look forward in the same direction.
generator picture
I want my object on spawn will have the same z-axis direction as for spawnPoint.
For common GameObject, I will do something like this
For Entity, I try to make something like this (this is doesn’t work!)
_entityManager.SetComponentData(newCar, new Rotation
{
Value = Quaternion.Euler(selectedSpawnPoint.transform.forward)
});
I try to use old guides, but can’t do anything with this. Thank you for help
QUESTION CLOSED!
So, I find a solution for my task
_entityManager.SetComponentData(newCar, new Rotation
{
Value = quaternion.LookRotationSafe(selectedSpawnPoint.transform.forward, selectedSpawnPoint.transform.up)
});
I think you are mixing the old api with the new one a bit too much here.
I think you should be getting localToWorld.Forward of your spawnPoint entity and simply set the localToWorld.Forward of your spawning entity to be the same value.
@MagicianArtemk In that case get the
Quaternion.LookRotation(transform.forward, transform.up) of your spawnPoint entity and simply set the localToWorld.Forward of your spawning entity to that value.
Quaternions and rotations in the new Unity.Mathematics/ECS are a bit cleaner imo.