Physics and Offset collisions

0 favourites
  • 4 posts
From the Asset Store
Simple yet very life-like rag doll made with Physics!
  • So, I made a quick example, as I can't figure out why it's not working, when a quick test positioning a sprite at an offset seems to work.


    CAPX download

    Am using Sin/Cos to convert current angle to an offset like so -



    I can place a sprite at that location on startup and during physics movement and it places perfectly each time, however using the same offset to test collision results in some rather odd behaviour.

    It should theoretically be testing for collision against the 16px distance towards the angle the box is facing [ marked by a + ], however it fails to collide, and instead collides when more than 100px away from anything at all.

  • The main reason for it screwing up is the physics is already applying it's own force / impulse upon collision. Also, your overlapping at offset is wrong..

    Remember overlapping at offset is how many pixels ahead you want to check, so basically you're adding the X and Y positions to that. You only need Sin(Box.Angle)*16 for X Offset and -Cos(Box.Angle)*16 for Y offset.

    Also, you're creating a new marker everytime the LMB is pressed (every 0.125 secs while LMB is down to be exact), but you're not destroying them. Just a minor thing, but you'd end up with thousands of markers after a while ;)

    Here's a fixed capx.. no more screwy bouncing around ;) Not sure if it's exactly what you want, but at least the physics is sorted. If you want it to bounce more, then just set elasticity to a higher value on the walls.


    Hope that helps.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ashley - thought I'd refer you- this might be something others find useful - if the behaviour of offset is based on absolute rather than relative coordinates.

    Would an 'offset at angle' be a possibility?

    So for example, if object is rotated 45 degrees, the collision is tested for collision at a a specified distance along a line 45 degrees, instead of x/y coordinates?

    <img src="" border="0">

    procrastinator - Thanks for the suggestions, I had indeed made a schoolboy including the existing coordinates haha.

    I made a working version using a pinned object, this is for a physics based shoot-'em'up game I'm working on, I wanted the enemy ships to turn away from objects.



  • I agree, angle at offset would be nice. It would save us making silly errors like what you had with the X and Y coords. Been there, done that... that's why I spotted that straight away hahah

    Yeah the movement is much better in the new version.

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