Hi there, I’m new to unity and am making a top down shooter. I have a cube I can move with WASD and it faces the cursor when I move it. I’m having an issue with my projectile, however. I want it to shoot toward the mouse cursor, and it does, however it then follows the cursor, which is not ideal. I’d like the shot to fly toward the initial point where i clicked.
here is my code, I feel like I’m close.
using UnityEngine;
using System.Collections;
namespace Mechanics{
public class Move : MonoBehaviour {
public float thrust;
public Rigidbody2D rb;
void start ()
{
rb = GetComponent<Rigidbody2D> ();
}
void Update(){
Vector3 shootDirection;
shootDirection = Input.mousePosition;
shootDirection.z = 0.0f;
shootDirection = Camera.main.ScreenToWorldPoint(shootDirection);
shootDirection = shootDirection-transform.position;
rb.velocity = new Vector2 (shootDirection.x * thrust, shootDirection.y * thrust);
}
}
}