'Why won't my Unity C# bullet go straight and keep a constant velocity?
Enemy bullets are curving after the enemy shoots and starts to rotate (towards the player who is dodging). Everything is Instantiated and Attack is called in the Update() however the CopyofCurrentRotation (misspelled in my code, I know) still is changing the velocity of the bullet.
public IEnumerator Attack(string goname)
{
IsAttacking = true; //Indicates if we are attacking
oldmovementspeed = MovementSpd;
MovementSpd = 0;
GameObject p = GuitarShooter.GrabObject();
p.transform.position = exitPoints[0].position;
p.transform.SetParent(this.transform);
yield return new WaitForSeconds(2.00f);
EvilProjectile q = p.GetComponent<EvilProjectile>();
q.Initialize(q.MyDamage);
if (q != null && q.HasBeenFired != true )
{
currentRoration = transform.rotation * Vector3.up;
copyofcurrentRoration = new Vector3(currentRoration.x, currentRoration.y, currentRoration.z);
q.MyEvilBody.velocity = CopyOfCurrentRoration * q.MySpeed;
q.HasBeenFired = true;
IsAttacking = false;
MovementSpd = oldmovementspeed;
StartCoroutine(Reload("morebullets"));
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
