S
Searous
Guest
First off, my collisions work fine. I just want to fix what happens when two instances collide. Also, I'm working with GMS 2.
What I want to do is write a script that pushes two instances away from each other, using the weight value of each object to determine how much it is affected by other instances; weight is the amplitude for the pushing effect. This scrip will execute on both colliding instances, and apply the pushing effect only to the executing object. The effect should scale the closer two instances are to each other, modifying the rate at which the amplitude increases basted on the size of the instances sprite. (while I would like this to be based on masks, simply using a sphere around the instances origin)
I've attempted an implementation of this effect myself, and it has several problems. The most noticible, is that instances seem to sltick to one another rather than being pushed away. This might be a simple fix though.
I've played with this on and off for most of the time I've been working on my game. It's pretty much stayed the same, and it's always had the problem I mention.
Here is the script:
On a side note, I would also like a hard collision version which uses masks, and prevents an instance from passing through another instance. My code is setup in such a way to allow different collision conditions based on any factor I want to implement.
Thank you for reading.
What I want to do is write a script that pushes two instances away from each other, using the weight value of each object to determine how much it is affected by other instances; weight is the amplitude for the pushing effect. This scrip will execute on both colliding instances, and apply the pushing effect only to the executing object. The effect should scale the closer two instances are to each other, modifying the rate at which the amplitude increases basted on the size of the instances sprite. (while I would like this to be based on masks, simply using a sphere around the instances origin)
I've attempted an implementation of this effect myself, and it has several problems. The most noticible, is that instances seem to sltick to one another rather than being pushed away. This might be a simple fix though.
I've played with this on and off for most of the time I've been working on my game. It's pretty much stayed the same, and it's always had the problem I mention.
Here is the script:
Code:
/// @description Soft entity collisions
var a, distance;
a = point_direction(x, y, other.x, other.y) - 90;
distance = point_distance(x, y, other.x, other.y);
x += sin(degtorad(a)) * (other.weight * (((other.sprite_width / 2) - distance) / (other.sprite_width / 2)));
y += cos(degtorad(a)) * (other.weight * (((other.sprite_width / 2) - distance) / (other.sprite_width / 2)));
Thank you for reading.