object is not moved by ijobparallelfortransform

For some reason, the bullets do not move, but teleport. The speed in this line works like a coordinate. The higher the number, the further objects are formed. But they don’t move. What could be the reason?

 trans = new TransformAccessArray(transforms);
            native = new NativeArray<Vector3>(targets, Allocator.Persistent);
            PhysucBullet  job = new PhysucBullet();
            job.delt = Time.deltaTime;
            job.Targets = native;
            // job.speed = Speed;
            newJobHandle = job.Schedule(trans);
           newJobHandle.Complete();
            trans.Dispose();
            native.Dispose();
            yield return StartCoroutine(HowWait(Cooldown));
        }
    }

    private struct PhysucBullet : IJobParallelForTransform
    {
        public float delt;
        public NativeArray<Vector3> Targets;
        // public float[] speed;
        public void Execute(int index, TransformAccess Transform)
        {
            //  Transform.position = Vector3.Lerp(Transform.position, Targets[index], delt / 0.03f);
              Transform.position += (Targets[index] * 5f);
          
        }

The vectors are obtained from the angle.

var velocityVector = new Vector3(Mathf.Sin(angle * Mathf.Deg2Rad), 0, Mathf.Cos(angle * Mathf.Deg2Rad)); // преобразование угла в вектор
transforms[CountBullet] = _prefab1.transform;
targets[CountBullet] = velocityVector;

For the future, the DOTS forums are here.

1 Like

All right, thank you. I wonder why bullets don’t move? It seems that I did everything, as it was in the examples, but does not work. I tried to find a mistake, but it doesn’t work.

No idea. A snippet of code above won’t tell anyone that because it’s all just snippets. Debugging really: verfy the job is actually making changes, make sure the transform you assign is correct etc. In the snippet you’re assign what looks like the same transform to all of them. Also, it’s named prefab which makes me suspect you’re modifying the prefab, not the instance of a prefab.

Your code is very rough though, allocating persistent that should be tempjob, not using time-delta but a constant time etc. It’s all guesswork because it’s just rough snippets.

You’re better off though posting on the correct forum.

1 Like

What do you recommend to do with time? As for the transformation of variables, it seems true - I did, as was the case in the examples.

Okay, I’ll try to figure it out myself. It is necessary to make the simplest code without other methods by example and check how it will work.

1 Like

I’m confused over the question. You pass in time but don’t use it but instead use a constant 5. I mean, what do you want me to say here?

All code “seems true” until you debug it and find the problem. My recommendations were above in debugging it. You seem to want us to somehow debug it but we don’t have it and you’ve not said what you’ve verified apart from “stating it seems true”.

1 Like

It is clear, you need to throw the full script here? By the way, can you ask an off-topic question? How to optimize particle systems? Let’s say there is a particle system on each bullet. And there are about 200-400 such bullets on the screen, as a result of which the FPS drops. But the particle systems are the same on every bullet. Is it possible to somehow combine a particle system so that it consumes few resources? It seems that this is what consumes more resources than physics.

By the way, I seem to understand what my mistake is. Need to call newJobHandle every frame via Update or Coroutines? I put this in the Update and the bullets started flying. I want to make it work through Coroutine, but for some reason, the bullets do not fly.