• 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!

Help with coding an aiming system

N

Niche Quiche

Guest
In some games there is an aiming system consisting of a dotted line and an icon where a given projectile would land (most common in tank or golf games). The dotted line is my focus here, though. When aiming a projectile, I want to have a set number of dots in the line that compact as the shot's range gets shorter, and space out as the range gets longer. For example:
Player-.-.-.-.-.-.-.-.-.- X
Player- . - . - . - . - . - . - . - . - . - . X
Both lines have 10 dashes (don't mind the dots), but one goes farther than the other. The dashes are all equally spaced out regardless of the distance or angle, and there is a set amount of dashes.
My question is: how would I go about coding this if I am using a mouse to control where the shot goes?
 
N

Niche Quiche

Guest
It isn't quite what I was after, but as you said, it is a start. Thanks for the help.
 

Dan1

Member
Hey,

I don't know if you're still looking for a solution but I've figured out something similar,
basically, the code I've done here displays a series of 1-5 dots depending on if your mouse is between 50 and 250 pixels away from the original point - this works if you intent to make a small dotted line out of sprites and can be modified depending on how you want to use it

Code:
if point_distance(point1x,point1y,mouse_x,mouse_y) > 50 then draw_sprite(sp_Dot,0,point1x+lengthdir_x(25,point_direction(point1x,point1y,mouse_x,mouse_y)),point1y+lengthdir_y(25,point_direction(point1x,point1y,mouse_x,mouse_y)))
if point_distance(point1x,point1y,mouse_x,mouse_y) > 100 then draw_sprite(sp_Dot,0,point1x+lengthdir_x(75,point_direction(point1x,point1y,mouse_x,mouse_y)),point1y+lengthdir_y(75,point_direction(point1x,point1y,mouse_x,mouse_y)))
if point_distance(point1x,point1y,mouse_x,mouse_y) > 150 then draw_sprite(sp_Dot,0,point1x+lengthdir_x(125,point_direction(point1x,point1y,mouse_x,mouse_y)),point1y+lengthdir_y(125,point_direction(point1x,point1y,mouse_x,mouse_y)))
if point_distance(point1x,point1y,mouse_x,mouse_y) > 200 then draw_sprite(sp_Dot,0,point1x+lengthdir_x(175,point_direction(point1x,point1y,mouse_x,mouse_y)),point1y+lengthdir_y(175,point_direction(point1x,point1y,mouse_x,mouse_y)))
if point_distance(point1x,point1y,mouse_x,mouse_y) > 250 then draw_sprite(sp_Dot,0,point1x+lengthdir_x(225,point_direction(point1x,point1y,mouse_x,mouse_y)),point1y+lengthdir_y(225,point_direction(point1x,point1y,mouse_x,mouse_y)))
Giving this sort of effect:
 

3dgeminis

Member
Try this :
CREATE
Code:
number=10
angle=0
max_dist=0
DRAW
Code:
angle=point_direction(x,y,mouse_x,mouse_y)
max_dist=point_distance(x,y,mouse_x,mouse_y)

for(i=0; i<number; i+=1)
    {  
     draw_sprite(sprite0, 0, x+lengthdir_x(i*max_dist/number, angle), y+lengthdir_y(i*max_dist/number, angle))
    }
I use GM8
 
Top