Hello, I am new to unity, c# and js.
I am trying to make a proof of concept for work. I have a 3d model which is set to rotate when the program starts.
I need the model to stop rotating when the mouse is over the object and switch to manual camera controls so i can rotate it with my right mouse button. Can someone please help me as i have no clue what im doing right now and i need this for Tuesday. It doesn’t have to look good i just need this to work.
Any help appreciated.
If you need a model display system in Unity right away, you might do well with picking up the $5 3D Model Viewer on the Asset Store. I am not affiliated with that asset. I use it to create scenes where I can display the various models I own and their animations in order to help me keep track of what is in my collection. If all you’re going for is a proof of concept demo, $5 might save you a bunch of time.
To code it yourself, here is the basic logic:
- Make a raycast from the camera based
on the mouse position to see if you
hit the model. (The Survival Shooter
tutorial in the Unity Learn section
uses this method for movement.)
- Once you hit the model, turn the rotation
off and set a bool value so you know
it’s off.
- If you stop hitting the
model, turn the rotation back on,
unless the right mouse button is
current pressed. (Because button
down means you’re moving the model
manually.)
Once the flag for rotation off is true, do the following:
-
If the right mouse button is pressed,
turn the model appropriately based on
mouse movement.
-
When the right mouse
button is released, the logic in the
section above will turn the rotation
back on automatically if the mouse is
no longer over the model.
You may want to put each model in a capsule or other simple collider that surrounds the whole model and use that instead of a mesh collider on the model. Not only is it a faster collider to process, but you won’t have issues with the model rotation stopping and starting because the mouse is just over the edge of a finger or something.