Jump to content


Photo

Moving past mouse cursor for a top down game.


  • Please log in to reply
9 replies to this topic

#1 Monolisk

Monolisk

    GMC Member

  • GMC Member
  • 62 posts
  • Version:GM:Studio

Posted 25 April 2012 - 09:39 PM

hi, I am working on a top-down game and I need to have my player object not only move towards the mouse cursor but to continue in that direction when it meets the cursor! I have been looking all over the net for tutorials on how to do this and I haven't found one yet, hopefully someone can help me out?

using move_towards_point for accelerating but when my object meets the mouse it bounces around and trips out, I need it to smoothly continue in the direction it was going until the left button is released. (all have code for limiting speed and for stopping but, this really has me stumped)

Step Event:
if mouse_check_button(mb_left) and active=0 {
speed+=0.10;
move_towards_point(mouse_x,mouse_y,speed);}

Thanks!
-Monolisk
  • 0

#2 drt_t1gg3r

drt_t1gg3r

    GMC Member

  • GMC Member
  • 3230 posts
  • Version:Unknown

Posted 25 April 2012 - 10:30 PM

put this in the global mouse button left pressed event and NOT in the step event
if(  active == 0 ) {
  speed = min( speed + 0.10, maximumspeed ); // note I changed this a bit so you can have a maximum speed
  direction = point_direction( x, y, mouse_x, mouse_y );
}

EDIT: if you use the normal mouse button events, the event will only happen if you click the object directly and that's not what you really want is it? if it is actually what you want then change the event to the mouse button left pressed event

Edited by drt_t1gg3r, 25 April 2012 - 10:32 PM.

  • 1

#3 The2Banned2One

The2Banned2One

    BANNED

  • GMC Member
  • 225 posts
  • Version:GM:Studio

Posted 25 April 2012 - 10:30 PM

In your create event add:
mx = -1;
my = -1;

In your step event do:
if (mouse_check_button_pressed(mb_left))
{
	//Set Point to Move Towards
 	mx = mouse_x;
 	my = mouse_y;
}

if (mouse_check_button(mb_left) && active = 0 && mx >= 0 && my >= 0)
{
 	speed += 0.10; //Accelerate
 	move_towards_point(mx,my,speed); //Move Towards Point
}
else if (speed - .2 >= 0) speed -= .2; //Slow down when released

Edited by The2Banned2One, 25 April 2012 - 10:38 PM.

  • 1

#4 Monolisk

Monolisk

    GMC Member

  • GMC Member
  • 62 posts
  • Version:GM:Studio

Posted 26 April 2012 - 12:54 AM

hey guys thanks for the quick response, I tried both of those snippets but neither worked for what I am trying to accomplish tho =/

essentially heres what im going for in explicit detail.

I already have moving towards mouse point and a max speed and smooth acceleration/deceleration but what I really am trying to make happen is that my player object will accelerate towards the mouse then upon meeting the mouse will continue to move smoothly beyond that point without changing direction at all.

Im trying to make a game for touch screen mobile devices and it would work by moving towards the mouse (or finger eventually) but I realize that it could create some issues if they player object runs into the point where the finger is then it will glitch bounce around un-accurately. I want the object to continue through the mouse cursor in the same direction that it was moving so that when the player gets to the edge of the room (on a phone especially) it will move past the finger instead of stop onto it. This will help with me using the move_wrap() function on an outside room event without the player having to lift their finger and use the acceleration. it will just make it more noob friendly, but this little issue is having its way with me right now lol

I'm uploading screens and a pre-alpha release of the exe so u can play it and see what i mean. Also comments/suggestions are greatly appreciated, although i hadn't intended on showing it this way but u will see what i mean about the moving glitch

SCREENS:
http://imgur.com/a/Xi7sX/all#0

EXE:
http://www.mediafire...4ratb0z7s6bl8iw - NOTE: this is in a .zip file and its about 11 MB (SOUNDS AND MUSIC)

Thanks again, and hopefully this will clear up what i mean!


EDIT: Click and hold Anywhere on Screen to accellerate towards that point

Double Click to Dash Accellerate

Click yourself to charge (for a moment) Release to activate

Your activate will interact with various objects like enemies and mines, or player controllable turrets

Programming, Art, and Music By Joshua Wayne. MONOLISK STUDIOS

except a few sprites for suns found in an example (will give credit if used in final game)

GATHERING ALL STAR ORBS in each level will summon a portal which will bring u through each level.

FOR TESTING PURPOSES YOU CAN SKIP EACH LEVEL WITH SPACEBAR. (can't remember if it glitches after last room or now but oh well)

Edited by Monolisk, 26 April 2012 - 12:56 AM.

  • 0

#5 Monolisk

Monolisk

    GMC Member

  • GMC Member
  • 62 posts
  • Version:GM:Studio

Posted 29 April 2012 - 06:08 PM

*bump* please I still haven't figured this out. =/
  • 0

#6 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 29 April 2012 - 06:30 PM

make a variable,(eg active)
add a global left mouse button press event,
and at the global left mouse button press event make the variable go to 1.(eg active = 1)
at the step event put this code in there:
if(active = 1)
{
move_towards_point(mouse_x,mouse_y,4)
active = 0
}
HOPED I HELPED!Posted Image
  • 1

#7 111Studio

111Studio

    GMC Member

  • GMC Member
  • 258 posts
  • Version:GM:Studio

Posted 29 April 2012 - 06:36 PM

The issue with your current method is that you're updating the direction every step. You need to get the direction only at the initial command (in this case left mouse pressed).

Place this in the left mouse pressed event. Remove whatever code you have modifying the direction in the regular left mouse event or step event. Then just use this variable when you tell the object to move.
targetDir = point_direction(x,y,mouse_x,mouse_y);

You can't use the move_towards_point in this case. You have to manually use direction and speed. At least that'd be the easiest way to do it.
  • 1

#8 Monolisk

Monolisk

    GMC Member

  • GMC Member
  • 62 posts
  • Version:GM:Studio

Posted 30 April 2012 - 05:36 AM

thanks for the responses guys. Idk if u guys tried the game but it really requires updating every step to feel like the environment is real. its kind of an ambient style game and it needs that organic touch but these methods still didn't do what i was hoping to accomplish but they at least taught me something. oh well i think that id have to try something different with the move_wrap to allow someone to touch the edge of their phone screen and still exit the room boundary to call the move_wrap action cuz it is vital to the gameplay honestly. but thanks again for the help, it did help me figure out how to make the glitching stop so thanks for that little fix =]]]]

-Monolisk
  • 0

#9 creators124

creators124

    awesomeliciousmember

  • GMC Member
  • 866 posts
  • Version:GM8

Posted 30 April 2012 - 05:52 AM

As I look at the game I have no idea why you need the object go past the mouse?
do want the object to keep the speed it is going?
if the object meets the mouse then put this code:
if ( x = mouse_x)
     	{
     	motion_set(direction,speed);
     	}
if ( y = mouse_y)
     	{
     	motion_set(direction,speed);
     	}
or just make the speed lessen every time the mouse comes closer.

Edited by creators124, 30 April 2012 - 05:59 AM.

  • 1

#10 Monolisk

Monolisk

    GMC Member

  • GMC Member
  • 62 posts
  • Version:GM:Studio

Posted 30 April 2012 - 06:33 AM

I'll try to play wit that little snippet thanks!

the idea is so that on an actual cell phone, all types of players (including lazy ones that wont lift their finger) will still be able to warp from one side of a level to the other without having their player object stopping on the edge of the screen where their finger would stay rested. if that makes sense?

its hard to explain exactly what im talking about but basically i want the game to be able to be easily played even by complete idiots without them getting frustrated that their player object stops on their finger when they try to move_wrap. i dont know how to be more clear on that, but that snippet of code seems to be at least going for what im talkign about although its ina step event that my and direction is checked so I may have to rewrite soem stuff but if it makes for a more easily controllable game environment (for many different types of gamers, i.e. Casual, hardcore, etc...) then that's the whole idea. most of the game i have finished i just want to clean up alot of the roughness in it and actually finalize some graphics before i actually put out a decent alpha version and eventually final product
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users