Collision line help

V

Vanthex

Guest
Hi guys
I used collision_line to determine if a block is between the player and the desired block to be selected (where the lines are pointed at). If there is an obstruction, the player's selection box will disappear (not shown here). For example line A, if I want to reach the block that is under the player, since a block is blocking it, the player can't reach it and therefore the player's selection box will disappear. However for line B, if I want to reach for the block that is on the surface, I am tracing the line to the center of the object, which technically is blocking the line. How do I make an exception that the first object it touches doesn't count as an obstruction? (in line A's case, it means that it will select the grass block that is RIGHT under the player)
 
A

anomalous

Guest
You didn't like the suggestions in the other thread?
Reading the manual entry of the function you are using is the first and best way to solve this stuff, its what most of us do.

collision_line( x1, y1, x2, y2, obj, prec, notme );
notme Whether the calling instance, if relevant, should be excluded (true) or not (false).

You would need to run collision from instance B to player, and set notme to true.

This will check collision from instance B to player instance, and NOT count the calling instance (instance B).
 
Last edited by a moderator:
V

Vanthex

Guest
You didn't like the suggestions in the other thread?
Reading the manual entry of the function you are using is the first and best way to solve this stuff, its what most of us do.

collision_line( x1, y1, x2, y2, obj, prec, notme );
notme Whether the calling instance, if relevant, should be excluded (true) or not (false).

You would need to run collision from instance B to player, and set notme to true.

This will check collision from instance B to player instance, and NOT count the calling instance (instance B).
The problem is that I'm checking if an instance is blocking the collision line. But if I start the line from instance B, it basically blocked itself. Which is why I need it to be able to ignore the instance it's starting on.
I'm trying to use an mp grid, it looks like it calculates a path that's strictly bound to the grid, correct me if I'm wrong though, but that's not what i want.
 
A

anomalous

Guest
As I wrote, you set "notme" to true, and as the manual states, the CALLING INSTANCE will be excluded from the collision check.
So you run the check from block B instance, and check collision_line to the player, using notme set to true.

Also, based on your other post mp_grid still gives the better result, I don't see collision_line working in a lot of cases. Just FYI.
 

TheouAegis

Member
var target_block = instance_position(mouse_x,mouse_y,obj_block);
with target_block
if !collision_line(x,y,other.x,other.y,0,1)
instance_destroy();


That is fundamentally how you would do this, just as everyone has said.
 
V

Vanthex

Guest
As I wrote, you set "notme" to true, and as the manual states, the CALLING INSTANCE will be excluded from the collision check.
So you run the check from block B instance, and check collision_line to the player, using notme set to true.

Also, based on your other post mp_grid still gives the better result, I don't see collision_line working in a lot of cases. Just FYI.
var target_block = instance_position(mouse_x,mouse_y,obj_block);
with target_block
if !collision_line(x,y,other.x,other.y,0,1)
instance_destroy();


That is fundamentally how you would do this, just as everyone has said.
Yea I realized my calling instance was the wrong object lol sorry that was my mistake. And yea that's basically how I did the collision line and it works!, I'm still trying the use the mp grid
 
Top