Posted By
|
Message
|
Kokocipher
Registered 03/06/2008
Points 439
|
5th March, 2009 at 05:15:22 -
I'm making a topview space shooter and I wanted to use mouse for movements. However, the default mouse movement simply replaces the cursor with the player1 sprite. What I wanted to do is to turn the mouse cursor into a target, then have the sprite object following my cursor with limited speed. I was able to do it with setting the direction of that sprite object relative to the cursor, but when the sprite object's position is at the cursor, it becomes bouncy (glitchy). Does anyone out there know another way of doing such movement?
http://blog.kokoarcade.com
|
UrbanMonk BRING BACK MITCH
Registered 07/07/2008
Points 49667
|
5th March, 2009 at 05:45:20 -
hmm, i seem to be giving this formula out a lot, but I'll just make you an example.
http://www.jsoftgames.com/mousecontrolexample.zip
I'll just copy and paste my explanation of the formula from a previous post
-First we get the ships x position
x("Ship")
-Then add it to %40 of the distance between the mouse and Ship-
((xmouse-x("Ship"))*0.4)
-There is no need to get the absolute value here because if the numbers negative that means that the ship is ahead of the mouse in which case the number needs to be negative to move backwards towards the mouse.
n/a
|
W3R3W00F Drum and Bass Fueled Psycho
Registered 08/11/2008
Points 374
|
5th March, 2009 at 05:48:52 -
Really simple; try the "Move it" object. The code would be:
•Always
-Add objects ("Target") to queue
-Move objects to target X("mouse"), Y("Mouse") with speed <desired speed>
An old and washed up once-kid
|
Kokocipher
Registered 03/06/2008
Points 439
|
6th March, 2009 at 03:53:42 -
Originally Posted by UrbanMonkhmm, i seem to be giving this formula out a lot, but I'll just make you an example.
http://www.jsoftgames.com/mousecontrolexample.zip
I'll just copy and paste my explanation of the formula from a previous post
-First we get the ships x position
x("Ship")
-Then add it to %40 of the distance between the mouse and Ship-
((xmouse-x("Ship"))*0.4)
-There is no need to get the absolute value here because if the numbers negative that means that the ship is ahead of the mouse in which case the number needs to be negative to move backwards towards the mouse.
Wow that's some hardcore math formula :0
http://blog.kokoarcade.com
|
Peblo Custom ratings must be 50 characters or less
Registered 05/07/2002
Points 185
|
6th March, 2009 at 06:42:28 -
If you use the bouncing ball movement, then you can set the speed to the distance of the two objects for smooth lag.
"Isn't it always amazing how we characterize a person's intelligence by how closely their thinking matches ours?"
~Belgarath
|
UrbanMonk BRING BACK MITCH
Registered 07/07/2008
Points 49667
|
6th March, 2009 at 14:16:55 -
Hey I never thought of that peblo, thanks for the tip. You still have to know the distance formula though, unless you use the advanced direction object.
n/a
|
|
|