Pages: 1
Author Topic: Creating targeted cone fire for a shmup?  (27,636 Views)
Offline (Unknown gender) Topodic

Member
Joined: May 2014
Posts: 2
View profile
Posted on: May 12, 2014, 05:46:55 AM
Hey folks! I'm quite a rookie at all of this, so . :ohdear: (And apologies if this is in the wrong section, it seemed the most fitting even though this seems so trivial compared to some of the other topics!)

I want to know how to create a consistent cone-shaped fire pattern for something like a shmup.

For example:



I want it to be directed at the player, but I don't want the arc of the cone to change, regardless of the player's position.

I've tried fiddling around with the "move_towards_point" function, having it fire a little above or to the right/left of the player, and it works fine enough for a single stream (of course), but the left and right streams seem impossible to create using said function (or, well, not impossible, but very wonky). There must be a different, more effective way to do this that I can't seem to figure out.

Thanks in advance! :D
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #1 Posted on: May 12, 2014, 09:48:53 AM
You should use instances as bullets. Then assign "speed" to make them move and use "direction" to show their direction. Then when firing do:
Code (edl) Select
inst = instance_create(x,y,obj_bullet);
inst.direction = direction;

This would fire the bullet in the direction the ship is facing. Now to add new ones in a cone you would just do this:
Code (edl) Select
inst = instance_create(x,y,obj_bullet);
inst.direction = direction;
inst = instance_create(x,y,obj_bullet);
inst.direction = direction-30;
inst = instance_create(x,y,obj_bullet);
inst.direction = direction+30;
This would fire 3 bullets in a cone with +-30 degrees angle. This way you can make any pattern you want.
Offline (Unknown gender) Topodic

Member
Joined: May 2014
Posts: 2
View profile
Reply #2 Posted on: May 12, 2014, 05:24:05 PM
Had to also add a "point_direction" variable to the enemy to use for the "= direction" bit - works perfectly! Thank you for the help, it's much appreciated! :)
Offline (Unknown gender) TheExDeus

Developer
Joined: Apr 2008
Posts: 1,860
View profile
Reply #3 Posted on: May 12, 2014, 06:06:33 PM
I am glad you could figure it out from what I told you. Usually I have to provide examples for everything (and was about to do so here as well). :)
Pages: 1