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 / Physics Raycasting against Sprite Groups [Tier 1]

Author
Message
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 11th Nov 2012 13:22 Edited at: 11th Nov 2012 16:53
Hello, I'm sure this has been asked before, but I couldn't find anything specific... I'm working on a platform game which is coming along nicely... However, I only want my character to be able to jump when in contact with the ground tiles...

Initially, I achieved this using a RayCast under his feet to check for contact. Like this:



The problem with this was that this checked for contact against everything and not just the ground so the 'Sprite' could jump off enemies etc...

I then tried to adapt this and check the RayCast SpriteID to check its a ground tile first (Group 1):



This however, is very CPU intensive. If checks every tile every loop which drops my FPS...

Is there a better/alternative way to do this? Many thanks in advance!
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 11th Nov 2012 15:39 Edited at: 11th Nov 2012 15:44
i use a single sprite where i simply add collison shapes on it for all solid tiles.

Now do you do a single raycast on that shape to see if its grounded.

The sprite i use for this is a dummy sprite!

Keep in mind that the amount of these shapes also slow down the app,i have written code hard to explain that check grid patterns and draw long or high shapes depending on if the closest tile is an solid tile.

I dont have any shapes on the tiles it self

Its hard for me to explain as its hard coded in to my game engine

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 12th Nov 2012 00:56
Since you are using box2d I would recommend welding(joint) a dummysprite made into a sensor to the feet of your character then checking this for collision. Reading the collisions that happen don't add to the workload of box2d because it checks for collisions anyway.
I'm unsure how much work is involved in keeping the weld intact but I haven't noticed anything, cpu load wise.

Use either GetPhysicsCollision if you need to specify what the feet hit or GetSpriteFirstContact(your_sensor) followed by GetContactSpriteID2()


Toby

My hovercraft is full of eels
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 12th Nov 2012 10:51
It's much simpler, instead of using "PhysicsRayCast" use "PhysicsRayCastGroup" and check for group 1.

You only need to change that one call from:


to:



this.mess = abs(sin(times#))
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 12th Nov 2012 13:55
Bax, that sounds just the ticket! I shall give that a go! Thank you!

Thanks for all the other suggestions too!
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 12th Nov 2012 17:22
Ok... So I think I may have found a bigger problem... SetSpriteGroup doesn't seem to work for Android. I have broadcasted the below code to my Samsung S2 and have also created an .apk. None of which correctly display the Group. They all return 0. Has anyone seen/reported this before? Have I missed something?

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 12th Nov 2012 17:44
Funnell7, I just tested your posted code in both v1076 and v1082, using the players I built, on two Android devices (Nexus 7, Android 4.0 and Toshiba 7" Thrive, Android 3.2) and it worked fine. They all reported the same as I saw on Windows (the correct group showing for sprites 3, 7 and 10).

What version of AppGameKit are you using? Where did you get your Player?

Cheers,
Ancient Lady
AGK Community Tester
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 12th Nov 2012 17:57
Hmmmm, that's interesting, I am using v1076 along with the beta player added to 'My Products' page at around the same time v1076 was launched...

Would you mind trying the attached .apk? Its the same code, for which I do not get the correct values.

Attachments

Login to view attachments
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 12th Nov 2012 18:07
That Player is known to be buggy.

Try one from this page (I built them and they work properly).

I just ran the apk you posted and it did not work.

Try using the good v1076 player from my posted set. It can be installed without installing your old one. If broadcasting to that one works properly, then there is something wrong with your apk build process.

Cheers,
Ancient Lady
AGK Community Tester
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 13th Nov 2012 11:09
Thank you for trying AL! It's good to know its likely a version issue and not an AppGameKit bug. I need to download Beta 3 anyway for the Ultrabook sensors, so will give it a try with that version... Thanks again...
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 13th Nov 2012 15:32
Remember to download both the main beta 3 and the sensors/touch packages from the 'My Products' page.

I have not produced an Android or iOS Player for v1083, yet. I don't know how good the beta 3 Android player is from the 'My Products' page.

Cheers,
Ancient Lady
AGK Community Tester

Login to post a reply

Server time is: 2024-11-27 19:24:04
Your offset time is: 2024-11-27 19:24:04