Continuous Collision Detection

JGary321JGary321 Member Posts: 1,246
edited November -1 in Tech Support
I want to check if an actor is overlapping with another actor. But the kicker is I want it to continue to check, not just once.

To explain.. I have a unit actor with the graphic as fixed. So it looks the same no matter what size the actor is.

I change the size of the actor based on which spell is selected, which essentially lets me have an easy way to do range attacks.

I have experimented with every way I know to continuously check to see if the 2 units overlap, but it only does it one time.

So the question is has any figured a way to CONTINUOUSLY check the collision/overlap rule.

As a second part, can someone who understands Magnitude write a basic Explanation of how to use Magnitude as a way of using ranged attacks.

The Magnitude Demo didn't really cover that.

Sincerely,
A non math genius

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    Hey,

    Yeah, I made the magnitude demo for someone else...
    It is too specific, I should remake it.

    Basically, in your case, Magnitude is the distance between two points.
    A line segment if you will.

    You would use it like this:

    DistanceBetweenPlayerandEnemy = Magnitude(abs(PlayerX-EnemyX),abs(PlayerY-EnemyY))

    (Magnitude is a measure of distance, and as such always needs to be positive. That is why the abs() method is in there as well)

    That will give you the distance between two points.

    Ah, but that is NOT exactly what you need. The opposite in fact...
    That number will INCREASE as the the distance between two points become greater.

    What you actually need is the "Inverse-square law". In physics, an inverse-square law is any physical law stating that some physical quantity or strength is inversely proportional to the square of the distance from the source of that physical quantity.

    In layman's terms, the GREATER the distance, the SMALLER the effect.
    In games, this would apply to bomb blasts, spell damage, acoustics, etc...

    In your case, you can simplify this by simply subtracting the magnitude from the spell's power.

    Something like this:

    Lightning Spell: causes 500 points of damage maximum
    Effect on Player: 500 - DistanceBetweenPlayerandSpell(in pixels)

    So if the player is close to the source it would be 500 - (let's say 30) for a total damage to the player of 470

    If the player is further away, let's say 350 pixels away, it would be 500 - 350 = 150 damage points.

    Something like that. Does that make sense?

    At any rate, you can google Newton's Inverse Square Law to learn more.

    My next game actually uses bombs, and I am using a similar formula to this.

    I'll make a new demo about this when I finish the game.

    Hope this helps!
    Joe
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Hey,

    Yeah, I made the magnitude demo for someone else...
    It is too specific, I should remake it.

    Basically, in your case, Magnitude is the distance between two points.
    A line segment if you will.

    You would use it like this:

    DistanceBetweenPlayerandEnemy = Magnitude(abs(PlayerX-EnemyX),abs(PlayerY-EnemyY))

    (Magnitude is a measure of distance, and as such always needs to be positive. That is why the abs() method is in there as well)

    That will give you the distance between two points.

    Ah, but that is NOT exactly what you need. The opposite in fact...
    That number will INCREASE as the the distance between two points become greater.

    What you actually need is the "Inverse-square law". In physics, an inverse-square law is any physical law stating that some physical quantity or strength is inversely proportional to the square of the distance from the source of that physical quantity.

    In layman's terms, the GREATER the distance, the SMALLER the effect.
    In games, this would apply to bomb blasts, spell damage, acoustics, etc...

    In your case, you can simplify this by simply subtracting the magnitude from the spell's power.

    Something like this:

    Lightning Spell: causes 500 points of damage maximum
    Effect on Player: 500 - DistanceBetweenPlayerandSpell(in pixels)

    So if the player is close to the source it would be 500 - (let's say 30) for a total damage to the player of 470

    If the player is further away, let's say 350 pixels away, it would be 500 - 350 = 150 damage points.

    Something like that. Does that make sense?

    At any rate, you can google Newton's Inverse Square Law to learn more.

    My next game actually uses bombs, and I am using a similar formula to this.

    I'll make a new demo about this when I finish the game.

    Hope this helps!
    Joe
  • JGary321JGary321 Member Posts: 1,246
    That's awesome, thanks firemaple. You know any way to do a continuous check for collision?? Like in my above example?
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Hey,

    If I understand correctly,

    I'm pretty sure GameSalad is using Box2D for their physics engine, in which case it doesn't have scaling functionality.

    So for example, you couldn't have a balloon under a pile of stuff, and have the balloon inflate, and have the collision constantly work. The balloon would just go through the other objects.

    Box2D has been ported to many languages, and the way you would accomplish the above with Flash, let's say, is to constantly destroy and respawn the object at a larger size. In that case it does work. A lot of web games use this trick. Shrinking is the same.

    Unfortunately, GameSalad doesn't have just a "overlap" condition, because it would be very helpful in making invisible triggers like this.

    If I was you though, I would ignore the physics in this case and just use Magnitude. That will constantly check its distance.

    Instead of looking for an overlapping shape, just check if the magnitude is within a certain amount.

    i.e., if myDistanceFromWhatever < somevalue, then do Something.

    Hope this helps!
    Joe
Sign In or Register to comment.