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 Studio Chat / [SOLVED] 3D Physics - Get first contact not staying active

Author
Message
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 4th May 2020 04:09 Edited at: 4th May 2020 16:14
Is there a trick to avoid the flickering and have solid on/off result for GetObject3DPhysicsFirstContact(obj) ? It seems to only be active if the object is moving, even with the Can Sleep disabled, and intermittent at that.

In the attached demo the swinging hanger should simply change colors if the doors hits it.

Thanks!

Attachments

Login to view attachments

The author of this post has marked a post as an answer.

Go to answer

Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 4th May 2020 04:55
Quote: "In the attached demo"

no demo attached
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 4th May 2020 13:59
Sorry - forgot to the upload file button apparently... Hopefully attached now.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 4th May 2020 14:29
The command is used like this

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 4th May 2020 14:43 Edited at: 4th May 2020 14:50
Hi fubarpk - I've been playing around with a few examples and have tried that with same result. Attached is updated file with the usage you describe but same output.

Attachments

Login to view attachments
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 4th May 2020 16:00 Edited at: 4th May 2020 16:01
You'd get a lot more help if you posted your code in [ code] tags instead of attaching a file.
Most people (I include myself) give up on the idea of helping if it involves downloading a file but would be happy to help if the code is visible on the forum.
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 4th May 2020 16:10 Edited at: 4th May 2020 16:13
Hi Scraggle, thanks I figured out the code tag thing here now, here's what I'm talking about:

Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 4th May 2020 16:22 Edited at: 4th May 2020 16:23
If it's just debug info that you want then take the Print commands out of the condition:
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 4th May 2020 16:47 Edited at: 4th May 2020 16:49
Quote: "If it's just debug info that you want then take the Print commands out of the condition:"


No actually I'm looking to change the color of the swinging arm, so looking for solid on/off color change on collision. I tried taking outside of the loop with this mod, but still only getting a couple flashes of it changing color to on before switching off again when at rest.



This is the simplest code I was trying at the start:
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 4th May 2020 19:41 Edited at: 4th May 2020 19:43
are you sure hangerSwing is the objectID

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 4th May 2020 20:07 Edited at: 4th May 2020 20:08
Quote: "are you sure hangerSwing is the objectID"


Yes this is the object I want to change color if it gets hit:


And this is the door that is sliding over and hitting the hangerSwing object:


This is just a mock up example I did to post here, specifically to avoid it being a collision with a ground plane. I've tried the Contact Report in the 3d Physics Demo put together by Stab in the Dark but it has the same problem, in that case if the ball is thrown so it stops rolling than the contact report stops polling data for that object. Why would the object stop reporting collision if it is at rest? I would expect the physics engine to be constantly reporting a collision as long as the object is not sleeping.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 4th May 2020 20:40 Edited at: 4th May 2020 20:52
the contact commands are only for physics and only report if there was a contact made during the physics step
it may be how you've define the objects as a physics type
A static object will report a collision with any dynamic object
A dynamic object will detect collision with a static or dynamic object
if you are using a dynamic object you must use the physics move commands you cant just set object via position
as the object and its collision will be in different places

Edit you may want to use kinematic objects or you could raycast

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 4th May 2020 21:24
Quote: " A dynamic object will detect collision with a static or dynamic object
if you are using a dynamic object you must use the physics move commands you cant just set object via position
as the object and its collision will be in different places "


Yep these are two dynamic objects, the door and the hinge. The movement is the slider joint motor, and the hangerSwing is attached to its block with a hinge joint. So this should be using all physics engine to create the collision. If I step the physics with each sync() of the main loop, I'm expecting the
to always be true when the door has the hinge pushed to the side.
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 4th May 2020 22:06
so basically you want a door that when a player walks into it swings open ?

not so sure dynamic objects is the answer

might be an idea to post a full example of what you have so far as a snippet

I know I had to use kinematic objects for something with a door that went up and down auto
but its not really the same so I may leave it for one of the experts around

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 4th May 2020 22:30
Quote: "might be an idea to post a full example of what you have so far as a snippet"

In my game its not that players will move the door by pushing it, the player activates something that operates the slider door motor which then pushes the "switch" (the hangerSwing object.) I can fake what I want to do by using a raycast to detect the door position, or even hard code checking for the doors coordinates. But I expect this to be a core feature of a 3D physics engine, as on the 2D side I get solid feedback that sprites have a collision without this chatter.

This is the full working demo posted again here:
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 5th May 2020 05:51
I think what the engine does is registers a collision and then the physics responds
so getfirstcontact probably should be named something like getfirstcollision because
it is detecting the first collision and not the contact

this may not be the solution you want but works well for me

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 5th May 2020 06:31 Edited at: 5th May 2020 06:32
If you do GetObject3DPhysicsFirstContact( ) and then immediately after GetObject3DPhysicsNextContact() you will miss the first contact
So the loop should look like;

At least that works for me
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 5th May 2020 06:43
Thanks blink the problem is it doesn't register contacts only the collision which I guess in a way was the first contact
jd_zoo wants it to continue getting the contact if they are next to each other. Which ive read before now that I think of it
getfirstcontact does not do

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 5th May 2020 06:53 Edited at: 5th May 2020 07:38
This post has been marked by the post author as the answer.
i know this isn't what you asked for, but:


also:


otherwise, revised code (using GetObjects3DPhysicsContactPositionVector() ), if you prefer:
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 5th May 2020 15:46
Virtual Nomad - you have solved the issue. The GetObjects3DPhysicsContactPositionVector() method gives me status of contact and not just the collision. I cannot explain the friction part but it is required to set the swinging arm friction to 0 for this to give a solid return.

The friction variable does not fix the GetObject3DPhysicsFirstContact() method. so I guess that really is just to register initial collisions and yes fubarpk in hindsight that one probably should have been named collisions instead of contact. I didn't try your method fubarpk as it is a little involved for what I hoped the physics engine could support, I'm glad this simple contact from Virtual Nomad saved me.

Thank you to everyone! Stay safe!
John

Login to post a reply

Server time is: 2024-03-29 09:32:34
Your offset time is: 2024-03-29 09:32:34