Force of impact

This forum is currently in read-only mode.
From the Asset Store
Build a thrilling space station scenario with these level assets and characters.
  • I'm using the physics behaviour and basically want one of my objects to be damaged on impact with other objects, where the amount of damage is proportional to the force of the impact.

    I guess my problem is that I don't really know what I mean by force of impact. My best guess is either the change in momentum of the object or the change in energy, before and after the collision.

    I can't get it to act the way I want, for example, one problem I've had every time was that if, say, I wanted an object to be hurt when it fell from a big height, then a lot of the time when it was pushed along the floor it got hurt just as much. (usually when the floor was a downward slope).

    I can see the reason for this happening but can't think of a way around it,

    my event was an attempt at the kinetic energy (1/2 mv^2):

    on collision -> subtract (sprite1.mass+sprite2.mass)*((sprite1.xvel-sprite2.xvel)^2+(sprite1.yvel-sprite2.yvel)^2) from health

    So here when the object was moving fast along the floor it wasn't slowing down and kept losing health proportional to speed. (there sprite1 was the object and sprite2 the floor).

    I'm guessing I need some way of resolving the angle of the collision, not sure how to go about this either though.

    any ideas?

  • Maybe use function that'll decrease vitality only when damage is big enough:

    v < k -> f(v) = 0

    v >= k -> f(v) = kmv

    You can check condition like "v >= k" inside expression.

    So doing damage would looke like this:

    Add to ('damage') value:

    (obj('v') >= obj('k')) * obj('k') * obj('m') * obj('v')[/code:3eve90fb]
    
    (obj('v') >= obj('k')) - this'll get value 1 or 0 depending on its logical value.
    
    Appaerently, syntax Cond?ValIfTrue:ValIfFalse crashes at my machine. Is this a bug?
    
    These above aren't examples of how does formula should look like. AFAIR kinethic energy has part coming from its linear velocity (1/2 * m * v^2) and angular velocity (1/2 * I * w^2). If you have rotating object, collision with ground makes damage proportional to Sum of there two elements.
  • Appaerently, syntax Cond?ValIfTrue:ValIfFalse crashes at my machine. Is this a bug?

    Yeah, crashes are always bugs What expression are you using that crashes?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 1. Always
    -> Sprite: Add (Sprite('myVal') > 0) ? 1 : 0 to 'myVal'[/code:vwitaakp]
    
    Even if I write (2 > 0) ? 1 : 0
    It goes wrong.
  • Even if it only damages if over a certain value (k), you still get that problem. If the object is moving along the floor at some speed over k, it damages it like before.

    I guess its to do with the change of energy before and after the collision???

    In this situation when using the physics behaviour and on collision event, will retrieving the velocity give me the velocity after the collision?

  • Technically it probably does relate to the energy before and after a collision, but you can fake it since in the physics engine it'll probably always be proportional to the momentum at the point of the collision. Momentum is speed * mass so you only really need something based off that, I think.

    However, you probably want the relative speed for calculating damage. If you're going at 1000 px/sec to the right, and you collide with something going right at 900 px/sec, that's a 100 px/sec collision speed, not 1000 px/sec collision speed (factor of 10 difference!).

    The result formula for A colliding with B (pseudocode) probably looks something like

    0.1 * distance(0, 0, A.XVelocity - B.XVelocity, A.YVelocity - B.YVelocity) * A.Mass

    where 0.1 is your 'fudge factor' (since a damage value just involving speed and mass is probably a really big number)

  • http://www.quotecats.com/what/gravplat1.cap

    In that cap, the last event is the damage one.

    controls are W A D Q and E.

    If you run down a hill it hurts you still, none of the formula changes help that. It's why I think it must need to be resolved in the direction of the collision or something, but I have no idea really.

    I'd like to make it hurt you from falling and when other physics objects bash into you. Running along a floor shouldn't hurt you though.

    While I've posted this, any ideas why, when the display is rotated, and you click, the effect isnt at the mouse. (It sets position to mousex("Main") mousey("Main"), seems to bug out when rotated, large possibility I just messed it up though.)

    oh and also, may as well ask, how do I timedeltaify the scrolling//rotating events?

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)