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.

Newcomers AppGameKit Corner / 3D physics : character push a crate ?

Author
Message
Blendman
6
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 4th Apr 2018 09:01
Hi

I use a physics character (3D platformer). I would like to push some crate.

I have created Box with dynamic physics. Do you know what are the physics parameters to push a this object ?
How to push an object with a character ?

thanks
AGK2 tier1 - http://www.dracaena-studio.com
PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 4th Apr 2018 09:51 Edited at: 4th Apr 2018 09:52
If the box is a dynamic physics object and the player uses the physics character controller to move around it should already be able to collide with the correct physics. It is also useful to check the physics character controller debug of the collider it uses, maybe it is misaligned or too small so it fails to collide?

Debug3DPhysicsCharacterController( objID, isDebug )

What code are you using for the box? If you're not using the right type of physics object it might not react properly.

If you want to drag the box you are going to need to add a linear velocity to the box ; check collision and check for a key and then add a slight linear velocity with a vector facing the player.
Blendman
6
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 4th Apr 2018 10:07 Edited at: 4th Apr 2018 10:12
Hi

The character debug is ok

The character react with the box, he's blocked.
The box (crate) has dynamic physics




I would like the character not drag but "push" (move) the crate, when he collide with it, like in a 3Dplatformer.


If I move a dynamic box (moving platform), and if the character collide with it, the dynamic box move my character.
But it dosen't work if I wnat the inverse : the character move the box (not moving alone) if he collide with it ?
AGK2 tier1 - http://www.dracaena-studio.com
Rick Nasher
3
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 4th Apr 2018 13:44 Edited at: 4th Apr 2018 13:58
Perhaps it's similar to throwing balls against a dumpster and a soldier. I've used this for that when was doing some quick experimentation with the ragdoll example.






In main loop something like this:


Dunno if this applies fully, but above seems a good indicator that mass and velocity are required in order to get it to move.
[EDIT]
If this cannot be applied to the character controller, perhaps an invisible object with SetObject3DPhysicsLinearVelocity( objID, directionX, directionY, directionZ, initialSpeed ) applied could do the thrick?
We really need more docs / examples on this subject.
[/EDIT]
Stab in the Dark software
Valued Member
17
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 4th Apr 2018 14:06 Edited at: 4th Apr 2018 14:07
Quote: "If I move a dynamic box (moving platform), and if the character collide with it, the dynamic box move my character.
But it dosen't work if I wnat the inverse : the character move the box (not moving alone) if he collide with it ?"


A Kinematic object can push/move a dynamic.
Dynamic can not push/move Kinematic.
The character controller is Kinematic so it can only push move a dynamic object.
If the character controller is not moving a dynamic box, as well as decreasing the mass you
need to set friction for the box and the floor/platform the box is in contact with. Friction must
get set for static objects like the floor. Decrease the floor friction.
The Character controller is capsule shaped so the dynamic box will be pushed forward and then slide
around the capsule.
A kinematic box/platform can push the character controller and you can controll the movement when you
want the character controller to look like it is moving it.
Another solution would be to create a pick joint at the contact point between the character controller and the dynamic box.
Attaching a pick joint to a dynamic object will allow you to move it in the physics world with out applying forces.
The coffee is lovely dark and deep,and I have code to write before I sleep.
Blendman
6
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 4th Apr 2018 14:41
@stab : do you have a code example when a character can move a dynamic box ?

I have tried to change all (mass, friction...) without any succes.

A character should move another character if they are in collision, right ?
But by default, my character can move another character (ennemy for exemple), I dont know why and how to set up thaht to work.

Thanks a lot.
AGK2 tier1 - http://www.dracaena-studio.com
Rick Nasher
3
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 4th Apr 2018 16:09 Edited at: 4th Apr 2018 16:10
Also.. just found that SetObject3DPhysicsGroupAndMask() doesn't show up in the docs.
So documentation could do little better.

But maybe they have plans..
Blendman
6
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 4th Apr 2018 17:00 Edited at: 4th Apr 2018 17:15
Hm well, I have made a test, and it works fine.

i don't understand why in my game it doesn't work properly...

I have to found where is the issue ^^


AGK2 tier1 - http://www.dracaena-studio.com
Rick Nasher
3
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 4th Apr 2018 18:46 Edited at: 4th Apr 2018 18:49
That's a pretty cool example.
Slight adjustments. Added: turning left/right, crouch/uncrouch, put nose onto player to indicate front. Tried capsule as body shape.



Now it appears when using the capsule shape for the player's body then another capsule shines through giving weird effect, but only while turning the player. Perhaps it's the physics collidercapsule, which would be odd for that one is invisible right?
Blendman
6
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 4th Apr 2018 19:57
The capsule that you see is the character debug
Comment the line 71 Debug3DPhysicsCharacterController
And you will not see this 2nd capsule .
AGK2 tier1 - http://www.dracaena-studio.com
Rick Nasher
3
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 5th Apr 2018 01:10 Edited at: 5th Apr 2018 12:56
Ah, yeah, of course. Completely overlooked that. Also corrected a bug and added some other play stuff like weighted spheres( lighter color means lighter weight) and added friction settings, but apparently doesn't work as simple all together.

I'll really need to invest and do some reading on the whole physics thing for doesn't behave as I think it would, only thing is: where, for docs are limited.

I would expect to be able to add weight to the player too as I've seen the ragdoll example, but somehow that didn't work here. Also I think should be possible to make objects so heavy that can't be moved or hardly, but I wonder how high mass would have to be set for such an object then for didn't succeed.





[EDIT] Also I've noticed the sphere's do not bounce as I expected they would. [/EDIT]
Green7
14
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: Switzerland
Posted: 5th Apr 2018 14:39
Quote: "I would expect to be able to add weight to the player too as I've seen the ragdoll example, but somehow that didn't work here. Also I think should be possible to make objects so heavy that can't be moved or hardly, but I wonder how high mass would have to be set for such an object then for didn't succeed."


maybe increase friction for ground and box.
Rick Nasher
3
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 5th Apr 2018 18:53
True, was my thought too, for friction of 0 makes for a very slippery ground. But without influencing the other objects movements it's bit tricky to figure out the correct values.
Also noticed the player's velocity has next to no influence on hit impact on the other objects, while amongst each other that does seem to matter.

Probably a very delicate balance/range for these values, but not very well documented what are acceptable suitable default values for specific situations.


PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 6th Apr 2018 15:07 Edited at: 6th Apr 2018 15:16
Quote: "I would expect to be able to add weight to the player too as I've seen the ragdoll example, but somehow that didn't work here. Also I think should be possible to make objects so heavy that can't be moved or hardly, but I wonder how high mass would have to be set for such an object then for didn't succeed."


The ragdoll stuff is separate from the physics character controller commands.

You need to set the mass of the crates and other objects higher and the player won't be able to move them anymore, despite being dynamic objects. I've done this in the Cube House Kings game I'm working on.
The idea here is that the player that uses a character physics controller basically has a mass around 1 to 5 or something. It might be some kind of default value we can not change, but.. it is very possible to change all other values in terms of mass and friction to create more meaningful interactions (like not moving a fridge easily, but a pizza box without any effort).

I think the only command influencing this directly in meaningful ways is Set3DPhysicsCharacterControllerGravity(objID, gravity) , but it's more related to jumping than anything else I guess.

If you set boxes to a mass of like 150 or so, it is very much possible to make them virtually unmovable. I've done this with the vault and couch in my Cube House Kings game.



Quote: "Also noticed the player's velocity has next to no influence on hit impact on the other objects, while amongst each other that does seem to matter."


Unfortunately, it seems the player character controller physics only stops other objects with collisions. It doesn't really impact the physics itself indeed. I'm hoping they will expand this actually, because it would be nice if you could create greater interactions using the controller.
Blendman
6
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 6th Apr 2018 15:23
Hi phemox : do you special shape for some object, like chairs ?
AGK2 tier1 - http://www.dracaena-studio.com
PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 6th Apr 2018 15:47
Setting specific values does matter a lot and I would also always recommend setting values for mass and friction etc. if you want a certain type of behaviour. Same goes for bouncing balls etc.

Blendman
6
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 6th Apr 2018 15:51
Phemox : do you have a special shape for your dynamic body, for the chairs in your video ? Or do you use the model (so you use polygon shape physics) ?
AGK2 tier1 - http://www.dracaena-studio.com
PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 6th Apr 2018 15:51
Quote: "Hi phemox : do you special shape for some object, like chairs ?"


Hi! Yes I use;

Create3DPhysicsDynamicBody(chairObj)

..and I use SetObjectShapeStaticPolygon(chairObj)

I have to add a disclaimer though ; it is not recommended to use that shape with Dynamic objects. However I haven't looked into using the 'compound shapes' yet. And honestly, the Polygon shape generation seems to work fairly well for models that are not complex.

Your milage may vary.

Apparently using compound shapes you can use a box for the legs and seat and another separate compound shape for the top part of the chair.
Stab in the Dark software
Valued Member
17
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 6th Apr 2018 17:40 Edited at: 6th Apr 2018 17:48
Quote: "Create3DPhysicsDynamicBody(chairObj)

..and I use SetObjectShapeStaticPolygon(chairObj)"


PHeMoX

You CAN NOT DO THAT. As the commands says in the name it is STATIC not DYNAMIC.
You guys really need to read the commands.

Also SetObjectCollisionMode does not work with the 3D physics commands.

Also you are making your objects too small for the default scale factor.
The coffee is lovely dark and deep,and I have code to write before I sleep.
PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 6th Apr 2018 18:58
Quote: "You CAN NOT DO THAT. As the commands says in the name it is STATIC not DYNAMIC."


Technically we *should not* do that. It is false to state you 'can not' do that.

You've already said as much before. However, it does work. And we still need a dynamic version of the polygonal shape. I'm sure there is a reason why the polygon collision shape are meant for static physics objects. However the compound shapes are unusable without a proper debug mode for physics. We're working blind.
Until then, I'll take the StaticPolygon solution for chairs. As said, with the right values set it works reliably and remains stable. I've also added the disclaimer about compound shapes, so I don't see the issue.

Also, for a lot of static objects that require polygon accurate collisions it works fine as it is intended.

Quote: "You guys really need to read the commands."


No offence, but what do you even mean? Where do you think I've found out about these commands in the first place?? I can't help it we currently need to make do with a still somewhat incomplete set of 3D physics commands in AppGameKit 2.

Quote: "Also you are making your objects too small for the default scale factor."


You mean 10 by 10 by 10 cubes? What exactly are you talking about? From my testing even smaller than 10 by 10 by 10 still works. I would agree default values will very rarely match without tweaks or changes. This is true for most things really.
Blendman
6
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 6th Apr 2018 19:02 Edited at: 6th Apr 2018 19:08
@stab :
Thanks.
What is the good size for object ?
AGK2 tier1 - http://www.dracaena-studio.com
Rick Nasher
3
Years of Service
User Offline
Joined: 25th Jul 2017
Location: Amsterdam
Posted: 6th Apr 2018 19:51 Edited at: 6th Apr 2018 20:16
Aaarrgh of course. That's why in the other code I was using it was working fine. That's what you get when jumping in/out of things.

There are quite a few commands to get into grips with but docs are limited on how to actually apply all of these.
https://www.appgamekit.com/documentation/Reference/3DPhysics/Create3DPhysicsWorld.htm

Best to study the examples, hopefully they're all used and explained in detail there. Haven't checked thoroughly enough to be honest for my current focus is getting networking side working the way I like it. Then will come back to this, not too good at multitasking. lol

Stab already explained the scale thing elsewhere, but can't find it at the moment.

Btw: looking good PHeMoX, was waiting for the tv to show the "I want my MTV.." thing from Dire Straits.
.

[EDIT] Explained here: https://forum.thegamecreators.com/thread/221249
Stab in the Dark software
Valued Member
17
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 6th Apr 2018 21:10
Quote: "Technically we *should not* do that. It is false to state you 'can not' do that. "


Since I am the one who added the bullet physics 3D physics code to AppGameKit I can say you CAN NOT do that.
The Bullet Physics collision shape that is know as a "bvhStaticTrianglemesh" shape can NEVER be dynamic.
I tried telling Paul when he came up with these command names that it would cause confusion.

Quote: "Also, for a lot of static objects that require polygon accurate collisions it works fine as it is intended."


In this AppGameKit implementation of Bullet physics there is NO Polygon collision shape for dynamic rigid bodies.
You are assuming that it will work correctly knowing nothing about the Bullet physics solver.

Quote: "You mean 10 by 10 by 10 cubes? What exactly are you talking about? From my testing even smaller than 10 by 10 by 10 still works. I would agree default values will very rarely match without tweaks or changes. This is true for most things really."


As I said read the command help.
Quote: "
You must create the Physics world before calling any other physics commands. Create3DPhysicsWorld Creates the physics world using the default scale factor of 40. This function will create the physics world with a different scale factor. The scale is not the size of the world, it is the factor by which all the data passed in is scaled down by to convert it to the Bullet Physics scale for the physics calculations. Then the data from Bullet is scaled up before it is passed to the AppGameKit 3D world. The default scale factor will be correct if your average character size is 72 AppGameKit units tall. Then the default gravity of -10.0 meters per second on the Y axis will give the correct visual result. The Bullet Physics solver has a minuim size for objects. Objects below this size will cause instability with the solver. At the default scale factor of 40 the smallest dimension that the solver can handle is about 3.5 AppGameKit units. To calculate the scale factor first determine your character's height in meters, a character of 72 units tall would be 1.8288 meters (or 6ft). Then divide the character's height in units by the characters height in meters, for this example the scale factor would be (72 / 1.8) = 40. "


https://www.appgamekit.com/documentation/Reference/3DPhysics/Create3DPhysicsWorld.htm
The coffee is lovely dark and deep,and I have code to write before I sleep.
PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 6th Apr 2018 22:53
Quote: "Since I am the one who added the bullet physics 3D physics code to AppGameKit I can say you CAN NOT do that."


...but I've got a working game that uses exactly what I described above for a chair to have polygonal accurate physics collision and it does work. Also, don't take any of this personally please. Life's too short.

Quote: "In this AppGameKit implementation of Bullet physics there is NO Polygon collision shape for dynamic rigid bodies.
You are assuming that it will work correctly knowing nothing about the Bullet physics solver."


I'm not assuming anything. I'm telling you what works in AppGameKit 2, despite how it possibly shouldn't work. I'm not sure why you're trying to pick a fight here?

Quote: "As I said read the command help.
"


There's nothing confusing about the command nor what it says in the Help. I've read what the help says. I'm not denying it says we should not use it this way. I'm telling you it does work though, despite your claim of it not working for dynamic objects. Nothing more, nothing less;



If anything I'd wish we see AppGameKit 2 get more physics commands, including an actual command that allows for polygonal accurate physics collisions without (potential) glitches.
PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 6th Apr 2018 22:58
By the way, thanks Rick Nasher. Still have lots of work to do on that game project though, not trying to hijack this thread.
Stab in the Dark software
Valued Member
17
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 6th Apr 2018 23:49
Please read.
http://bulletphysics.org/Bullet/BulletFull/classbtBvhTriangleMeshShape.html
The coffee is lovely dark and deep,and I have code to write before I sleep.
PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 7th Apr 2018 13:41
Quote: "Please read.
http://bulletphysics.org/Bullet/BulletFull/classbtBvhTriangleMeshShape.html"


No thanks. I'm not in an argument with you about anything to do with the solver.
Stab in the Dark software
Valued Member
17
Years of Service
User Offline
Joined: 12th Dec 2002
Playing: Badges, I don't need no stinkin badges
Posted: 7th Apr 2018 19:00
PHeMoX

I am just trying to stop the spread of inaccurate information as other community members may read these posts
and be lead astray. I can no longer help you as you refuse to read the correct information.

The coffee is lovely dark and deep,and I have code to write before I sleep.
Blendman
6
Years of Service
User Offline
Joined: 17th Feb 2014
Location: Arkeos
Posted: 7th Apr 2018 19:24
Hi

What is thegood size for a character ?
Height : 72 ?

I use height : 55
Width 20

So height 72 and width 30 for example ? Or more ?

Thanks
AGK2 tier1 - http://www.dracaena-studio.com
hoyoyo80
4
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 7th Apr 2018 23:42
Blendman, i think anything with 3.5 unit or more can use the physic.
PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 8th Apr 2018 10:11
Yeah around 3.5 units works but can be twitchy / 'buggy' . I wouldn't go smaller than strictly necessary.
PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 8th Apr 2018 10:14
Quote: "Height : 72 ?"


Honestly, it takes a bit of trial and error. I think 72 is what the help assumes default for physics character controller.
But my player is about half that I think and physics mostly work flawlessly in that size range.
hoyoyo80
4
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 9th Apr 2018 00:41
Yes..best to go bigger than the minimum require. I think even non physic collision have problem with small unit. I have a model 1.8 unit size and non physic raycast have problem..i rescale if around 20 times the problem magically gone.
PHeMoX
2
Years of Service
User Offline
Joined: 9th Jan 2018
Location:
Posted: 9th Apr 2018 12:25
Yeah when I come to think of it, there is possibly a bug with the collision that sets an object to the height of a height map generated terrain mesh at position 0,0. Scaling it up makes it less of a problem. Haven't truly figured out if it's my code, but I've simply added a slight offset so no objects are ever at exactly 0,0 at spawn start, nor can the camera that uses terrain as minimum height ever be at 0,0 as a work around.

Login to post a reply

Server time is: 2020-09-19 07:01:36
Your offset time is: 2020-09-19 07:01:36