
#pragma strict
var isQ : boolean;
var arrow : GameObject;
function Start () {
}
function Update () {
if(Input.GetKeyDown(KeyCode.Q)){
isQ = true;
arrow.SetActive(true);
}
if(isQ){
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var hit : RaycastHit;
if(Physics.Raycast(ray,hit)){
var arrowPos = Vector3(hit.point.x,0,hit.point.z);
arrow.transform.position = arrowPos;
var tR = Quaternion.LookRotation(transform.position - arrow.transform.position);
}
}
}
I’ve no Idea where to start… Can someone help me? 
1 Answer
1
Someone on #unity3d IRC helped me, here’s the code in case someone needs it 
public Transform Target;
public float RotationSpeed;
private Quaternion _lookRotation;
private Vector3 _direction;
void Update()
{
//find the vector pointing from our position to the target
_direction = (Target.position - transform.position).normalized;
//create the rotation we need to be in to look at the target
_lookRotation = Quaternion.LookRotation(_direction);
//rotate us over time according to speed until we are in the required rotation
transform.rotation = Quaternion.Slerp(transform.rotation, _lookRotation, Time.deltaTime * RotationSpeed);
}
If this script is connected to the ball, then you are 99 percent of the way there. I think all you need to do is is add this below line 20:: arrow.transform.rotation = tR; In some ways this is a bit backwards from how folks usually solve this problem. Usually they would add the script to the arrow and use Trasnform.LookAt(). Note you may have to adjust your look position so that the 'Y' value matches the arrow.
– robertbuThanks for your comment :) however someone on IRC helped me :)
– skoandi