示例#1
0
        private void Update()
        {
            Screen.CursorVisible = false;
            Screen.CursorLock    = CursorLockMode.Locked;

            // Mouse
            Vector2 mouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

            pitch = Mathf.Clamp(pitch + mouseDelta.Y, -88, 88);
            yaw  += mouseDelta.X;

            // Jump
            if (CanJump && Input.GetAction("Jump"))
            {
                _jump = true;
            }

            // Shoot
            if (Input.GetAction("Fire"))
            {
                var ball         = RigidBody.New();
                var ballCollider = SphereCollider.New();
                var ballModel    = StaticModel.New();
                ball.Name                = "Bullet";
                ball.StaticFlags         = StaticFlags.None;
                ballModel.Model          = SphereModel;
                ballModel.Parent         = ball;
                ballModel.StaticFlags    = StaticFlags.None;
                ballCollider.Parent      = ball;
                ballCollider.StaticFlags = StaticFlags.None;
                ball.UseCCD              = true;
                Actor gun = this.Actor.FindActor("BulletSpawner");
                ball.Transform = new Transform(
                    gun.Position,
                    Quaternion.Identity,
                    new Vector3(0.1f));
                SceneManager.SpawnActor(ball);
                ball.LinearVelocity = gun.Direction * 600.0f;
                Destroy(ball, 5.0f);
            }
        }
示例#2
0
        void Update()
        {
            Screen.CursorVisible = false;
            Screen.CursorLock    = CursorLockMode.Locked;

            // Mouse
            Vector2 mouseDelta = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

            pitch = Mathf.Clamp(pitch + mouseDelta.Y, -88, 88);
            yaw  += mouseDelta.X;

            // Jump
            if (CanJump && Input.GetAction("Jump"))
            {
                _jump = true;
            }

            // Shoot
            if (CanShoot && Input.GetAction("Fire"))
            {
                var ball         = RigidBody.New();
                var ballCollider = SphereCollider.New();
                var ballModel    = ModelActor.New();
                ballModel.Model     = SphereModel;
                ballModel.Parent    = ball;
                ballCollider.Parent = ball;
                ball.UseCCD         = true;
                ball.Transform      = new Transform(
                    CameraTarget.Position + Horizontal(CameraTarget.Direction) * 70.0f,
                    Quaternion.Identity,
                    new Vector3(0.1f));
                SceneManager.SpawnActor(ball);
                ball.LinearVelocity = CameraTarget.Direction * 600.0f;
                Destroy(ball, 5.0f);
            }
        }