Jump to content


Photo

TDS shooter: enemies and shotgun problems!


  • Please log in to reply
6 replies to this topic

#1 killer24norway

killer24norway

    GMC Member

  • New Member
  • 62 posts
  • Version:GM8

Posted 12 November 2011 - 04:57 PM

Ok so I am making a new game (Top Down Shooter), called Zombies Attack and I have come up on 2 problems that has me stuck!

1. Problem: Enemies

So my enemies (I'm gonna call them zombies now) are trying to kill me. Here is the code:
move_towards_point(obj_player.x,obj_player.y,2)
image_angle=point_direction(x,y,obj_player.x,obj_player.y);

Simple code to make them follow me, and face my direction.
But if I have multiple zombies in the room and they follow me for some time, they "overlap". Hope u know what I mean.. So what should I do?? D:


2. Problem: Shotgun

Ok so the player has weapons to defend himself (obviously). I so far made a normal pistol, and a mini uzi. But when it comes to the shotgun I am stuck...
When the player left clicks, obj_bullet is created at obj_player.x,obj_player.y and in the create event of the bullet it has this code:
image_angle=point_direction(x,y,mouse_x,mouse_y)
move_towards_point(mouse_x,mouse_y,20)

For the shotgun I want 5,6 maybe 7 bullets to fire out, and each bullet in its own direction, if that makes sense... And remember this is a Top Down Shooter. Any help would be appreciated.   :thumbsup:
  • 0

#2 Timothyfoster

Timothyfoster

    GMC Member

  • GMC Member
  • 78 posts

Posted 12 November 2011 - 05:31 PM

a simple solution to your first problem is to use mp_potential_step like this:

mp_potential_step_object( player.x, player.y, 3, obj_zombie);

this will take steps towards the player and avoid instances of obj_zombie on the way there... you can change other options with the use of mp_potential_settings. However, this is a bit buggy so you might want to consider using one of the many A* dll's out there (espeically if you have other stuff in the way of the zombie and player)

to shoot multiple bullets say something like this:

in the mouse_left event that triggers the bullet being shot put

repeat(10)
{
   b = instance_create(x,y,obj_bullet);
   b.speed = 15 + random(4) - random( 4);
   b.direction = point_direction(x,y,mouse_x,mouse_y) + random( 25) -random( 25);
   b.image_angle = b.direction;
}

The use of all the randoms is just to make it look like it is spraying... you'll need to fiddle with these values to create the effect you want.
If you use this code then don't put the code you had above in the create event

Edited by Timothyfoster, 12 November 2011 - 05:36 PM.

  • 0

#3 killer24norway

killer24norway

    GMC Member

  • New Member
  • 62 posts
  • Version:GM8

Posted 12 November 2011 - 05:33 PM

Thank you! I will try this out :P Ill' let you know if it worked
  • 0

#4 killer24norway

killer24norway

    GMC Member

  • New Member
  • 62 posts
  • Version:GM8

Posted 12 November 2011 - 05:42 PM

Yay it worked! Thank you!
  • 0

#5 killer24norway

killer24norway

    GMC Member

  • New Member
  • 62 posts
  • Version:GM8

Posted 12 November 2011 - 05:43 PM

But how can I choose what the max and min speed of the bullet should be? :o
  • 0

#6 killer24norway

killer24norway

    GMC Member

  • New Member
  • 62 posts
  • Version:GM8

Posted 12 November 2011 - 05:44 PM

Oh nvm! :D
  • 0

#7 saibot22

saibot22

    GMC Member

  • New Member
  • 302 posts

Posted 13 November 2011 - 05:15 PM

First you edit a post second you can just make the zombies solid...
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users