The Daily Click ::. Forums ::. Klik Coding Help ::. Change speed according to mouse movement speed?
 

Post Reply  Post Oekaki 
 

Posted By Message

Mr G



Registered
  31/12/2008
Points
  178

VIP MemberPS3 OwnerI like Aliens!Attention GetterDos Rules!
18th May, 2009 at 09:49:02 -

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.

Can anyone tell me a formula to do that?

 
Image

http://create-games.com/project.asp?id=1549

nim



Registered
  17/05/2002
Points
  7216
18th May, 2009 at 15:04:05 -

It sounds like a simple thing, but something like that will take a lot of work. You might want to check out extensions (Move Safely, maybe?) to help.

 
//

OMC

What a goofball

Registered
  21/05/2007
Points
  3307

KlikCast Musician! Guy with a HatSomewhat CrazyARGH SignLikes TDCHas Donated, Thank You!Retired Admin
18th May, 2009 at 15:19:06 -

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.

Or was that the question? O_o

Edited by OMC

 

  		
  		

Mr G



Registered
  31/12/2008
Points
  178

VIP MemberPS3 OwnerI like Aliens!Attention GetterDos Rules!
18th May, 2009 at 18:47:31 -

@nim: Which extensions does the thing I want actually?
@OMC: I don't really get what you said :S

 
Image

http://create-games.com/project.asp?id=1549

Spitznagl

Cabinetmaker

Registered
  06/12/2008
Points
  4260

The SpinsterVIP MemberHas Donated, Thank You!Picture Me This Round 29 Winner!Picture Me This Round 31 Winner!Picture Me This Round 36 Winner!
18th May, 2009 at 20:35:54 -

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.

 
...

Codemonkey

Always Serious

Registered
  06/11/2007
Points
  164

Code MonkeyKlikCast StarVIP MemberAttention GetterWii Owner360 OwnerThe Cake is a LieCardboard BoxHero of TimeI'm a Storm Trooper
I'm on a BoatIt's-a me, Mario!PS3 OwnerSonic SpeedGOTM - SEPTEMBER 2009 - WINNER!Evil klikerPokemon Ball!I am an April Fool
18th May, 2009 at 20:58:03 -

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.

 
You can log off any time you like, but you can't ever leave.

Spitznagl

Cabinetmaker

Registered
  06/12/2008
Points
  4260

The SpinsterVIP MemberHas Donated, Thank You!Picture Me This Round 29 Winner!Picture Me This Round 31 Winner!Picture Me This Round 36 Winner!
18th May, 2009 at 22:32:31 -


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.



Wouldn't you still need to find the direction?

 
...

Muz



Registered
  14/02/2002
Points
  6499

VIP MemberI'm on a BoatI am an April FoolHonored Admin Alumnus
19th May, 2009 at 11:20:20 -

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.

Image

nim



Registered
  17/05/2002
Points
  7216
19th May, 2009 at 11:27:21 -


Originally Posted by Muz
Just





 
//

nim



Registered
  17/05/2002
Points
  7216
19th May, 2009 at 11:33:13 -

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.

 
//
   

Post Reply



 



Advertisement

Worth A Click