Jump to content


Photo

Make Bullets Go To The Mouse Pointer


  • Please log in to reply
9 replies to this topic

#1 maneatingmoo

maneatingmoo

    GMC Member

  • New Member
  • 31 posts

Posted 03 January 2009 - 02:50 AM

I can't figure out how to make a bullet fly towards the mouse pointer when I left click. I also need to make an enemy walk towards the player, but I can't figure that out either. I searched around and tried a few codes, but I couldn't find any that worked.
  • 0

#2 Blackout3234

Blackout3234

    GMC Member

  • New Member
  • 382 posts

Posted 03 January 2009 - 02:53 AM

to make the bullet go towards the mouse use this in the bullet creation event

move_towards_point(mouse_x,mouse_y,10)

  • 0

#3 LedgendaryHero

LedgendaryHero

    GMC Member

  • New Member
  • 648 posts

Posted 03 January 2009 - 02:54 AM

try searching "move_towards_point" in the GM manual. And then also search mouse.
  • 0

#4 BattleRifle BR55

BattleRifle BR55

    Moo

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

Posted 03 January 2009 - 02:55 AM

How could you not? These questions been answered more times than I can count

Bullet

Create
direction=point_direction(player.x,player.y,mouse_x,mouse_y)
speed=5

Enemy

Step
move_towards_object(player.x,player.y,3)

  • 0

#5 maneatingmoo

maneatingmoo

    GMC Member

  • New Member
  • 31 posts

Posted 03 January 2009 - 10:13 PM

Awesome, it works, but there's a cool looking problem. If I hold the space button, a stream of tons of bullets fly towards the mouse. I think I have to set some alarm somewhere. Also, BattleRifle BR55, that code for the enemy caused a fatal error.

Edited by maneatingmoo, 03 January 2009 - 10:16 PM.

  • 0

#6 BattleRifle BR55

BattleRifle BR55

    Moo

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

Posted 03 January 2009 - 10:31 PM

My mistake, the code should be move_towards_point

To create bullets at a certain rate, you'll need to use alarms. (Well, not need, but they work great)

Create
can_shoot = 1;
Fire
if (can_shoot == 1)
{
	 can_shoot = 0;
	 //create bullet
	 alarm[0] = 10; //change to preference
}
Alarm[0]
can_shoot = 1;

  • 0

#7 maneatingmoo

maneatingmoo

    GMC Member

  • New Member
  • 31 posts

Posted 03 January 2009 - 10:36 PM

Thanks, but where do I put the code with Fire above it? Is there supposed to be two equal signs in the fire code?
  • 0

#8 BattleRifle BR55

BattleRifle BR55

    Moo

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

Posted 03 January 2009 - 10:43 PM

You put it wherever you create the bullets.

In GML there doesn't have to be two equal signs like other languages, but I like to put them there anyways.
  • 0

#9 maneatingmoo

maneatingmoo

    GMC Member

  • New Member
  • 31 posts

Posted 03 January 2009 - 11:32 PM

EDIT: Nevermind, I fixed it. But the code for the enemy only makes it move to where the player starts, then keeps going, instead of chasing him. How can I make the enemie(s) chase the player?

Edited by maneatingmoo, 04 January 2009 - 05:08 AM.

  • 0

#10 maneatingmoo

maneatingmoo

    GMC Member

  • New Member
  • 31 posts

Posted 05 January 2009 - 02:58 AM

Ok I got the enemies to chase the player. But I wanted to make bigger rooms, so I made the rooms bigger and set the view to follow the player. But now when I shoot, the bullet doesn't go towards the mouse. It flies towards the upper left corner of the room. I think it's trying to go to the mouse, because if I have the mouse pointer above the player, the bullet flies more upwards. If it's below him, it flies more downwards, but still towards the upper left corner of the room. The problem goes away when I make the room the original size.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users