• 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 Curved Hitscan

Dragula5892

Member
Hello everyone, I know i've seen this somewhere, but i figured i'd try to get it back to life, and i also am trying to figure out how to do this myself for a weapon that would simply look awesome with curved hitscan lines going around the place :p, i already know how to do hitscan weapons, my question is, how would i make it curve or coil around to an close by enemy before hitting them within the instant it's drawn? I'm making a side scrolling shooter, and my enemies spawn in waves, so it'd be cool for the gun to randomly curve and hit a random enemy, i already have something like this in place as a projectile weapon, but i want it to be more instant
 
S

SyntheticStorm9

Guest
Probably something like:


in create event

alarm[0] = 5
spd = ?



in alarm[0]

motion_set(choose(0, 45, 90, 135, 180, 225, 270, 315),spd/2);
alarm[0] = 5

in step
if distance_to_object(obj_enemy) >10
{
move_towards point(obj_enemy)

if collision_point(x,y,obj_enemy)
{
instance_destroy()
}
}
 

Dragula5892

Member
Probably something like:


in create event

alarm[0] = 5
spd = ?



in alarm[0]

motion_set(choose(0, 45, 90, 135, 180, 225, 270, 315),spd/2);
alarm[0] = 5

in step
if distance_to_object(obj_enemy) >10
{
move_towards point(obj_enemy)
}
hitscans take place in the draw event, that's for a projectile weapon, which i already have, here's a basic hitscan weapon completely coded out for you guys to use if you wish

Code:
//Create event:

fire=false
timer=0
wait=0
wep=0
ammo=100

//Step Event:

If wait>=1 {wait-=1}

If wait=0
{
if timer>=1
{
timer-=1
}
}

If timer<=0 {timer=0}

If timer=0
{
If fire=true {fire=false}
}

If ammo>=100 {ammo=100}

If ammo<=0 {ammo=0}

If mouse_check_button_pressed(mb_left)
{

if wep=0
{
If ammo>=1
{
ammo-=1
If fire=false
{
wait=2
timer=1
fire=true

audio_play_sound(gunshot1,0,0)
}
}
}


}

//Draw Event:

len=0
maxlen=1600

If fire=true
{
while(len<maxlen && !position_meeting(x+lengthdir_x(16,angle),y+lengthdir_y(16,angle),enemy_parent))
{
 
draw_sprite_ext(res_line_8by1,0,x+lengthdir_x(16+len,angle),y+lengthdir_y(16+len,angle),1,1,angle,c_white,1)

len+=8
}
}

var hit=instance_position(x+lengthdir_x(16+len,angle),y+lengthdir_y(16+len,angle),enemy_parent)
 if hit
 {
hit.HP-=1
 }
i'm trying to make it so it's able to curve and coil to a random enemy that's on screen and ahead of my character
 
Last edited:
S

SyntheticStorm9

Guest
How about this:



in create event

target = false
alarm[0] = 5
alarm[2] = 0


in alarm[0]

target = true

in step event
if target = false
{
alarm[2] = 3
}


in alarm[2]
motion_set(choose(0, 45, 90, 135, 180, 225, 270, 315),spd/2);


in draw event

if target = true
{
move_to_point(x,y,obj_enemy)
}

draw line behind self
 

Dragula5892

Member
How about this:



in create event

target = false
alarm[0] = 5
alarm[2] = 0


in alarm[0]

target = true

in step event
if target = false
{
alarm[2] = 3
}


in alarm[2]
motion_set(choose(0, 45, 90, 135, 180, 225, 270, 315),spd/2);


in draw event

if target = true
{
move_to_point(x,y,obj_enemy)
}

draw line behind self
ok, i just said this, i already have something like this in place i'm looking to create the hitscan alternative, hitscan weapons happen in one frame, dude
 
A

amusudan

Guest
You might want to look into parabolas (I'm not sure how they're called) to get the correct formula for a curved line (which you can use for the actual hitscan collision checks and drawing it (in a loop, of diddly course))
 

Dragula5892

Member
You might want to look into parabolas (I'm not sure how they're called) to get the correct formula for a curved line (which you can use for the actual hitscan collision checks and drawing it (in a loop, of diddly course))
Alright, i'll be sure to do so, i know gamemaker takes a lot of math to do the simplest of things at times
 

Dragula5892

Member
You might want to look into parabolas (I'm not sure how they're called) to get the correct formula for a curved line (which you can use for the actual hitscan collision checks and drawing it (in a loop, of diddly course))
alright, i got a start, here's my current code


Code:
//Step Event:
keyboard_check(ord("Z"))
{

 if fire=false
 {
 timer=2
 audio_play_sound(bullet_fire,0,0)
 fire=true
 rand=random_range(-2,2)
 rand2=random_range(-.005,.005)
 }
}

//Draw Event:
len=0
maxlen=1600

if fire=true
{
while (len<maxlen && !position_meeting(x+lengthdir_x(len,0),y+lengthdir_y(len,0-rand),enemy_parent))
{

draw_point_colour(x+lengthdir_x(len,0),y+lengthdir_y(len,0-rand),c_lime)

rand-=rand2
len+=4
}

var hit=collision_point(x+lengthdir_x(len,0),y+lengthdir_y(len,0-rand),enemy_parent,1,1)

if hit
{
 instance_create(x+lengthdir_x(len,0),y+lengthdir_y(len,0-rand),tracker)
}
}
how would i make it have more curves along the way, and maybe even have full loops completely randomly?
 

sp202

Member
I think a path is the easiest thing to do. When do you want the bullet to curve towards an enemy? When it's within a certain distance? Add a path point at the player, add a path point at the enemy location and a third between them with an offset and draw the path as a curve.
 

Dragula5892

Member
I think a path is the easiest thing to do. When do you want the bullet to curve towards an enemy? When it's within a certain distance? Add a path point at the player, add a path point at the enemy location and a third between them with an offset and draw the path as a curve.
ok, you may have to give me a small example, i'm toying with it as we speak, but how do i set a path as a collision point?
 

sp202

Member
The path is just for graphical effect. I think tracking a parabola is overkill, just pick an instance within range of the regular collision_line.
 

Dragula5892

Member
The path is just for graphical effect. I think tracking a parabola is overkill, just pick an instance within range of the regular collision_line.
i'm kinda done with the tracking part, i'm just trying to make it look cooler, more random curves and the like, other than that, it's pretty decent, and hits very randomly, like i initially wanted
 
Top