• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

Legacy GM Flamethrower [Solved]

P

Purin

Guest
Hello, I'm trying to make my player shoot two streams of flame in the direction that the object is facing. My player sprite rotates with the mouse, but it has a fixed rotation speed. I am able to shoot flames from the right place and in the direction the mouse is pointing, but when my object rotates, i'm not sure how to rotate the creation location. In my code it currently shoots the flame to the mouse location, but my end goal is to have it shoot in the direction the player is facing.

In my player's step event, I have this:
Code:
///Rotate object in the direction of mouse

var mouse_angle = point_direction(x,y,mouse_x,mouse_y);
var rot_factor = 15; // speed of rotation
image_angle -= (sin(degtorad(image_angle - mouse_angle)) * rot_factor);
In my player's Glob Left Button event, I have this:
Code:
/// Shoot flame

//Left Side
fire = instance_create(x+32, y-16, ctrl_flamethrower);
fire.speed = 5;
variation = choose (-2, -1, 0, 1, 2)
fire.direction = point_direction(x, y, mouse_x, mouse_y) + variation;

//Right Side
fire = instance_create(x+32, y+16, ctrl_flamethrower);
fire.speed = 5;
variation = choose (-2, -1, 0, 1, 2)
fire.direction = point_direction(x, y, mouse_x, mouse_y) + variation;
Here is a picture of the player sprite's dimensions and origin, in case that helps to clarify anything:

P.S. No, I cant use particles because i'm planning on having some collision events with the flame in the future.
 

TripTrem

Member
Try playing with Length/Direction. Instead of using xy to create the object, you pick a direction and a length.

Something like

//Left
instance_create(x+lengthdir_x(32,direction-30), y+lengthdir_y(32,direction-30), ctrl_flamethrower)

//Right
instance_create(x+lengthdir_x(32,direction+30), y+lengthdir_y(32,direction+30), ctrl_flamethrower)
 
P

Purin

Guest
Try playing with Length/Direction. Instead of using xy to create the object, you pick a direction and a length.

Something like

//Left
instance_create(x+lengthdir_x(32,direction-30), y+lengthdir_y(32,direction-30), ctrl_flamethrower)

//Right
instance_create(x+lengthdir_x(32,direction+30), y+lengthdir_y(32,direction+30), ctrl_flamethrower)
I tried replacing my fire = instance_create(x+32, y-16, ctrl_flamethrower); with your instance_create(x+lengthdir_x(32,direction-30), y+lengthdir_y(32,direction-30), ctrl_flamethrower) and nothing changed. Am I supposed to set lengthdir_x and lengthdir_y somewhere else? I know that I dont need to be using a constant x and y values, but how can i make these values change based on the rotation of the sprite?

EDIT: by nothing has changed, i mean to say that the spot where the flames are created is still not rotating around with the image, and is staying in place.
 
Last edited by a moderator:
P

Purin

Guest
Try replacing direction+30 and direction-30 in the code with image_angle+30 and image_angle-30.
That's it! Its so simple now that I look at it. Thanks so much for your time and multiple posts.
 
P

Purin

Guest
Now the final portion to my posted question; have the direction that the flames shoot dependent on the facing direction of the sprite. Currently, the direction of the flame is aimed at the mouse.
Code:
variation = choose (-2, -1, 0, 1, 2)
fire.direction = point_direction(x, y, mouse_x, mouse_y) + variation;
Instead of using this ^, how do I use the sprite's facing direction for the flame's moving direction
 
Top