Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Collision Checking - Concave Shapes

Author
Message
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 16th Jun 2014 01:23
Say you have an 'S' shaped race track, and you want to check if the car is on the track, how could you do that currently seeing as you cannot create concave shapes?

Are there any clever ways of doing this, without using multiple sprites to make up the 'S'?

For example, Is it possible to check the colour of a particular pixel? My thinking is that you could check the pixel under the center of the car to see if it is on the track, if that makes sense...

Thank you!
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 16th Jun 2014 02:46
You could add a bunch of rectangles that overlap to the physics shape to make your S.

easter bunny
12
Years of Service
User Offline
Joined: 20th Nov 2012
Playing: Dota 2
Posted: 16th Jun 2014 08:33
Quote: "without using multiple sprites to make up the 'S'?"

Not that I can think of
If your track was made out of perfect hyperbolas (hyperbolae?), or some other procedurally drawn shape, then it'd be easy enough, but obviously you want some variation in it, so that wouldn't do.

It's not that bad though having multiple shapes, the AppGameKit engine is easily fast enough to handle it. Just make sure you hide them with SetSpriteVisible not SetSpriteColorAlpha. I'm pretty sure if you do the colour alpha method, it'll still draw them and slow down the game a tonne. Not sure completely about this though, should check it out some time


Audacia Games - Latest WIP - AUTOMAYTE 2.1, AppGameKit one click deploy to Android
"When you've finished 90% of your game, you only have 90% left"
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 16th Jun 2014 13:46
You can make concave shapes using multiple triangles / other concave shapes. As long as each shape you add is concave you can add as many as you like. Take a look at my tool:
http://forum.thegamecreators.com/?m=forum_view&t=194938&b=48
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 16th Jun 2014 13:52
If you plan to use a single image for the track, then adding your own triangles to the sprite is the best way. I've actually used this to make a 2D planet, uses a lot of triangles but it does work - but you really need a tool like Baxslash has made to do it properly.

I'd suggest storing the vertex coordinates as 0.0-1.0 floats, then you can multiply them by the sprite size - this means that if you have to re-size the track, you don't have to lay out the collision data all over again.

I am the one who knocks...
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 16th Jun 2014 14:52 Edited at: 16th Jun 2014 14:53
Thanks guys, yeah Bax, I'm aware of your excellent tool, but I was hoping to do this without the need to create multiple sprites to make up the 'S' (I thought perhaps something had changed what with V2 etc)... Doesn't sound like I have any other way though

If there was a way to look at a particular pixel colour then that would work, but I guess you cannot do that either?

Thanks again all!
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 16th Jun 2014 15:39
You don't need to use individual sprites - just get your track sprite, and add collision triangles to that, as many as you need!

It might not be easy to confine it all to 1 single sprite, depends on how complicated the track is - maybe need 1 sprite for the outside edge and 1 sprite for the inside edge, assuming a looping track of course.

I am the one who knocks...
Matty H
16
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 16th Jun 2014 16:03
Quote: "For example, Is it possible to check the colour of a particular pixel?"


Absolutely. Your question was just about checking if the car is on the track, if that is all you need then checking a pixel colour is probably a really good idea.

You could have a small image that represents the surface of the world, red may be the track, green may be grass, blue could be ice(slippy), etc... You then scale everything(car position) down to correspond with that image and you can check what the surface is at any given time, it would be like a mini-map that the user does not see.

Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 16th Jun 2014 17:50 Edited at: 16th Jun 2014 17:54
That's right, my question is about checking if object A is currently on the track, I had assumed the only way to do this would have been with the collision commands...

To make things clearer, here is an image of what I mean. Point A is clearly on the Red track whereas Point B clearly isn't. What I was thinking is that if I could check the pixel colour at these points, I'd know whether the object was either on the track (Red pixel) or off the track (white pixel)... Is something likt that possible??



I get what Van is saying, which is to add multiple shapes (not sprites) to either the track or surround to build up a collision area. I was hoping there was an easier method...

Many thanks!!

Attachments

Login to view attachments
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 16th Jun 2014 18:45
Yes, you can get the colour of a pixel from an image using memblocks. If you create an image like this you can get the colour of an exact pixel and check what colour it is. That's arguably easier to get and certainly easier to make accurate.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 17th Jun 2014 01:47
Quote: "Say you have an 'S' shaped race track, and you want to check if the car is on the track, how could you do that currently seeing as you cannot create concave shapes?"


Trace the center of the track with line segments. If the car is more than a certain distance from the line, it's off the track.

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 17th Jun 2014 09:56
If the track doesn't loop, then it might be possible to just have a 1D array with 2 indices, one for the left side and one for the right, then if the car is inbetween those for it's Y position/array index then it's on the track. This has the added benefit of letting you guage just how off or on the track the car is, so it can be a gradual effect on the car when you go off road.

You could of course use a memblock to trace the track.

I am the one who knocks...

Login to post a reply

Server time is: 2024-11-25 06:52:18
Your offset time is: 2024-11-25 06:52:18