• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GML Bullet positioning

K

Kaplutnoir

Guest
Hi, I'm a first time porogrammer, and I'm trying to learn GML. To learn this, I'm trying to program a very simple shooter based loosely on Asteroids. For a few days now, I've been struggling to find a good way to program how to keep a bullet coming out of the barrel of the gun. After some searching on the internet and through some forums, the best one I could find was this:

var inst = instance_create_layer((x + lengthdir_x(50, image_angle)), (y + lengthdir_y(50, image_angle)), "Instances", obj_Shot);
inst.direction = image_angle;


However, it seems I can only adjust the distance from the center point of the sprite, not the exact position at which the bullet is created. So, when I change the center point, I can get the bullet to spawn from the gun's barrel, but the character now has a funny rotation which I don't like at all. The character is holding the gun more to the right of his body, which means I have to adjust the center point to the right as well. I have been looking for code in which I can adjust the "height" of the bullet spawning. But I probably use incorrect wording or phrasing in my searches. Anyone who can help me would earn a lot of my thanks as I've always wanted to learn programming one day and it kinda sucks running into a wall so early in my programming days.
 

curato

Member
you need to do some trig to calculation the position of the barrel around the circle it is rotating. The center is the center of the ship and the radius would be the distance the barrel is from the center.
 
K

Kaplutnoir

Guest
you need to do some trig to calculation the position of the barrel around the circle it is rotating. The center is the center of the ship and the radius would be the distance the barrel is from the center.
Since I suck at math, I need to ask you to elaborate. For example, if the barrel of the gun is positioned at x: 50 y: 60, or, looking radius wise, is placed at 50 from the center and at let's say 300 degrees on the radius ,what formula should I use to make the bullet spawn there?

Thanks any way for the quick reply
 
Top