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

Collision Line Issue

F

foldupgames

Guest
Hey guys!

This OUGHT to be a simple, fix but it's making me crazy. I've got multiple copies of a "Terrain" object that draws terrain triangles instead of putting in a bunch of blocks. It's supposed to have a collision_line that destroys bullets when they cross the line it's drawing.

The same code works well to make the player bounce off the ground, but the bullets? Not so much.

//Terrain object step event
if instance_exists(obj_bullet)
{
if collision_line(x,y,x-640,y+640,obj_bullet,0,1)
with (other)
{
instance_destroy()
}
}

I'm missing something here. It doesn't really work and not all of the Terrain objects even do this - they just fly right through. I'm finding they also don't all generate trees like they should - it's as if the game is only considering ONE to be real. Yet, the plane hits them all just fine.

Say what?

 
Last edited by a moderator:

TheouAegis

Member
Are you sure the bullet is actually ON the line when that code is run? Maybe the bullet passes over the line and so it's never detected. You're talking about a line after all.

Also, you want

with collision_line(x,y, x-640,y+640,obj_bullet,0,1)

The other does absolutely nothing in your code.
 
F

foldupgames

Guest
Hmmm...passing over it. That's a really good thought, actually. Thanks for the input.

Perhaps I will change the collision system for this altogether.
 

Mercerenies

Member
Since you mention that the terrain instances are triangles, this might help. Assuming your bullet is a rectangular mask (and it's probably small enough that you could pretend it's a rectangular mask anyway), GM provides the rectangle_in_triangle() function that should help. Just pass bbox_left, bbox_top, bbox_right, and bbox_bottom of the bullet instance for the rectangle, and the coordinates of your terrain for the triangle.
 
F

foldupgames

Guest
Since you mention that the terrain instances are triangles, this might help. Assuming your bullet is a rectangular mask (and it's probably small enough that you could pretend it's a rectangular mask anyway), GM provides the rectangle_in_triangle() function that should help. Just pass bbox_left, bbox_top, bbox_right, and bbox_bottom of the bullet instance for the rectangle, and the coordinates of your terrain for the triangle.
Oh, that's a good idea too. Thanks!

This is my first attempt at using coordinates and drawing instead of dropping in solid objects, so I'm having to dig into the dreaded mathematics to make things work!

At present, I had the peaks use a rectangle object as a more-familiar workaround. I will have to look at this idea though. Very interesting.

Here's some progress on the way it's drawing mountains though - it's super cool because they will change their elevation at random and the gameplay can go on forever until you lose with the terrain probably becoming more erratic as time goes on.

 
Top