[Help] Projectiles Question

In the last project BlockBreaker I implemented a shooting system, when the player got the appropriate power up, and in that project I moved the projectiles using this code:

clone.transform.Translate (Vector3.up * speed *Time.deltaTime);

(I instantiated the object as clone). So I went and typed this code for this project and nothing happened and I’m a little lost as to why. Then i thought I would use the code that we have been using all along to move objects:

clone.transform.position += Vector3.left * speed * Time.deltaTime;

And that didn’t work either! To be honest that shocked me a little. So why is it that in this instance clone.rigidbody2D.velocity2D worked and the other two methods did not?

To anyone who can shed some light on this matter here is a big thankyou in advance.

Regards,
Vaughan.

Hi Vaughan!, actually it work but you are not updating it’s position ( it’s translated by a tiny amount since you are multiplying by delta time), with rigidbody velocity instead, you assign to the clone a linear velocity handled by the internal loop of the physic calcuation.

I prefer to instantiate the projectile clone as a rigid body for example:

Rigidbody2D laserClone = Instantiate(laser, transform.position, Quaternion.identity) as Rigidbody2D;
laserClone.velocity = Vector2.up * laserSpeed;

:blush:. Ok, I think I get it now. Based on what you said I took the translate code out of where it is instantiated and made a bool called bulletFired and put in the script if missileFired then translate the sprite and that worked fine - it could then update it’s position. I wish I had known that before I posted. Still I learnt something and that’s always good.

Glad it helps :slight_smile: I’m still learning too!

Privacy & Terms