コード例 #1
0
        public override void Update(float deltaTime)
        {
            if (Vector3.Distance(Position, Camera.CameraPos) < PlayerStats.thickness)
            {
                Game.PlayerStats.DealDamage(damage);
                if (poison)
                {
                    Game.PlayerStats.Poison(damage);
                }
                Destroy = true;
            }

            if (Scene.CheckMovement(Position, direction * speed * deltaTime, 0f, ObstacleLayerMask.GetMask(ObstacleLayer.Wall)))
            {
                Position += direction * speed * deltaTime;
            }
            else
            {
                Destroy = true;
            }
        }
コード例 #2
0
        public override void Update(float deltaTime)
        {
            // This is extremely inefficient, but let's hope that it's sufficient :p
            foreach (GameObject gameObject in Scene.gameObjects)
            {
                if (gameObject is Monster monster && !monster.Invincible)
                {
                    if (Vector3.Distance(Position, monster.Position) < monster.HitRadius)
                    {
                        monster.DealDamage(damage);
                        Destroy = true;
                    }
                }
            }

            if (Scene.CheckMovement(Position, direction * speed * deltaTime, 0f, ObstacleLayerMask.GetMask(ObstacleLayer.Wall)))
            {
                Position += direction * speed * deltaTime;
            }
            else
            {
                Destroy = true;
            }
        }
コード例 #3
0
        public override void Update(float deltaTime)
        {
            MeshObject.Rotation += deltaTime * (float)Math.PI * 0.3f;

            behaviourCheckTime -= deltaTime;
            if (behaviourCheckTime < 0f)
            {
                behaviourCheckTime = 0.2f;
                behaviourState     = StateCheck();
            }

            Vector3 towardsTarget = Vector3.Normalize(targetPosition - Position);

            if (behaviourState == BehaviourState.Chasing || behaviourState == BehaviourState.Searching)
            {
                float magnitude = Math.Min(deltaTime * Speed, PlayerStats.thickness + HitRadius);
                Position += Scene.SmoothMovement(Position, towardsTarget * magnitude, HitRadius, ObstacleLayerMask.GetMask(ObstacleLayer.Wall));
            }
            if (behaviourState == BehaviourState.Chasing || behaviourState == BehaviourState.Attacking)
            {
                shootTime += deltaTime;
                if (shootTime > ShootSpeed && !Game.PlayerStats.dead)
                {
                    shootTime = 0f;
                    Attack(towardsTarget);
                }
            }
        }
コード例 #4
0
        protected BehaviourState StateCheck()
        {
            float distance = Vector3.Distance(Position, Camera.CameraPos);

            if (distance < AlertDistance && Scene.CheckMovement(Position, Camera.CameraPos - Position, 0f, ObstacleLayerMask.GetMask(ObstacleLayer.Wall)))
            {
                targetPosition = Camera.CameraPos;
                if (distance < AttackDistance)
                {
                    return(BehaviourState.Attacking);
                }
                else
                {
                    return(BehaviourState.Chasing);
                }
            }

            if (Vector3.Distance(targetPosition, Position) > HitRadius)
            {
                return(BehaviourState.Searching);
            }
            return(BehaviourState.Idle);
        }
コード例 #5
0
        public override void Update(float deltaTime)
        {
            behaviourCheckTime -= deltaTime;
            if (behaviourCheckTime < 0f)
            {
                behaviourCheckTime = 0.2f;
                float distance = Vector3.Distance(Position, Camera.CameraPos);

                if (distance < AttackDistance)
                {
                    bool playerVisible = Scene.CheckMovement(Position, Camera.CameraPos - Position, 0f, ObstacleLayerMask.GetMask(ObstacleLayer.Wall));

                    if (behaviourState == BehaviourState.Idle && playerVisible && distance < AlertDistance)
                    {
                        behaviourState = BehaviourState.Attacking;
                    }
                    else if (behaviourState == BehaviourState.Attacking && !playerVisible)
                    {
                        behaviourState = BehaviourState.Idle;
                    }
                }
                else
                {
                    behaviourState = BehaviourState.Idle;
                }
            }

            if (behaviourState == BehaviourState.Attacking)
            {
                if (Position.Y < -2f)
                {
                    Position += 3f * deltaTime * Vector3.Up;
                }
            }
            else
            {
                if (Position.Y > -4.25f)
                {
                    Position += 3f * deltaTime * Vector3.Down;
                }
            }

            Vector3 towardsTarget = Vector3.Normalize(Camera.CameraPos - Position - Vector3.Up * 2f);

            if (Position.Y > -3f)
            {
                shootTime += deltaTime;
                if (shootTime > ShootSpeed && !Game.PlayerStats.dead)
                {
                    shootTime = 0f;
                    Attack(towardsTarget);
                }
            }
        }
コード例 #6
0
        public override void Update(float deltaTime)
        {
            MeshObject.Rotation += deltaTime * (float)Math.PI * 0.3f;

            behaviourCheckTime -= deltaTime;
            if (behaviourCheckTime < 0f)
            {
                behaviourCheckTime = 0.2f;
                behaviourState     = StateCheck();
            }

            if (behaviourState == BehaviourState.Chasing || behaviourState == BehaviourState.Searching)
            {
                float   distance        = (targetPosition - Position).Length();
                Vector3 desiredVelocity = (targetPosition - Position) / distance * Math.Min(Speed, 8f * distance);
                Vector3 correction      = desiredVelocity - velocity;

                velocity += Vector3.Normalize(deltaTime * acceleration * Vector3.Normalize(correction));
            }

            if (velocity.Length() > 0f)
            {
                velocity = Vector3.Normalize(velocity) * Math.Min(Speed, velocity.Length());
            }
            Position += Scene.SmoothMovement(Position, velocity * deltaTime, HitRadius, ObstacleLayerMask.GetMask(ObstacleLayer.Wall));

            Vector3 towardsTarget = Vector3.Normalize(targetPosition - Position);

            if (behaviourState == BehaviourState.Chasing || behaviourState == BehaviourState.Attacking)
            {
                shootTime += deltaTime;
                if (shootTime > ShootSpeed && !Game.PlayerStats.dead)
                {
                    shootTime = 0f;
                    Attack(towardsTarget);
                }
            }
        }