Jump to content


Photo

Objects move from mouse cursor?


  • Please log in to reply
9 replies to this topic

#1 mollycarroll

mollycarroll

    GMC Member

  • New Member
  • 18 posts

Posted 19 July 2010 - 02:21 PM

Hello! I'm a newbie to Game Maker (I've only completed the tutorial so far. ^^;) and I'm in a spot of bother. I'm sure you guys can give me the answer I'm looking for!

I'm making a game that involves dots moving away from the mouse cursor, but I can't get it to work properly. I've gotten as far as making an object that follows the mouse. I tried setting a collision event with the cursor object, with the action 'step avoid.' (speed 3) But instead of the dots bouncing away from the cursor, they always strafe to the top right, no matter which angle you knock into them from. :blink:

How do I make the dots move away from the cursor relative to the side from which it is knocked against?


I hope I explained this clearly enough. ;P

Thanks in advance!
  • 0

#2 Saruwatari

Saruwatari

    GMC Member

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

Posted 19 July 2010 - 02:47 PM

Hello! I'm a newbie to Game Maker (I've only completed the tutorial so far. ^^;) and I'm in a spot of bother. I'm sure you guys can give me the answer I'm looking for!

I'm making a game that involves dots moving away from the mouse cursor, but I can't get it to work properly. I've gotten as far as making an object that follows the mouse. I tried setting a collision event with the cursor object, with the action 'step avoid.' (speed 3) But instead of the dots bouncing away from the cursor, they always strafe to the top right, no matter which angle you knock into them from. :blink:

How do I make the dots move away from the cursor relative to the side from which it is knocked against?


I hope I explained this clearly enough. ;P

Thanks in advance!

In D&D (drag'n'drop) it's in tab "Move" and called "Bounce". Use these settings: precisely, all objects. In GML (Game Maker Language) it's move_bounce_all(advanced);

Hope I helped
  • 0

#3 TerraFriedSheep

TerraFriedSheep

    GMC Member

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

Posted 19 July 2010 - 02:48 PM

You can do it using the step avoid action in the collision event. The direction you want the dots to move is effectivly the opposite to if they were moving towards the mouse object. So, in the dots collision event with the mouse object, put the step avoid action, and fill the entries with:

x:
other.x
y:
other.y
speed:
-3

This would move the dot towards the "other" object (which in this case is the mouse object), but because the speed is set to -3 it moves backwards, effectivly moving them away from the object.
  • 0

#4 MasterMind007

MasterMind007

    MasterMind Prod.

  • GMC Member
  • 543 posts

Posted 19 July 2010 - 02:50 PM

This code will make it that they reverse the direction when hit by the mouse:
Step Event:
if x=mouse_x && y=mouse_y
{direction-=180}

EDIT: Typo(I wrote 360 instead of 180)

Edited by MasterMind007, 19 July 2010 - 02:56 PM.

  • 0

#5 TerraFriedSheep

TerraFriedSheep

    GMC Member

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

Posted 19 July 2010 - 02:53 PM

This code will make it that they reverse the direction when hit by the mouse:
Step Event:

if x=mouse_x && y=mouse_y
{direction=direction-360}


Hehe, nope that would keep them going in the same direction. To reverse the direction you would need to take off 180.

Because it is when they are colliding with the object, checking if they are actually at the mouse's x and y coordinates would perhaps not create the effect needed. However, you can check if it is colliding in the step event, then reverse the direction. Of course this depends on the dots having speed in the first place.

if place_meeting(x,y,obj_mouse_object_name)
{
direction-=180;
}

  • 0

#6 MasterMind007

MasterMind007

    MasterMind Prod.

  • GMC Member
  • 543 posts

Posted 19 July 2010 - 02:55 PM

Sorry I made a mistake. I meant 180. And, by the way, the cursor has no object, unless you make it that an object follows the cursor.

Edited by MasterMind007, 19 July 2010 - 02:55 PM.

  • 0

#7 TerraFriedSheep

TerraFriedSheep

    GMC Member

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

Posted 19 July 2010 - 02:59 PM

And, by the way, the cursor has no object, unless you make it that an object follows the cursor.



I am aware of that ;) I was just relating it to the problem, as mollycarroll said in his original post:

I tried setting a collision event with the cursor object


  • 0

#8 Kaeru

Kaeru

    GMC Member

  • New Member
  • 675 posts

Posted 19 July 2010 - 04:04 PM

other.x, other.y, -3

cool idea, spares the call of point_direction(x, y, other.x, other.y)
  • 0

#9 MasterMind007

MasterMind007

    MasterMind Prod.

  • GMC Member
  • 543 posts

Posted 19 July 2010 - 06:02 PM

And, by the way, the cursor has no object, unless you make it that an object follows the cursor.

I am aware of that ;) I was just relating it to the problem, as mollycarroll said in his original post

I wasn't referring to you, I was referring to the original post.
  • 0

#10 mollycarroll

mollycarroll

    GMC Member

  • New Member
  • 18 posts

Posted 19 July 2010 - 11:13 PM

I took your advice Soulsnatcher and it works fine now. Thanks everyone!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users