美文网首页
DOTS常用代码一

DOTS常用代码一

作者: Leo0543 | 来源:发表于2021-03-23 12:37 被阅读0次

物体是绕其物理碰撞器轴旋转的,因为物理碰撞器驱动着它们的运动。这是您可以“消除”对撞机方向的方法:

Entities
        .WithBurst()
        .WithAll<PhysicsVelocity, PhysicsMass>()
        .ForEach((ref PhysicsVelocity velocity, in PhysicsMass mass) =>
        {
            velocity.Angular = math.transform(math.inverse(mass.Transform), new float3(0, 0, 1));
        })
        .ScheduleParallel();

使用DOTS执行多线程Capsule Collider转换的正确方法:

//在.ForEach之前添加.WithReadOnly(world),这将使世界变为只读
World world = World.DefaultGameObjectInjectionWorld;
BuildPhysicsWorld buildPhysicsWorld = world.GetExistingSystem<BuildPhysicsWorld>();
PhysicsWorld physicsWorld = buildPhysicsWorld.PhysicsWorld;
CollisionWorld collisionWorld = physicsWorld.CollisionWorld;
         
Entities.WithReadOnly(collisionWorld).ForEach((Entity e,  ref Translation translation, ref Rotation rotation) =>
{
    // Your code here for casting colliders
    ColliderCastHit hit = new ColliderCastHit();
    bool haveHit = collisionWorld.CastCollider(c, out hit);
});

相关文章

网友评论

      本文标题:DOTS常用代码一

      本文链接:https://www.haomeiwen.com/subject/bkcfhltx.html