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 / 3d collision with character

Author
Message
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 14th Apr 2018 09:10
Hi
How to know when a physics character is in collision with another object (3d) ?

Thank you.
AGK2 tier1 - http://www.dracaena-studio.com
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 15th Apr 2018 10:30 Edited at: 15th Apr 2018 10:36
Something like this
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 15th Apr 2018 10:34 Edited at: 15th Apr 2018 10:59
Apologies that's not needed '
collision with two objects

Collision with a object and a sprite but not yet tested


replacing that line should work better you will have to play around with it
end_z# = 100*unit_z# - GetCameraZ(1)
fubar
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 16th Apr 2018 10:04
Thank you, but it doesn't works properly

I have only collision with object at the right of my character : in x+width, y-h, Z + length

It doesn't work for example in ( x - width, , y-h, Z + length) or ( x + width, , y - h, Z - length) and so...
AGK2 tier1 - http://www.dracaena-studio.com
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 17th Apr 2018 19:32 Edited at: 17th Apr 2018 20:07
if x,y and z hold the center of the object these calculations should work for collision with another object

the width height and depth may be calculated
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 17th Apr 2018 19:43 Edited at: 17th Apr 2018 20:11
If you want to calculate collision with a sprite you may have to do same as above but change the calculations with the unit vectors
more like
fubar
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 17th Apr 2018 20:13
width height and depth need to be float values too
fubar
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 18th Apr 2018 17:46
Hi

Thansk, i will try to see if its ok with my charactercontroller
AGK2 tier1 - http://www.dracaena-studio.com
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 1st May 2018 18:25
Oh sorry Blendman I was guiding you in the wrong direction raycasting only detects the collision between two objects within a
declared area. But I think its possible to detect if the sprite was overlapping the object, if you use vectors to determine if the
vectors would intercept as if the sprite was placed in a 3d world

hope that's a bit more helpful
fubar
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 27th Jul 2023 13:54
HI

Sorry to re open an old thread, but I have always the same matter

When I use the code from your message :


it doesn't work, because object_hit is always the chracter or the model inside the character ^^.

So i have tried some changes but it doesn't work.

do you have an idea how to get the object wich collide with the character or how to fixe that ?

thank you
AGK2 tier1 - http://www.dracaena-studio.com
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 27th Jul 2023 23:28 Edited at: 27th Jul 2023 23:38
blendman,

i skimmed the above, got lost as to why sprites were a part of the discussion, but if you want collision detection between 2 known 3D physics objects, see HERE.

otherwise, if there's something i'm missing, please explain with a little more detail.

and, since you probably have limited experience with bullet, don't forget to delete any 3d object AND its physics body (separate calls).
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 28th Jul 2023 07:55 Edited at: 28th Jul 2023 08:00
HI

Thnak you for the example, but it doesn't work with a character and a box (kinematic or static) :



What I would like is just to know if the character has collision with another object (like in your example) but between a character (physics) and another object physics (static, kinematic, dynamic or character).

For example :
- if the character is on an area where it loses HP, I would like to know ^^.

For the moment, I use a sphere collision (distance), but its not enough precise.
AGK2 tier1 - http://www.dracaena-studio.com
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 28th Jul 2023 13:41 Edited at: 28th Jul 2023 13:42
I'm not sure Create3DPhysicsCharacterController() creates a 3D object the engine is polling for collisions? Interesting that the capsule does not show with the Debug3DPhysicsCharacterController(n,1) switch so I am wondering if there is something else going on I apologize for just guessing here...

I just tried using GetObject3DPhysicsFirstContact() / GetObject3DPhysicsNextContact() and GetObject3DPhysicsContactObjectB() and the collision registers but are a little flakey. I have no experience with Create3DPhysicsCharacterController() so may get chance to look further. In my experience AppGameKit display object and its corresponding 3D physics body are not one in the same (ie moving a static object will not update it's 3d physics body, so curious if the Move3DPhysicsCharacterController() is updating it's corresponding object's physics location or not.)

Automation on Steam now!
Score Table Jr. on Google Play!
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 28th Jul 2023 15:48
HI

thnak you for your answer, I have tried, but it doesn't work I don't know why :



To see the "physics capsule" of the character, you can reduce the box2 object (or set it visible=0).

When we create a physics object, I think it's a 2nd object, depending of the "main object" (model3D for exemple).
This 2nd object (the physics object) can be box, sphere or polygon based on the mesh.

Static object can't update the physics object if we move the "main object", because it's static.
Only kinematic, dynamic and character can update the physics object, if we move the "main object", I guess.
AGK2 tier1 - http://www.dracaena-studio.com
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 28th Jul 2023 18:50 Edited at: 28th Jul 2023 19:26
I cannot seem to get it to return the object ID of the character from the collision, I suspect there is something else that we are missing here...

Try this and see the jump/crouch impacting the debug capsule. You are correct the move set is typically on loading with exception to kinematic objects, the engine will think the object hasn't moved when it comes to the 3D physics. You need to stick with the SetObject3DPhysicsLinearVelocity() commands when moving around dynamic objects during runtime. And to be honest I'm not sure how this even impacts the character controller I am hoping it will handle all this (the crouch/jump actually looks quite effective here just need a fancy animated model.)



Edit - The GetObjectWorldX() coordinates for the character object are updated when moving the character controller. So in some walk-over cases could use the object position, but I think it should be populated in the contact report...
Automation on Steam now!
Score Table Jr. on Google Play!
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 29th Jul 2023 00:16
If I have understood correctly the things you are missing are that the character controller does return a unique value of -1 and contact will only happen momentarily unless a force is constantly applied. There are many moments when contact is clearly taking place but nothing reflects this other than the character visually showing this. If you move around constantly you will note rotation/position affects this significantly. I believe it may be a case of needing more triangles per mesh, perhaps something along the lines of the rest position is achieved instantly which would be more quickly than expected for the overall scale? I have changed the code to show the collisions of the character so that the boxes all change colour for that 1 frame being checked. Green for first contact and purple if at any point after this.

Win 10 Home 64, Intel(R) Core(TM) i5-10300H, 8GB DDR4, NVidia GeForce GTX 1650 4GB GDDR6
jd_zoo
5
Years of Service
User Offline
Joined: 12th May 2018
Location: Nova Scotia
Posted: 29th Jul 2023 14:35
Quote: "the character controller does return a unique value of -1"


I noticed the -1 but was stubbornly set on getting the specific character object ID to be returned... If the -1 is a unique return then Blendman you are likely off to the races here.
Automation on Steam now!
Score Table Jr. on Google Play!
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 30th Jul 2023 00:34 Edited at: 30th Jul 2023 00:40
is there an advantage to using the character controller vs coding our own? from what i can tell, CCs are just a number of helper functions?

re: -1, i've only skimmed the code but there's an apparent ghost object involved internally that may be said "-1"? it would be nice if Create3DPhysicsCharacterController() returned some usable ID.

when we create a 3D object, then set them to bullet objects, the body has the same ID as the object; it would have been nice if character controllers followed the same train of thought.

so, yes, the CCs will work while bringing obstacles like this topic into play, along with some limitations we wouldn't have in coding our own?
James H
17
Years of Service
User Offline
Joined: 21st Apr 2007
Location: St Helens
Posted: 30th Jul 2023 03:45
+1 on the usable Id...although I said -1 is unique I must correct that as I was not thinking further than the code provided by jd_zoo - it might not be if there is another area of the 3d physics that might produce it as a result - just because I can't think of one doesn't mean there isn't.

However that is less important than catching all collisions which is what I see at my end - I think realistically using this hit detection method is too unreliable to be of any meaningful use, unless the usage/code is wrong. In DBP there was newton physics plugin and that had an extra boundary option you could set the thickness for. The boundary basically was like having a second invisible scaled object overlapping the physics object that defines the collision bounds. So the physics object can be sat on a surface where some physics frames the object might or might not penetrate the surface giving "hit and miss " results for hit detection. With the collision bounds set slightly larger contact/hit detection gave 100% reliability in the results. That would have been useful here.

I haven't played much with bullet, so no idea how hard coding our own would be, but it might well be the better option.
Win 10 Home 64, Intel(R) Core(TM) i5-10300H, 8GB DDR4, NVidia GeForce GTX 1650 4GB GDDR6
Blendman
10
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 30th Jul 2023 08:55
Thank you a lot for your answers.

I think I will add the collision object with player in a temporary array and check if there is an object in this array which has special behavior (trap for exemple).

Quote: "is there an advantage to using the character controller vs coding our own? "

I guess, the character can interact with all bullet rigid bodys (static, kinematic and dynamic).
I think it's not the case for the bullet kinematic or the other physics body.

How will you create your own character controller ?
AGK2 tier1 - http://www.dracaena-studio.com
Aidan
User Banned
Posted: 30th Jul 2023 16:26 Edited at: 30th Jul 2023 16:37
I would create 6 invisible objects like small boxes or planes surrounding the main player and object ray cast between the main player and those surrounding objects. Ok this maybe time consuming or even memory consuming cause we will have of their vertexes added to it too. But if they are invisible then shouldn't really matter.

Put these 0.5, 0.5, 0.5 size invisible boxes, below, forward, behind, to the left and right of the main object/player not too close or too far from its origin, something like 1.0 unit away.

The object ray cast should then hit if another object in the scene passes through these and then do what you need to do to the player if does collide, like jump or something.

The idea is simple, programming it would be challenging, but is definitely achievable.

I've seen something done like this before now and works pretty ok for collision detection between other visible objects

Edit .
Found this snippet




Aidan
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 30th Sep 2023 13:45 Edited at: 1st Oct 2023 21:56
Late post but thought I'd have a go.

I also used a ray to get ID and distance.

This one will identify near objects all around.




EDIT: tweeked the code for accuracy trying to detect only what is below feet.



BASIC appeared in May 1964. Lightning flashed, the wind roared and the Earth moved.
And nine months later I was born.
So here I am.
I am Basic.
Code is in my genes.

Attachments

Login to view attachments
Game_Code_here
3
Years of Service
User Offline
Joined: 2nd Jun 2020
Location:
Posted: 30th Sep 2023 22:00
Yes and hello, a long while but thought I would check in to see what's new.

What I do is use a distance formula and do not use collision as it uses to much system memory to keep checking plus it does not work well.

So if each object is to close to each other something happens. collision is based on touching each other and distance is the same thing.

There are real good distance functions on here it is up to you to test them all.

I hope this helps you.

I usually do not post much for others but I figured this out a while back so thought to help is possible.

Login to post a reply

Server time is: 2024-04-25 10:34:07
Your offset time is: 2024-04-25 10:34:07