projectile system help (SOLVED)

N

Nyool

Guest
Hello, game maker community I am hoping someone here could help me figure this out. I have been following heartbeast free RPG series on youtube and I'm using the projectile system used in this video:

I want to make it so my projectiles shoot towards my mouse location and maybe make the range of the projectile shot end where the location of the mouse was at the moment of the shot.

I don't want my player sprite following the mouse like in a top down shooter but instead, I'd like my player sprite to be facing within one of the four direction it already has. So my player sprite would simply be in its spr_player_up when shooting projectiles upwards of the obj_player and then transition to the right sprite whenever the mouse shoots in the angle range whom be considered towards the right, etc.

I don't know if this is asking too much and if I'm complicating things.. Basically, I just don't want it to look dumb if he's shooting somewhere left be looking left..

Thank you in advance to anybody that would take some of their time to help me.
 

TesloStep

Member
I want to make it so my projectiles shoot towards my mouse location
at the 11:40 of the tutorial thre is that things:
Code:
var xforce = lengthdir_x(20, face*90)
var yforce = lengthdir_y(20, face*90)
to do what you want just replace it that way:

Code:
var xforce = lengthdir_x(20, point_direction(x,y,mouse_x,mouse_y))
var yforce = lengthdir_y(20,point_direction(x,y,mouse_x,mouse_y))
and maybe make the range of the projectile shot end where the location of the mouse was at the moment of the shot
you need to calculate distance to mouse(use point_distance(x,y,mouse_x,mouse_y)) and then divide it by speed of the bullet. then start alarm in bullet of that amout, that destroy bullet at the end.

So my player sprite would simply be in its spr_player_up when shooting projectiles upwards of the obj_player and then transition to the right sprite whenever the mouse shoots in the angle range whom be considered towards the right, etc.
That might work:
Code:
var sprite_num = round((point_direction(x,y,mouse_x,mouse_y)-45.1)/90)
//0 - right, 1 top, 2 left, 3 - right
more long way, but more stable/ease is to use
Code:
var angl = point_direction(x,y,mouse_x,mouse_y);
if angl>315
sprite=spr_right
else
if angle >225
sprite=spr_down
else
if angle >135
sprite=spr_right
else
if angle >45
sprite=spr_up
else
sprite=spr_right
Basically, I just don't want it to look dumb if he's shooting somewhere left be looking left
dont understand that

I don't know if this is asking too much and if I'm complicating things..
Basically, all that things are "newbie level" and there is probably tutorials for them too.
 

zircher

Member
TesloStep knocked it out of the park. The one thing I would add is that if you have a lot a bullets then the alarm thing might not work out (there are a limited number of alarms.) You can use roughly the same logic and set up a frame counter for each bullet and decrease it by one in the step event. When it hits zero, destroy the bullet, spawn explosions, etc. if it has not already hit something before hand.
 
Top