GMS2.Issue with moving circles collision

Petrik33

Member
I have an issue with collision checking of circle instances, actually it just doesn't work and collide_object=noone in any case, also importatnt thing is that i don't know why but x always= chobj.x
Important thing:Object doing this script is also a child of Pobj_circle
So this is my GMS 2 script to check for collision between two circle instances:
///@desc CheckForCCollision
for(var t=0;t<instance_number(all);t++)
{
if(t==0) var list=ds_list_create();
var iobj=instance_find(Pobj_circle,t); !!!!!!!!! Actually I think problem is here or down below <------
inst[t]=iobj;
ds_list_add(list,inst[t]);
}
for(var u=0;u<ds_list_size(list);u++)
{

var chobj=ds_list_find_value(list,u)//Object we are checking now

//Include Dynamic-Dynamic Collision
//Make One Circle Stationary (V1-V2) creating new Velocity vector
var scriptV_length=point_distance(chobj.Vx,chobj.Vy,Vx,Vy);
var scriptV_direction=point_direction(chobj.Vx,chobj.Vy,Vx,Vy);


// Early Escape test: if the length of the movevec is less
// than distance between the centers of these circles minus
// their radii, there's no way they can hit.
var dist=point_distance(x,y,chobj.x,chobj.y) !!!!!! Using debugger I found that even When i Have checked Object as a different from checking object it's X and Y coordinates still don't change and have x=chobj.x
when chobj is not the same as the object doing this script; <-------
var R_Sum=R+chobj.R;
if(scriptV_length<(dist-R_Sum)) collide_with=noone;
............
..................
................
}
 

Yal

šŸ§ *penguin noises*
GMC Elder
instance_number(all) is illegal since all isn't an object ID. Try using instance_count instead (which is the number of all instances in the room, regardless of type).
 

Petrik33

Member
instance_number(all) is illegal since all isn't an object ID. Try using instance_count instead (which is the number of all instances in the room, regardless of type).
Doesnt help because my for cicle needs to be checked instance_numebr(Pobj_circle) times.which is a number not an instance_id
 
R

robproctor83

Guest
I'm having a difficult time following your code and I feel like you could probably doing this in a lot simpler way. But, if your set on going about it this way and not just doing normal collisions then you should add some debugging to see what is your issue exactly. show_debug_message() for each value, each step of the way, and you should be able to trace it back and find the issue. Also, you should probably change that all to just the name of the object your testing collisions on instance_number(Pobj_circle)
 

Petrik33

Member
Has already done the thing you wrote in the end, I had it previously but changed trying to fix an issue, about debugging: I used it and found that X of object doing check and X of object being checked is the same , whatever the object is, but thank you very much, and i hadn't known about show debug message
 

Petrik33

Member
I'm having a difficult time following your code and I feel like you could probably doing this in a lot simpler way. But, if your set on going about it this way and not just doing normal collisions then you should add some debugging to see what is your issue exactly. show_debug_message() for each value, each step of the way, and you should be able to trace it back and find the issue. Also, you should probably change that all to just the name of the object your testing collisions on instance_number(Pobj_circle)
Replied below
I'm having a difficult time following your code and I feel like you could probably doing this in a lot simpler way. But, if your set on going about it this way and not just doing normal collisions then you should add some debugging to see what is your issue exactly. show_debug_message() for each value, each step of the way, and you should be able to trace it back and find the issue. Also, you should probably change that all to just the name of the object your testing collisions on instance_number(Pobj_circle)
Sorry please but i really need help, maybe you know what to do with this problem, knowing that the main problem are variables of different objects which are equal without a reason, I mean i cant understand why X=Cobj.x and Y=cobj.y , cant talk about other variables because they are all equal to 0 while debugging because i Cant give my circles a speed while debugging
 

Petrik33

Member
I'm having a difficult time following your code and I feel like you could probably doing this in a lot simpler way. But, if your set on going about it this way and not just doing normal collisions then you should add some debugging to see what is your issue exactly. show_debug_message() for each value, each step of the way, and you should be able to trace it back and find the issue. Also, you should probably change that all to just the name of the object your testing collisions on instance_number(Pobj_circle)
Forget everything I wrote before. You really helped me, the variables are all correct, the script itself is wrong, but actually it would be great if you helped me with it, because i dont want to make a new post. But if you cant please reply, and I will make a new post
 
R

robproctor83

Guest
Well you can post your issue here and I can give it a shot, but no promises
 

Petrik33

Member
So now i have everything clear, but... I dont know how to make last part of my collision code:
1.how to move circles until the point where they will meet accurately, after script detected collision;
2.How to change their speed and moving direction after collision, knowing their masses,velocities,and direction before collision.
 

Petrik33

Member
So, to understand first problem better, my script detects collision and then does this code:
//Dynamic-Static
if(chobj.V=0)
{
x+=lengthdir_x(distance,scriptV_direction);
y+=lengthdir_y(distance,scriptV_direction);
}

//Dynamic-Dynamic
if (chobj.V!=0)
{
var i=scriptV_length/V; //represents when over the course of their movement the circles collided.

distance=V*i;//Checking object distance
var other_distance=chobj.V*i;//Distance of object being checked

//Making an accurate collision
chobj.x+=lengthdir_x(other_distance,chobj.destination);
chobj.y+=lengthdir_y(other_distance,chobj.destination);

x+=lengthdir_x(distance,destination);
y+=lengthdir_y(distance,destination);
}
return true;

scriptV_length is a vector subtraction of moving vector of one circle and another(V-cobj.V);
destination is direction of moving vector;
 

Petrik33

Member
About the second problem: It si just physics and the main problem is to add an momentum lose to avoid infinity movement for example if my circle hit the ball into the wall, the ball woud bounce back to circle the back to wall and it lasts infinity. To avoid these I need to add momentum lose, but i Dont know how to calculate it.
Also I think about adding rotation to movement but its other story.
 
Top