How do I setup the editor / fields to have in this case my player entity not collide with itself ?
Warning newbie even when it comes to standard physics and layermasks.
Thanks
PointDistanceInput pointDistanceInput = new PointDistanceInput
{
Position = translation.Value,
MaxDistance = 2.0f,
Filter = CollisionFilter.Default
};
You should be able to do something like this in an Authoring Component:
using Unity.Entities;
using UnityEngine;
using Unity.Physics.Authoring;
using Unity.Physics;
// Example Component that holds a Collision Filter.
public struct ExampleComponent : IComponentData
{
public CollisionFilter CollisionFilter;
}
public class ExampleAuthoring : MonoBehaviour, IConvertGameObjectToEntity
{
public void OnEnable() { }
public ExampleComponent ExampleComponent;
public PhysicsCategoryTags BelongsTo = new PhysicsCategoryTags { Category00 = true }; // You can switch / add / remove the default "layers" here.
public PhysicsCategoryTags CollidesWith = new PhysicsCategoryTags { Category01 = true }; // You can switch / add / remove the default "layers" here.
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
// Set the uint values on the CollisionFilter.
ExampleComponent.CollisionFilter.BelongsTo = BelongsTo.Value;
ExampleComponent.CollisionFilter.CollidesWith = CollidesWith.Value;
// Add the component.
dstManager.AddComponentData(entity, ExampleComponent);
}
}
And that will give you two dropdown boxes for you to select your BelongsTo and CollidesWith on the CollisionFilter within the ExampleComponent.
You can set the default values by initializing the PhysicsCategoryTags struct like Iām doing. Just make sure to set the defaults to values that make sense for your own project!
2 Likes
Also, you can do something like BelongsTo = SomeValue, CollidesWith = ~SomeValue (meaning it belongs to a certain group and collides with everything but that group).
In the editor, just choose some category for Belongs To in the Collision Filter field of the Physics Shape script, and in the Collides With make sure this category is deselected.
3 Likes