IEnumerator CalculateTrajectory(Bullet bullet)
{
while (true)
{
bullet.flightTime += 0.1f;
//print("Fire1");
bullet.lastPosition.x = 0.0f;
bullet.lastPosition.y = bullet.startPosition.y + bullet.height;
bullet.lastPosition.z = bullet.startPosition.z + bullet.distance;
CalculateZDev(bullet);
CalculateYDev(bullet);
bullet.newPosition.x = 0.0f;
bullet.newPosition.y = bullet.startPosition.y + bullet.height;
bullet.newPosition.z = bullet.startPosition.z + bullet.distance;
//print("FlightTime:" + bullet.flightTime);
print(bullet.lastPosition);
if (Physics.Raycast(bullet.lastPosition, bullet.newPosition - bullet.lastPosition, Vector3.Distance(bullet.lastPosition,bullet.newPosition)))
{
print("Hit.");
}
Debug.DrawRay(transform.TransformPoint(bullet.lastPosition), transform.TransformDirection(bullet.newPosition - bullet.lastPosition), Color.green, 5.0f);
yield return new WaitForSeconds(0.1f);
}
}
What I'm trying to do is ensure that if the character turns, the bullet trajectory goes in the direction of transform.forward, instead of remaining in the world space z axis. However, as seen in the image, the ray is acting up. I have no clue as to why this is happening and have been trying to work on this single issue for hours.