Question by
$$anonymous$$ · Apr 03, 2017 at 04:26 PM ·
raycastfpsshootingrotate object
how can i set the direction of my gun to the Raycast collision point?
I have created a Raycast that starts from my camera and points foward, now I need that the object "Gun" is oriented to the Raycast's collision point.
for now i made this....
Ray FowardRay = new Ray(Head.transform.position, Head.transform.forward);
RaycastHit Hit;
if (Physics.Raycast(FowardRay, out Hit))
{
Debug.Log(Hit.collider.name);
Debug.Log(Hit.point);
Vector3 Point = Hit.transform.position;
Vector3 gun = Gun.transform.position;
Vector3 Direction = (Gun.transform.position - Hit.transform.position).normalized;
Ray r2 = new Ray(transform.position, Direction);
Gun.transform.eulerAngles = r2.direction;
}
Comment
Best Answer
Answer by VeeooshL · Apr 03, 2017 at 07:05 PM
Would Gun.transform.LookAt(Hit);
not work?
Your answer
Follow this Question
Related Questions
Raycast Weapon not cause damage 1 Answer
Disable Damage Raycast? 1 Answer
FPS Raycasting vs Instantiate 0 Answers
Shoot projectile towards the end of a raycast? 0 Answers
Range not working c# - shooting script using raycast 0 Answers