Quantcast
Channel: Questions in topic: "rotating"
Viewing all articles
Browse latest Browse all 173

I want an arrow that aims at the player but it only works in 90°

$
0
0
Hi! I have an arrow that is suppose to aim at the player but it only works in 90°. For example if the player is above the arrow the arrow aims upwards and if the player is next and above the arrow the arrow still aims straight up. If I make it aim at the mouse it works perfect. Here is the source code. using UnityEngine; using System.Collections; public class arrowScript : MonoBehaviour { Vector3 mousePosition = new Vector3(0,0,0); Vector3 playerPosition = new Vector3(0,0,0); void Start () { //playerPosition = GameObject.Find("dude").transform.position; } // Update is called once per frame void Update () { mousePosition = Input.mousePosition; mousePosition = Camera.main.ScreenToWorldPoint(mousePosition); playerPosition = GameObject.Find("dude").transform.position; Quaternion rot = Quaternion.LookRotation(transform.position - GameObject.Find("dude").transform.position, Vector3.forward ); transform.rotation = rot; transform.eulerAngles = new Vector3(0, 0,transform.eulerAngles.z); } } Thanks for any help!

Viewing all articles
Browse latest Browse all 173

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>