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 / GetPhysicsCollision not 2 sprites just simply hit by anything...

Author
Message
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 26th Jun 2012 13:01
Is there a command that I can use to simply check if a physics enabled sprite has been hit by anything?

So I don't need to go through the list of physics enabled sprites?

All I really need to know is if the sprite was hit or not in the last sync.

Tks
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 26th Jun 2012 14:10
You can loop through all of the collisions and just trigger a variable result like this:

The above code is untested but it should work


this.mess = abs(sin(times#))
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 26th Jun 2012 14:56
I was hoping to get a command that would just tell me if the sprite was actually hit or not to save me from going through the list of sprites.

IE like if I had a wall I wanted it to glow after anything hit it, I don't really need to know what hit it, which could save alot of checking, especially if I had a lot of walls and moving objects.

I could save your code for something more important.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 26th Jun 2012 15:13
This doesn't loop through every sprite, just every contact. Contacts are sprites that are within a certain distance of your test sprite. I added the collision check to test for actual collisions too.

This is a very quick function if you test it. I use it (or a very similar check) on dozens of sprites per loop with no speed issues. It's also more or less exactly how it would be checked internally if TGC wrote a command in Box2D.


this.mess = abs(sin(times#))
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 26th Jun 2012 16:42
If GetSpriteFirstContact(spriteID) returns a non-zero value then it had a collision in the last frame, if you don't need to know what it hit, or how many collisions it had, then you can stop there.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 26th Jun 2012 17:14
Quote: "If GetSpriteFirstContact(spriteID) returns a non-zero value then it had a collision in the last frame, if you don't need to know what it hit, or how many collisions it had, then you can stop there."

What would happen if you then did "getSpriteFirstContact" again on the same or another sprite? I just figured it would be best to finish the loop. I guess if you have hundreds of sprites then it might impact on speed at some point...


this.mess = abs(sin(times#))
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 26th Jun 2012 19:58
Calling GetSpriteFirstContact on the same sprite will always return either 1 or 0. It will return the same results no matter how many times you call it during the same sync cycle.

To determine what sprite it actually hit, you call GetContactSpriteID2 to get the first contact in the list.

You can check for multiple contacts on the same sprite by using GetSpriteNextContact until it returns zero. After each call to GetSpriteNextContact you use GetContactSpriteID2 to determine the id of the contacted sprite.

Cheers,
Ancient Lady
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 26th Jun 2012 21:30
Quote: "What would happen if you then did "getSpriteFirstContact" again on the same or another sprite? I just figured it would be best to finish the loop."


Calling it again is fine. There is only one "GetFirst" loop in AppGameKit that must be completed with "GetNext" until 0 and that is the GetNetworkFirstClient loop since that interacts with the network thread in a specific way.
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 26th Jun 2012 21:58
OK great. Worth checking I thought


this.mess = abs(sin(times#))
ICERGB
22
Years of Service
User Offline
Joined: 8th Nov 2002
Location: Canada
Posted: 30th Jun 2012 23:24
Thanks for the info!

I was thinking, there has to be another command that does this.

And sure enough

Login to post a reply

Server time is: 2024-11-23 17:32:12
Your offset time is: 2024-11-23 17:32:12