Pepis
December 16, 2012, 11:44pm
1
My problem is that even if I am staring at the target directly, the missiles decide to take a longer/large round path.
RigidBody component was removed
Missile homing code:
transform.rotation = Quaternion.Slerp (transform.rotation,
Quaternion.LookRotation(enemy.position - transform.position), speedRotation* Time.deltaTime);
transform.Translate(Vector3.forward* speed);
Code to launch missile:
if(Input.GetButtonDown("Fire2"))
{
Instantiate(Missile,transform.position,transform.rotation);
}
Have you tried increasing your speedRotation?
BFGames
December 17, 2012, 12:38am
4
The problem is that if your interpolation is not fast enough it will not rotate directly towards it. So as overlord says if your speedRotation is fast enough it should not “bend” as much in its movement pattern but still some;
You can see this if you implement it to look at it instantly like this:
transform.rotation = Quaternion.LookRotation(enemy.position - transform.position);
BFGames
December 17, 2012, 12:42am
5
If you want to keep the smooth rotation by using slerp you can move it towards the enemy in another way like:
transform.rotation = Quaternion.Slerp (transform.rotation, Quaternion.LookRotation(enemy.position - transform.position), speedRotation* Time.deltaTime);
Vector3 direction = (enemy.position - transform.position).normalized;
transform.position = Vector3.MoveTowards(transform.positions, transform.position + direction, Time.deltaTime * speed);
Or instead of creating the direction vector just use the enemy.position.