Job System usage on Moving Different Transform in Different Speeds
Main Objective: Trying to move different GameObjects in different speeds and stopping them depending on their position from one job.
I am currently making a Tower Defence game where there will be hordes of enemies coming to the castle. Moving 500-1000 objects to the Tower is really taxing on normal Update in every enemy object. I have made it so one EnemyManager moves every enemy object in IJobParallelForTransform work, where i call the work in EnemyManager on Update.
But the problem arises when i try to change their speeds. Every enemy will have different speeds depending on their type and size. But i cant pass any value in a job with normal manner.
I have tried to create 3 with fixed count where an enemyobject, enemyobject.speed, enemyobject.isMoving will be stored with sync. But i cant sync it with TransformAccessArray, because it doesnt behaves like an array. I cant allocate 500 transforms in it with null values, i can only use TransformAccessArray.Add to add some transforms in it. But enemies can die without order, so sync just collapses after some enemies dies.
Then i used nativearrays to find create and new nativearrays everyframe to pass the list as native arrays in the job using .ToArray() , but it feels like it slows it down too much to be playable.
How can i do this, or more importanly, is there any clear definition what jobs actually do, the ways to pass values in it, nativearrays working logic and so on. My only major obstacle is this right now, every little thing helps.
Desired Structure is (as pseudocode)
movementJob : IJobParallelForTransform{
Execute(int index, TransformAccessArray transform)
{
if( enemyList[index].ismoving )
{
transform.position += enemySpeed[index] * deltatime * Vector2.left;
}
}
Thanks a lot in advance.
Your answer
Follow this Question
Related Questions
One GameObejct script affecting another GameObject of the same prefab 0 Answers
Tree chopping 0 Answers
Rotation script isn't working 1 Answer
How does CollisionFlags work? 0 Answers