I need to make it so that if the player moves the object that is related to the mouse at varying speed and hits another object with that speed the clashed object should ricochet. But the effect and the speed of the ricochet should vary on how fast the mouse-active hits that object.
One way you could do it is set the object's speed to the distance from the mouse, divided by whatever value makes it reasonable. Probably a better way would be to track the mouse's X and Y speed with two counters that update with the difference between its last value and the new value--that'll give you a speed.
XMouse & YMouse are under the keyboard and mouse icon in the event editor.
XKnockSpeed, YKnockSpeed, LastX, LastY, ObjectXSpeed & ObjectYSpeed are alterables values:
+Always
set XKnockSpeed to: XMouse-LastX
+set YKnockSpeed to: YMouse-LastY
+set LastX to: XMouse
+set LastY to: YMouse
Mouse-Active collides with objects
+Set ObjectXSpeed to: XKnockSpeed
+Set ObjectYSpeed to: YKnockSpeed
Then move the objects according to their X and Y Speed values.
Originally Posted by Tasteful Codemonkey If you are a lazy bum coder like me, you can use the "mouse" extension, it has a "distance rolled" thing that gives you the speed of the mouse.
Just set the speed to the derivative of the mouse position vs time Does MMF handle derivatives?
Failing that, make a custom one.. take a window of time.. like, say, in the past 0.05 seconds, then get the distance rolled within that period, and reset and take a new value every 0.05 seconds.
Then speed = (distance in past 0.05 seconds)*X
Set X to any number you like.
Disclaimer: Any sarcasm in my posts will not be mentioned as that would ruin the purpose. It is assumed that the reader is intelligent enough to tell the difference between what is sarcasm and what is not.
Mr Green, I don't know what extensions would be best to use. The Move Safely object moves an object from A to B while checking the steps in between. I think you should be prepared for a lot of wrestling with MMF just to get this to work. Even once you've got the mouse following code sorted, you'll have to apply some physics to work out the collisions.