getting mouse speed and direction and applying it to an object as velocity
by Ryan Batten · in Torque Game Builder · 08/13/2009 (1:17 pm) · 6 replies
Let me explain what I'm trying to do, first.
I have an object in my game that can be dragged around by the mouse. Ideally, when I let go of the object (onMouseUp) the item is released and moves in the direction the mouse was moving and at a speed relative to house fast the mouse was moving when the player "let go". Sort of like throwing the object with your mouse.
Does anyone have any idea as to how I would go about this?
I have an object in my game that can be dragged around by the mouse. Ideally, when I let go of the object (onMouseUp) the item is released and moves in the direction the mouse was moving and at a speed relative to house fast the mouse was moving when the player "let go". Sort of like throwing the object with your mouse.
Does anyone have any idea as to how I would go about this?
About the author
#2
I've been searching and browsing the forum, haven't seen anything all that similar yet.
08/13/2009 (1:27 pm)
If anyone could point me in its direction I'd be very appreciative. :)I've been searching and browsing the forum, haven't seen anything all that similar yet.
#3
I believe one of the ways to do it is to take the position and time of the object when it is selected and then again when it is released and you can calculate a velocity vector. If you want a velocity closer to when the object is released you could set a short period timer to calculate the velocity periodically.
08/14/2009 (5:59 am)
GG search strikes again. I didn't have much time to post yesterday and was hoping that thread would be easy to find but I'm not having any luck with a brief search either...I believe one of the ways to do it is to take the position and time of the object when it is selected and then again when it is released and you can calculate a velocity vector. If you want a velocity closer to when the object is released you could set a short period timer to calculate the velocity periodically.
#4
08/14/2009 (6:37 am)
thats almost like what i said on the other thread last week... look on the threads that are on the 2nd or 3rd page,you might find it easily.
#5
Store the mouse position (and perhaps system time) on mouse down, then again on mouse up. Use those stored values to calculate the velocity vector (Pythagorean theorem of two points over difference in system time); apply that as an impulse to the selected object. Then decelerate the object if you need to stop it.
Not sure how smooth it will turn out though.
Hopefully you share it when you're done, it would make a great resource.
`Patrick
08/14/2009 (6:50 am)
My thoughts are essentially to go with what Drethon recommended:Store the mouse position (and perhaps system time) on mouse down, then again on mouse up. Use those stored values to calculate the velocity vector (Pythagorean theorem of two points over difference in system time); apply that as an impulse to the selected object. Then decelerate the object if you need to stop it.
Not sure how smooth it will turn out though.
Hopefully you share it when you're done, it would make a great resource.
`Patrick
#6
08/14/2009 (8:07 am)
Thanks guys, I'll see if I can try that out. I'll let you know what comes of it!
Torque 3D Owner Drethon
Default Studio Name