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 / Check All Collision at one code

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Jan 2016 19:08
Hi.

I wrote my jump action (without physics) and now I need check collision between Player and all floors. I don't want check one by one floors and player collisions, So I need a way for check all at one code. (e.g: if Player is ground (need how can check it) then IsGround = 1).

please guide me to do this.

Thanks.
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 8th Jan 2016 19:15
Without looking at the help files, there should be collision commands where you can check against your object and 0. 0 means check against all objects.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 8th Jan 2016 20:02
Checking against everything all the time is inefficient. Minimize the overhead by only checking those floor objects that are near the player. No point in checking if it hits something on a whole other screen away.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Jan 2016 20:17 Edited at: 8th Jan 2016 21:10
is a good way that I define all floors as Array and check them in a for loop?

like below example :

MarcoBruti
12
Years of Service
User Offline
Joined: 20th Nov 2011
Location: Caput Mundi
Posted: 8th Jan 2016 20:26
Simply switch on physics, and use setSpriteCollideBits() and setSpriteCategoryBits(). Set gravity and all physics parameters to 0 in order gravity does not affect the movements. Set all sprite to kinematic (no mass). There is an example in the help files related to those commands.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 8th Jan 2016 20:55
Quote: "Simply switch on physics, and use setSpriteCollideBits() and setSpriteCategoryBits(). Set gravity and all physics parameters to 0 in order gravity does not affect the movements. Set all sprite to kinematic (no mass). There is an example in the help files related to those commands."


OK, Thanks.

I check it.
mrradd
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: CA, USA
Posted: 10th Jan 2016 16:00
I do what MarcoBruti, so I can use the AGK2's physics collision list--it works really well.
Crazy Programmer
AGK Developer
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Lost in AGK
Posted: 10th Jan 2016 17:35
Quote: "I wrote my jump action (without physics) and now I need check collision between Player and all floors. I don't want check one by one floors and player collisions, So I need a way for check all at one code. (e.g: if Player is ground (need how can check it) then IsGround = 1)."


Set your Ground tiles to SpriteGroup = 1

Then Check a RayCastGroup from your players feet to check if it is touching the ground.

RayCast = SpriteGroupRayCast(1,PlayerX#,PlayerY#,PlayerX#,PlayerY# + CharacterSpriteHeight# + 1)

If RayCast = 1 and GetRawKeyPressed(32) = 1
//Do your jump stuff only if sprite is touching ground
endif


Sign up for NaGaCreMo!
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 12th Jan 2016 04:36
Quote: "Set your Ground tiles to SpriteGroup = 1

Then Check a RayCastGroup from your players feet to check if it is touching the ground.

RayCast = SpriteGroupRayCast(1,PlayerX#,PlayerY#,PlayerX#,PlayerY# + CharacterSpriteHeight# + 1)

If RayCast = 1 and GetRawKeyPressed(32) = 1
//Do your jump stuff only if sprite is touching ground
endif"


Thanks, I think this is good idea.

is there any way to see RayCast?

Login to post a reply

Server time is: 2024-11-17 02:39:48
Your offset time is: 2024-11-17 02:39:48