Kahrabaa
Member
Hello.
I want two objects, in 3d, to repel each other based on their position and distance.
In 2d I would:
How would I do the same in 3d?
I found a point_distance_3d but no point_direction_3d.
My thinking is limited to 2d wich is probably why Im thinking incorrectly maybe.
One thing I tried was to move each axis independently. Like
But this gives me incorrect behaviour. Because if the difference in Y is GREAT and the difference in X is small. They still repel each other in the X axis strongly even though they are far away wich is incorrect. This is because each axis is being affected independently. (Realised this after i tried it)
Would appreciate any help
Thank you!
I want two objects, in 3d, to repel each other based on their position and distance.
In 2d I would:
Code:
//Get the inverted distance between the two points (inverted cuz the repulsion needs to be stronger the closer the two objects are)
dis= 1 / point_distance( x1,y1, x2,y2);
//Get the direction
dir=point_direction(x1,y1,x2,y2);
//Accelerate
hspeed+=lengthdir_x( dis, dir);
vspeed+=lengthdir_y( dis, dir);
I found a point_distance_3d but no point_direction_3d.
My thinking is limited to 2d wich is probably why Im thinking incorrectly maybe.
One thing I tried was to move each axis independently. Like
Code:
//Get the inverted X difference between two objects
xdis= 1/(x2-x1);
ydis= 1/(y2-y1);
zdis= 1/(z2-z1);
//The add that to acceleration
hspeed+=xdis;
vspeed+=ydis;
"zspeed"+=zdis;
Would appreciate any help
Thank you!