In this video, Brackeys adds velocity to the homing missile. The value he passes is transform.up * velocity
but what if I want to calculate velocity on my own how would I do that.
I tried the following code
void FixedUpdate ()
{
Vector2 target = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 direction = target - GetComponent<Rigidbody2D>().position;
direction.Normalize();
float rotationAmount = Vector3.Cross(direction, transform.up).z;
GetComponent<Rigidbody2D>().angularVelocity = -rotationAmount * rotationVelocity;
//GetComponent<Rigidbody2D>().velocity = transform.up * velocity;
Vector2 initialPos = transform.position;
Vector2 finalPos = (transform.position + (transform.up)) * Time.deltaTime;
Vector2 targetPos = finalPos - initialPos / Time.deltaTime;
transform.Translate(targetPos);
}
But the gameObject moves too fast and results in this error.
transform.position assign attempt for 'New Sprite' is not valid. Input position is { NaN, NaN, NaN }.
UnityEngine.Transform:Translate(Vector3)
Rocket:FixedUpdate() (at Assets/Rocket.cs:33)
Please help me just trying to implement basic physics in Unity.
Also, I did check other questions but they did not help me I am still stuck.