I would like to move several cubes with the mouse at the same time.
I use the following code (all cubes are children of one parent cube):
if (Input.GetMouseButton(0) && movingObject)
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
float rayDistance;
if (plane.Raycast(ray, out rayDistance))
{
[B]cubeRouge.transform.Translate(Vector3.right * Input.GetAxis("Mouse X") * Time.deltaTime*10);
cubeRouge.transform.Translate(Vector3.forward * Input.GetAxis("Mouse Y") * Time.deltaTime*10);[/B]
}
}
The problem is that when I move the cubes with the mouse, the cursor gets detached from the cubes.
The video speaks for itself (just look at the cursor).
https://www.transfernow.net/fMahyH032021
Thanks for your help.
I’m not downloading a 70mb strange video file. Have you considered Youtube?
Also, to help you track down what’s happening and in order to help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.
Doing this should help you answer these types of questions:
- is this code even running? which parts are running? how often does it run?
- what are the values of the variables involved? Are they initialized?
Knowing this information will help you reason about the behavior you are seeing.
2 Likes
Not downloading the video, but in your code you move the cube in the direction of the mouse movement that frame X 10. That seems like a pretty arbitrary number. Also, Input.GetAxis already takes into account frame times for mouse movements, so you’re applying frame time effectively twice to the movement.
Salut,
Voici la vidéo elle est plus parlante (youtube)
,
Le code est le suivant :
transform.Translate(Vector3.right) * (Input.GetAxis("Mouse X"));
transform.Translate(Vector3.forward) * (Input.GetAxis("Mouse Y"));
Il suffit de regarder le curseur de la souris pour voire le décrochage.
Merci pour votre aide
FYI, setting a YouTube video to “private” means no one can watch it.