GML Visual Bullet issue Top Down Shooter

N

newbs

Guest
Hello,

I'm a fresh beginner on Game Maker 2 and I try to do some Top Down Shooter with drag and drop system.

I have an issue with my bullet.

I want to shoot my bullet from my gun who is in a position x=30 y=30 from middle center of my player sprite.
My player rotate from the position of my mouse. All is working but the bullet is not coming from my gun sprite, is not rotating with my object player.

Here a video to illustrate my problem, and 2 screenshot of my code.

Thank you for your help





 

Alexx

Member
change the values in creer une instance to:
Code:
x+lengthdir_x(30,direction)
and
Code:
y+lengthdir_y(30,direction)
Let me know how that works out.
 
N

newbs

Guest
Thanks for your help,
but still not working :(

if I change the number (30 to anything else) to try to align to the gun is not working

here the video of the result with your's parameter :

 

Alexx

Member
Try changing this:
x+lengthdir_x(30,direction)

to something like
x+lengthdir_x(60,direction)
or
x+lengthdir_x(0,direction)

Your settings will depend on where the origin of your player sprite is, which I guess if around the center.

edit: I won't be anymore help today, my license just expired. Perhaps someone else can step in?
 
Last edited:
N

newbs

Guest
I tried to change the value, but is not working, or i can make it work.

Still not working with x+lengthdir_x(60,direction) and we have a new issue :
As you can see on the video the point from where the bullet spawn si "moving"

Here the results with :
x+lengthdir_x(60,direction)
y+lengthdir_y(30,direction)


here is my sprite if it can help you :

 
A

Andy

Guest
Calling the lengthdir functions once is more optimized, so I recreated the example. It now has better code comments as well.

You could do something like this:
Code:
// Create bullet
var _dir = (image_angle+315) mod 360; // Direction from player to gun
var _dis = 44; // Distance from player to gun
var _x = x+lengthdir_x(_dis, _dir); // Gun x
var _y = y+lengthdir_y(_dis, _dir); // Gun y
with (instance_create_depth(_x, _y, depth, obj_bullet)) // Create bullet instance at gun position
{
    direction = other.image_angle; // Set bullet direction
    speed = 10; // Set bullet speed
    
    image_angle = direction; // Set bullet image angle
}
I don’t know how to use drag and drop, but here is a working example in GML:
http://www.filedropper.com/bullethelpgmcv2
 
Last edited by a moderator:
N

newbs

Guest
Thank you for your time and for your help !

I don't know if it's working but i'm restarting all from scratch and I'm learning GML. It will be easier for future to know the code rather than drag and drop.
It's a long way but will be worth it I guess.

I'll keep your solution in mind for next time, very appréciated it !
 
A

Andy

Guest
I remade the example (see my edit above) since the first version was not optimized. For a better explanation of what the lengthdir functions are doing check out this video:

Learning GML is a good idea, it takes time but is well worth the effort. :)
 
Top