Physics and Offset collisions

Get help using Construct 2

» Wed Apr 24, 2013 2:40 am

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.

DEMO GAME

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

Box.X+(Sin(Box.Angle)*16)

Box.Y-(Cos(Box.Angle)*16)

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.
B
27
S
9
G
5
Posts: 495
Reputation: 11,964

» Wed Apr 24, 2013 4:48 am

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.

CLICKY HERE

Hope that helps.
B
15
S
5
G
7
Posts: 876
Reputation: 5,650

» Wed Apr 24, 2013 2:38 pm

@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?

@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.

game

capx
B
27
S
9
G
5
Posts: 495
Reputation: 11,964

» Wed Apr 24, 2013 6:20 pm

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.
B
15
S
5
G
7
Posts: 876
Reputation: 5,650