Question by
Gabrieldonley · Dec 20, 2015 at 03:19 PM ·
movement script
Creating projectile prefab that points at the mouse
I was wondering what my next step in create the quaternion.lookrotation to follow the mouse would be? I've been working on getting it to rotate but I haven't had much success. If it helps at all, here is my code so far: public GameObject projectilePrefab; public Transform target;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown (0)) {
GameObject click = GameObject.Instantiate (projectilePrefab) as GameObject;
click.transform.position = transform.position;
Camera camera = Camera.main;
Vector3 p = camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, camera.nearClipPlane));
Vector3 relativePos = target.position - transform.position;
Quaternion rotation = Quaternion.LookRotation(relativePos);
transform.rotation = rotation;
}
}
Comment
Your answer
Follow this Question
Related Questions
Isometric movement for MoveTowards 0 Answers
Input System: How to declare interaction types to compare to callback context? 0 Answers
(2D) My Character wont stop moving/sliding when I let go of the button 1 Answer
Need to make the both of the light work as a line of sight 0 Answers
2D Board Game Movement Script Results in Empty Calculations 0 Answers