Page 1 of 1

How to setup entity collision in C#

Posted: Fri Mar 17, 2017 8:09 pm
by yiannis128
I have an entity, what would be the best way to implement collision for the object, physicalizing it does not do the trick since it stops working after changing the position of the entity in the update event.

Re: How to setup entity collision in C#

Posted: Mon Mar 20, 2017 1:40 pm
by cry-miron
If you have your EntityComponent you can Physicalize it by calling the Physicalize-method on the Physics property of the EntityComponent. For the RollingBall template it works like this for example:

Code: Select all

var physicsEntity = Entity.Physics; if(physicsEntity == null) { return; } // Physicalize the Entity as type Rigid. // This physical entity type is specifically implemented for objects that can move around (so not static). physicsEntity.Physicalize(Mass, EPhysicalizationType.ePT_Rigid);
Moving the object can be done by using the Impulse property on the PhysicsEntity, or by calling the Action<> method on the PhysicsEntity. Example:

Code: Select all

var physics = Entity.Physics; if(physics == null) { return; } //Using the impulse property physics.Impulse = Vector3.Forward * frameTime; //Using the Action<> method physics.Action((Common.pe_action_impulse action) => { action.impulse = Vector3.Forward * frameTime; });
I know this isn't currently the most intuitive way to work with physicalized entities, so let me know if you need more help.
We are currently working on more C# templates which will also bring with it a few upgrades on Physicalize and moving physical-entities so it becomes a bit more intuitive.

Re: How to setup entity collision in C#

Posted: Mon Mar 20, 2017 3:14 pm
by yiannis128
Thanks a lot! Using the first way of movement did not work since the object phased through the terrain but using the action method worked! Also the collision works fine with the terrain but designer shapes don't seem to apply to it.

Re: How to setup entity collision in C#

Posted: Mon Mar 20, 2017 5:59 pm
by cry-miron
This could be caused by a missing surface-type for the designer objects. Can you check if you have a surfacetypes.xml file in you assets folder? It should be in Assets/libs/materialeffects/surfacetypes.xml. From what I remember the designer objects use the default surface type, so make sure there is a definition for a mat_default surfacetype. If you open the surfacetypes.xml file in a text-editor like notepad++ you can see which types are already defined.
My (very simple) surfacetypes.xml looks like this:

Code: Select all

<SurfaceTypes> <SurfaceType name="mat_default"> <Physics sound_obstruction="0.5" /> </SurfaceType> <SurfaceType name="mat_canopy"> <Physics sound_obstruction="0.5" /> </SurfaceType> <SurfaceType name="mat_bullet"> <Physics friction="0.1" /> </SurfaceType> </SurfaceTypes>
If the xml file is missing you can create a new one manually and paste the above xml-code in there.

Re: How to setup entity collision in C#

Posted: Wed Mar 22, 2017 8:55 pm
by yiannis128
Thank you for the xml file, collision seems to be working with designer brushes fine now. I did not have anything in the directory you mentioned, the materialeffects folder was also missing so I had to create that as well with the xml file.