movement - Unity3d C# turret gun projectile won't move -
i'm working on gun turret. i've got working except having projectile shoot out of turret gun barrel. currently, barrel used is
void start(){ firingpointright = gameobject.findgameobjectwithtag ("firingpointright").transform; firingpointleft = gameobject.findgameobjectwithtag ("firingpointleft").transform; }
void update() { if(input.getmousebutton(0)){ count++; if (count >= maxcount) { count = 0; //debug.log ("fire"); firingpointright = gameobject.findgameobjectwithtag ("firingpointright").transform; firingpointleft = gameobject.findgameobjectwithtag ("firingpointleft").transform; // create cannon muzzle fire effect. gameobject e1 = instantiate (cannonmuzzlefire) gameobject; e1.transform.position = firingpointright.transform.position; e1.transform.rotation = firingpointright.transform.rotation; destroy (e1, 0.03f); gameobject e2 = instantiate (cannonmuzzlefire) gameobject; e2.transform.position = firingpointleft.transform.position; e2.transform.rotation = firingpointleft.transform.rotation; destroy (e2, 0.03f); //------------------------------------------- //left cannon. fire projectile cannon. //debug.log ("firing left"); rigidbody instantiateedprojectile = instantiate(cannonammo, firingpointleft.transform.position, firingpointleft.transform.rotation) rigidbody; if (instantiateedprojectile != null) { print ("firing projectile"); instantiateedprojectile.transform.translate(vector3.forward * cannonammospeed * time.deltatime); } } }
does projectile have script of own? doesn't you're setting velocity instantiated projectile.
translate() doesn't perform much in way of movement, other setting new position. if projectile has rigidbody component attached, can straight set velocity of rigidbody.
like so:
instantiateedprojectile.velocity = vector3.forward * cannonammospeed;
time.deltatime wouldn't used here, since needs included in calculations performed every frame.
as side note, might wish consider reusing flare effect instead of spawning new 1 every shot. can create effect invisible , reset between shots instead, give improve performance.
unity3d movement projectile
No comments:
Post a Comment