Example #1
0
        public static void Update()
        {
            for (byte worldId = 0; worldId < sInstance.Length; ++worldId)
            {
                World world = sInstance[worldId];

                world.mTickCounter.Update();

                //update all game objects- sometimes they want to die, so we need to tread carefully...

                for (int i = 0, c = world.mGameObjects.Count; i < c; ++i)
                {
                    NetGameObject go = world.mGameObjects[i];
                    if (!go.DoesWantToDie())
                    {
                        go.Update();
                    }
                    //you might suddenly want to die after your update, so check again
                    if (go.DoesWantToDie())
                    {
                        world.RemoveGameObject(go);
                        go.HandleDying();
                        --i;
                        --c;
                    }
                }
            }
        }
Example #2
0
        public static void LateUpdate()
        {
#if _USE_BEPU_PHYSICS
            for (byte worldId = 0; worldId < sInstance.Length; ++worldId)
            {
                World world = sInstance[worldId];

                world.space.Update();


                for (int i = 0, c = world.mGameObjects.Count; i < c; ++i)
                {
                    NetGameObject go = world.mGameObjects[i];
                    if (!go.DoesWantToDie())
                    {
                        go.LateUpdate();
                    }
                }
            }
#elif _USE_BULLET_SHARP
            for (byte worldId = 0; worldId < sInstance.Length; ++worldId)
            {
                World world = sInstance[worldId];

                world.world.StepSimulation(Timing.sInstance.GetDeltaTime());

                //BulletSharp.Math.Matrix trans;
                //world.floor.GetWorldTransform(out trans);
                //LogHelper.LogInfo($"floor {trans.ToString()}, {world.floor.CollisionShape}");


                for (int i = 0, c = world.mGameObjects.Count; i < c; ++i)
                {
                    NetGameObject go = world.mGameObjects[i];
                    if (!go.DoesWantToDie())
                    {
                        go.LateUpdate();
                    }
                }
            }
#elif _USE_BEPU_PHYSICS_V2
            for (byte worldId = 0; worldId < sInstance.Length; ++worldId)
            {
                World world = sInstance[worldId];

                world.Simulation.Timestep(Timing.sInstance.GetDeltaTime());

                for (int i = 0, c = world.mGameObjects.Count; i < c; ++i)
                {
                    NetGameObject go = world.mGameObjects[i];
                    if (!go.DoesWantToDie())
                    {
                        go.LateUpdate();
                    }
                }
            }
#endif
        }
Example #3
0
        public static void LateUpdate()
        {
#if _USE_BEPU_PHYSICS
            for (byte worldId = 0; worldId < sInstance.Length; ++worldId)
            {
                World world = sInstance[worldId];

                world.space.Update();


                for (int i = 0, c = world.mGameObjects.Count; i < c; ++i)
                {
                    NetGameObject go = world.mGameObjects[i];
                    if (!go.DoesWantToDie())
                    {
                        go.LateUpdate();
                    }
                }
            }
#endif
        }
Example #4
0
        private bool Collision(float sourceRadius, Vector3 sourceLocation, NetGameObject target)
        {
            if (target.GetNetworkId() != this.GetNetworkId() && !target.DoesWantToDie())
            {
                // 같은 층이 아닌 경우는 충돌 검사에서 제외
                if (target.DetectCollision(sourceRadius, sourceLocation) && IsSameFloor(target))
                {
                    //first, tell the other guy there was a collision with a cat, so it can do something...
                    if (target.HandleCollisionWithActor(this))
                    {
#if _USE_INPUT_SYNC
                        //simple collision test for spheres- are the radii summed less than the distance?
                        Vector3 targetLocation = target.GetLocation();
                        float   targetRadius   = target.GetCollisionRadius();

                        Vector3 delta         = targetLocation - sourceLocation;
                        float   distSq        = delta.sqrMagnitude;
                        float   collisionDist = (sourceRadius + targetRadius);
                        //if (distSq < (collisionDist * collisionDist))
                        collisionDist = 1.02f;


#if UNITY_EDITOR || DEBUG
                        LogHelper.LogInfo($"collision source{sourceLocation}, target{targetLocation}, delta{delta}, dist{collisionDist}, mapID{target.GetMapId()}, objectCount{World.Instance(WorldId).GetGameObjects().Count+ World.mStaticGameObjects.Count}");
                        LogHelper.LogDrawRay(sourceLocation, delta, new Vector3(1, 0, 1), 1);
                        Vector3 startPos = target.GetLocation() + Vector3.up * (target.rh * 0.5f) + Vector3.left * 0.5f + Vector3.back * (0.5f + target.rh - 1);
                        LogHelper.LogDrawLine(startPos, startPos + Vector3.right * (target.rw), new Vector3(1, 1, 1), 1);
                        LogHelper.LogDrawLine(startPos, startPos + Vector3.forward * (target.rh), new Vector3(1, 1, 1), 1);
                        startPos = target.GetLocation() + Vector3.up * (target.rh * 0.5f) + Vector3.right * (0.5f + target.rw - 1) + Vector3.forward * 0.5f;
                        LogHelper.LogDrawLine(startPos, startPos + Vector3.left * (target.rw), new Vector3(1, 1, 1), 1);
                        LogHelper.LogDrawLine(startPos, startPos + Vector3.back * (target.rh), new Vector3(1, 1, 1), 1);
#endif

#if UNITY_EDITOR || UNITY_STANDALONE_WIN || UNITY_IOS || UNITY_ANDROID
                        if (distSq < ((targetLocation - lastLocation).sqrMagnitude - 0.01f))
                        {
                            LogHelper.LogInfo($"cur {distSq}, last {(targetLocation - lastLocation).sqrMagnitude}");
                            SolveCollision(sourceRadius, sourceLocation, target.GetLocation().x, target.GetLocation().z, target.rw, target.rh);
                        }
                        return(true);
#endif

                        //okay, you hit something!
                        //so, project your location far enough that you're not colliding
                        Vector3 dirToTarget = delta;
                        dirToTarget.Normalize();
                        Vector3 acceptableDeltaFromSourceToTarget = dirToTarget * collisionDist;
                        //important note- we only move this cat. the other cat can take care of moving itself
                        SetLocation(targetLocation - acceptableDeltaFromSourceToTarget);

                        // Collision 크기가 1보다 큰 경우 처리
                        if (target.rw > 1 || target.rh > 1)
                        {
                            Vector3 movePosRW = Vector3.zero;
                            Vector3 movePosRH = Vector3.zero;

                            if (target.rw > 1 && sourceLocation.x >= targetLocation.x + 0.5f)
                            {
                                movePosRW = Vector3.right;
                            }
                            if (target.rh > 1 && sourceLocation.z >= targetLocation.z + 0.5f)
                            {
                                movePosRH = Vector3.forward;
                            }

                            Vector3 deltaRect       = (targetLocation + movePosRW + movePosRH) - sourceLocation;
                            Vector3 dirToTargetRect = deltaRect;
                            dirToTargetRect.Normalize();
                            Vector3 acceptableDeltaFromSourceToTargetRect = dirToTargetRect * collisionDist;
                            SetLocation((targetLocation + movePosRW + movePosRH) - acceptableDeltaFromSourceToTargetRect);
#if UNITY_EDITOR || DEBUG
                            LogHelper.LogDrawRay(sourceLocation, deltaRect, new Vector3(0, 1, 1), 1);
                            startPos = target.GetLocation() + Vector3.up * (target.rh * 0.5f) + Vector3.left * 0.5f + Vector3.back * (0.5f + target.rh - 1);
                            LogHelper.LogDrawLine(startPos, startPos + Vector3.right * (target.rw), new Vector3(1, 1, 1), 1);
                            LogHelper.LogDrawLine(startPos, startPos + Vector3.forward * (target.rh), new Vector3(1, 1, 1), 1);
                            startPos = target.GetLocation() + Vector3.up * (target.rh * 0.5f) + Vector3.right * (0.5f + target.rw - 1) + Vector3.forward * 0.5f;
                            LogHelper.LogDrawLine(startPos, startPos + Vector3.left * (target.rw), new Vector3(1, 1, 1), 1);
                            LogHelper.LogDrawLine(startPos, startPos + Vector3.back * (target.rh), new Vector3(1, 1, 1), 1);
#endif
                        }


                        Vector3 relVel = mVelocity;

                        //if other object is a cat, it might have velocity, so there might be relative velocity...
                        Actor targetActor = target.GetAsActor();
                        if (targetActor != null)
                        {
                            relVel -= targetActor.mVelocity;
                        }

                        //got vel with dir between objects to figure out if they're moving towards each other
                        //and if so, the magnitude of the impulse ( since they're both just balls )
                        float relVelDotDir = Vector3.Dot(relVel, dirToTarget);

                        if (relVelDotDir > 0.0f)
                        {
                            Vector3 impulse = relVelDotDir * dirToTarget;

                            if (targetActor != null)
                            {
                                mVelocity -= impulse;
                                mVelocity *= mActorRestitution;
                            }
                            else
                            {
                                mVelocity -= impulse * 2.0f;
                                mVelocity *= mWallRestitution;
                            }
                        }

                        return(true);
#else
                        // Solve collision disable
                        // LogHelper.LogInfo($"collision source{sourceLocation}, objectCount{World.Instance(WorldId).GetGameObjects().Count + World.mStaticGameObjects.Count}");
                        return(true);
#endif
                    }
                }
                else
                {
                    target.HandleExitCollisionWithActor(this);
                }
            }

            return(false);
        }