|
Okay my math is a bit fuzzy. I have an object at a position;
And I can get the current rotation to hold for later as I when my mouse is up I want to find the final rotation based on where it was from when the mouse was first put down.
When my mouse button goes down I can shoot a ray to verify I am on the object, then get a world position of where the mouse went down
Now, as the mouse moves I can get the current mouse position
It seems to me, now I have a triangle in 3 space from MouseBegin to the center of the object and back out to the place I want that first mouse position to be at. This is where my mind goes blank and turns to mush. I should be able to say "Now calculating the angle in three space we want to move the object
We can now rotate the object
I should be able to figure out a way to rotate my object based on the angle from the MouseBegin to MousePos--and move it in real time giving the affect that I am actually dragging the real object--giving he affect of spinning it in place using the mouse. Now for extra credit, I would think it would be possible to flick an object forward and end up giving it some momentum. I notice a lot of people asking similar questions but not getting responses that answer it. I think my logic is pretty sound how it should be calculated--however my math is so limited that I can't take it the last bit. Hopefully my logic will help someone easily come up with a solution!
(comments are locked)
|
|
Thanks for your help, Brian, you got me on the right track. I ended up creating a script that I think could be helpful for everyone who asked a similar question as I did on the forum or here. Just add this to the object you want to rotate and tell it what camera you are using and the distance you want the rays to go. I am actually a cleaner version of this that slerps the rotation and actually just projects the mouse touch in front of the object so it is smoother as your mouse goes off of it but this was the easiest way to show the example. It boils down to this:
For me, the key was Euler math couldn't be easier. Then, once the difference is calculated (with simple subtraction) rotate the object just that little bit. It works! Please let me know your experiences! Best, Thom
using System.Collections; public class SimpleRotate : MonoBehaviour {
} hmm... something is wrong with the code parser. Please try to edit the code blocks so it shows as one block of code
Feb 02 '10 at 02:08 PM
Nicolaj Schweitz ♦♦
(comments are locked)
|
|
For what you describe, you could use:
You may have to play with the mouse position a little bit to figure out how much you really wanted to move the object. I'm not sure which plane you should be operating on. EDIT: I think you probably want to raycast at the object, figure out what point you clicked on, and use that as your point to follow the mouse. This is going to be a bit tricky - I'll try to get some code working down below. For momentum, you just need speed of mouse movement at release, here is a basic way to get that, you probably want something smoother.
Here is how to get the point on the object you clicked on:
Here is a somewhat fidgety implementation of what you want:
To avoid the glitchiness, you can either use a different solution, perhaps faking it, or figuring out mouse position on a plane at the original distance. Or, you could compare RaycastHit.triangleIndex to see if you are still mousing over the same triangle. Brian, Thank you. It's getting closer. The only problem I have is that the object snaps to the look at position the first time it is touched then tracks beautifully. I really need to track it from whatever rotation it is currently at and then give the same behavior so it gives the appearance of just grabbing it and spinning it around then letting up and it stays in the same place.
Jan 28 '10 at 05:39 AM
thom
You can set an offset between the original vector and the onclick vector, and continually add (or subtract?) that.
Jan 28 '10 at 02:46 PM
Brian Kehrer
(comments are locked)
|
