Camera rotation with mouse cursor
Hello ,
I begin in Unity and i would like to do a Minigolf game , but , i have a problem when i want to rotate the ball in the direction of the mouse ( I watched this tutorial https://unity3d.com/learn/tutorials/projects/survival-shooter/player-character?playlist=17144 , but nothing work )
Here my script :
using UnityEngine;
public class Mouvement : MonoBehaviour {
 int  solmask ; 
 float rayonCameraLength = 100f ; //distance scene - camera 
 Rigidbody JoueurBody ; 
 void Awake()
 {
     solmask = LayerMask.GetMask ("Sol");
     JoueurBody = GetComponent<Rigidbody> (); 
 }    
 // Update is called once per frame
 void FixedUpdate ()
 {
     Rotation ();
 }
 void Update ()
 {
     Debug.Log (Input.mousePosition);
 }
 void Rotation()
 {
     Ray rayonCamera = Camera.main.ScreenPointToRay (Input.mousePosition); // on crée un rayon a partir de la caméra on va chercher le point produit par la souris si elle touche le sol 
     RaycastHit Touche_sol ; // ce que touche le rayon 
     if (Physics.Raycast( rayonCamera ,  out Touche_sol , rayonCameraLength  , solmask)) // (origine , direction , distance max ,le layer mask qui ignore les collisions quand on produit un rayon ) 
     {
         Vector3 JoueurCamera = Touche_sol.point - transform.position; //disance du pt d'impact au sol au joueur 
         JoueurCamera.y = 0f; // jamais de valeur en Y 
         Quaternion Rotation = Quaternion.LookRotation (JoueurCamera); // rotation basée sur vecteur joueur /souris 
         JoueurBody.MoveRotation (Rotation); 
     }
 }
}
So , when my mouse touch the ground , i want that the ball rotate to the mouse's direction.
PS : I'm french so , Sol = Ground , Joueur = Player , Ray = rayon
Good day.
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
               
 
			 
                