I have a script to instantiate a knife for the player to throw. Right now, when I push the key, the knife just falls from the middle of the screen straight down. I need the knife to appear in front of the character and launch forward from whatever direction he is facing. How can I do this? (PS: I’m using C#) Thanks ahead of time.
My code:
void Update () {
if (Input.GetKeyDown ("f")) {
GameObject myKunaiInstance =
Instantiate (Resources.Load ("Kunai"),
direction = (target.position - transform.position).normalized
new Vector3 (1, 1, 1),
Quaternion.identity) as GameObject;
}
Edit: I’ve been able to control the position with transform.TransformPoint(Vector3.forward * 20)
but it doesn’t face the same direction of the player (it’s always facing right), and I still don’t know how to change the velocity to make it lung forward.