Hello I am having trouble implementing a working physics solution for my enemies, I want to add a physics rigid body and collider to them, unsure what I am doing wrong as I can't seen to get them to collide with each other and instead they just go right through each other. here is my code:
using UnityEngine;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using Unity.Physics;
class EnemyAuthoring : MonoBehaviour
{
public float3 TargetPosition;
public float Speed;
}
class EnemyBaker : Baker<EnemyAuthoring>
{
public override void Bake(EnemyAuthoring authoring)
{
var entity = GetEntity(TransformUsageFlags.None);
AddComponent(entity, new Enemy
{
CurrentPosition = float3.zero,
TargetPosition = authoring.TargetPosition,
Entity = entity,
PhysicsVelocity = new PhysicsVelocity { Linear = float3.zero },
PhysicsMass = PhysicsMass.CreateDynamic(MassProperties.UnitSphere, 1.0f),
PhysicsCollider = new PhysicsCollider { Value = Unity.Physics.SphereCollider.Create(new SphereGeometry { Radius = 8.0f, Center = float3.zero }) }
});
AddComponent(entity, new LocalTransform
{
Position = float3.zero,
Rotation = quaternion.identity,
Scale = 1.0f
});
}
}