EDIT: SOLVED! Great thanks to FlyingSaucerInvasion, you're one First Contact scenario I wouldn't mind!
Link to comment with a portable solution usable as a script:
https://forum.yoyogames.com/index.p...t-of-another-object-solved.64338/#post-385711
I am attempting to draw a line between a circle's center and the edge of another object.
Unfortunately, the code below will draw lines around the circle calling the action, but doesn't seem to detect the collision along the line. If I don't //comment out the "if collision_line(x,y,cx,cy,obj_box,false,false) = true", it just draws nothing.
An overview of the code below: the for loop checks 360 degrees at the distance between the circle and box. Collision_line_point gets the point of contact (in both directions), which is used to get the points between which to draw the lines. This is color-coded to show 360 red lines when no collision is detected, and to do the same with green when a collision is detected (and to stop testing, hence i=360).
Collision_line_point is below:
Any ideas?
Link to comment with a portable solution usable as a script:
https://forum.yoyogames.com/index.p...t-of-another-object-solved.64338/#post-385711
I am attempting to draw a line between a circle's center and the edge of another object.
Unfortunately, the code below will draw lines around the circle calling the action, but doesn't seem to detect the collision along the line. If I don't //comment out the "if collision_line(x,y,cx,cy,obj_box,false,false) = true", it just draws nothing.
An overview of the code below: the for loop checks 360 degrees at the distance between the circle and box. Collision_line_point gets the point of contact (in both directions), which is used to get the points between which to draw the lines. This is color-coded to show 360 red lines when no collision is detected, and to do the same with green when a collision is detected (and to stop testing, hence i=360).
Code:
var circle_self = self
if instance_exists(obj_box)
{
with obj_box
{
var dist = distance_to_object(obj_circle)+16
draw_set_color(c_black)
draw_text(x,y,string(dist))
for (i=0; i<360; i+=1)
{
var cx = (circle_self).x+lengthdir_x(dist,i)
var cy = (circle_self).y+lengthdir_y(dist,i)
draw_set_color(c_red)
with (obj_circle)
if collision_line(x,y,cx,cy,obj_box,false,false) = true
{
i = 360
draw_set_color(c_green)
draw_text(mouse_x+5,mouse_y+5,"Collision True")
var box_edge = collision_line_point(x,y,cx,cy,obj_box,true,true)
var box_edge_x = box_edge[1]
var box_edge_y = box_edge[2]
var circle_edge = collision_line_point(cx,cy,x,y,obj_circle,true,true)
var ciredge_x = circle_edge[1]
var ciredge_y = circle_edge[2]
draw_line(ciredge_x,ciredge_y,box_edge_x,box_edge_y)
}
else
{
draw_line(x,y,cx,cy)
draw_text(mouse_x+5,mouse_y+5,"Collision False")
}
}
}
}
draw_self()
Collision_line_point is below:
Code:
/// collision_line_point(x1, y1, x2, y2, obj, prec, notme)
/*returns an array with following points
r[0] = instance collided with
r[1] = x of point of collision
r[2] = y of point of collision
*/
var x1 = argument0;
var y1 = argument1;
var x2 = argument2;
var y2 = argument3;
var qi = argument4;
var qp = argument5;
var qn = argument6;
var rr, rx, ry;
rr = collision_line(x1, y1, x2, y2, qi, qp, qn);
rx = x2;
ry = y2;
if (rr != noone) {
var p0 = 0;
var p1 = 1;
repeat (ceil(log2(point_distance(x1, y1, x2, y2))) + 1) {
var np = p0 + (p1 - p0) * 0.5;
var nx = x1 + (x2 - x1) * np;
var ny = y1 + (y2 - y1) * np;
var px = x1 + (x2 - x1) * p0;
var py = y1 + (y2 - y1) * p0;
var nr = collision_line(px, py, nx, ny, qi, qp, qn);
if (nr != noone) {
rr = nr;
rx = nx;
ry = ny;
p1 = np;
} else p0 = np;
}
}
var r;
r[0] = rr;
r[1] = rx;
r[2] = ry;
return r;
Last edited: