private void GetInputs() { movementInput.X = Input.GetAxis("Horizontal"); movementInput.Z = Input.GetAxis("Vertical"); movementInput.Normalize(); rotateInput.X = Input.GetAxis("Mouse Y"); rotateInput.Y = Input.GetAxis("Mouse X"); gravityClockwiseAngleDelta = Mathf.SmoothDamp(gravityClockwiseAngleDelta, Convert.ToSingle(Input.GetAction("Gravity clockwise")) - Convert.ToSingle(Input.GetAction("Gravity counterclockwise")), ref gravityClockwiseChangeVelocity, GravityRotationSmoothTime); gravityVerticalAngleDelta = Mathf.SmoothDamp( gravityVerticalAngleDelta, Input.GetAxis("Gravity vertical"), ref gravityVerticalChangeVelocity, GravityRotationSmoothTime); if (Input.GetAction("Jump")) { Jump(); } if (Input.GetAction("Reset gravity")) { SetGravityToGroundNormal(); } if (Input.GetKeyDown(KeyboardKeys.C)) { Screen.CursorVisible = true; Screen.CursorLock = CursorLockMode.None; } }
public override void OnUpdate() { if (Input.GetAction("Fire") && Time.GameTime >= _timeToFire) { _timeToFire = Time.GameTime + 1.0f / _data.FireRate; var bullet = new RigidBody { Name = "Bullet", StaticFlags = StaticFlags.None, UseCCD = true, }; new StaticModel { Model = _data.BulletModel, Parent = bullet, StaticFlags = StaticFlags.None }; // Ideally you would also use raycasting to determine if something was hit new SphereCollider { Parent = bullet, StaticFlags = StaticFlags.None }; bullet.Transform = new Transform(BulletSpawnPoint.Position, Quaternion.Identity, _data.BulletScale); Level.SpawnActor(bullet); bullet.LinearVelocity = BulletSpawnPoint.Direction * _data.BulletVelocity; Destroy(bullet, _data.BulletLifetime); } }
public override void OnFixedUpdate() { // Camera Rotation { // Get mouse axis values and clamp pitch _yaw += Input.GetAxis("Mouse X") * MouseSensitivity * Time.DeltaTime; // H _pitch += Input.GetAxis("Mouse Y") * MouseSensitivity * Time.DeltaTime; // V _pitch = Mathf.Clamp(_pitch, PitchMinMax.X, PitchMinMax.Y); // The camera's parent should be another actor, like a spring arm for instance CameraView.Parent.Orientation = Quaternion.Lerp(CameraView.Parent.Orientation, Quaternion.Euler(_pitch, _yaw, 0), Time.DeltaTime * CameraLag); CharacterObj.Orientation = Quaternion.Euler(0, _yaw, 0); // When right clicking, zoom in or out if (Input.GetAction("Aim")) { CameraView.FieldOfView = Mathf.Lerp(CameraView.FieldOfView, FOVZoom, Time.DeltaTime * 5f); } else { CameraView.FieldOfView = Mathf.Lerp(CameraView.FieldOfView, _defaultFov, Time.DeltaTime * 5f); } } // Character Movement { // If the character is grounded we just set it to 0, avoiding constantly adding to Y if (_controller.IsGrounded) { _velocity.Y = 0f; } // Get input axes var inputH = Input.GetAxis("Horizontal"); var inputV = Input.GetAxis("Vertical"); // Apply movement towards the camera direction var movement = new Vector3(inputH, 0.0f, inputV); var movementDirection = CameraView.Transform.TransformDirection(movement); // Jump if the space bar is down, jump if (_controller.IsGrounded && Input.GetAction("Jump")) { _velocity.Y = Mathf.Sqrt(JumpStrength * -2f * Gravity); } // Apply gravity _velocity.Y += Gravity * Time.DeltaTime; movementDirection += (_velocity * 0.5f); // Apply controller movement, evaluate whether we are sprinting or not _controller.Move(movementDirection * Time.DeltaTime * (Input.GetAction("Sprint") ? SprintSpeed : Speed)); } }
public override void OnUpdate() { if (Input.GetAction("Space")) { Actor spawn = PrefabManager.SpawnPrefab(FireworkPrefab, Camera.MainCamera.Position); ParticleEffect fireworkFX = spawn.As <ParticleEffect>(); Color selectedColor = Colors[random.Next(0, Colors.Length)]; fireworkFX.SetParameterValue("Fireworks_Sphere", "Fireworks Color", selectedColor); fireworkFX.SetParameterValue("Fireworks_Inner", "Fireworks Color", selectedColor); Destroy(spawn, 12); } }
private void HandleFire() { var fireInput = Input.GetAction("Fire"); if (fireInput) { var bullet = _bulletPool.Rent(); Action returnBullet = async() => { await Task.Delay(TimeSpan.FromSeconds(2)); _bulletPool.Return(bullet); }; returnBullet(); bullet.Actor.Position = Actor.Position + _bulletOffset; var rigidbody = bullet.Actor.As <RigidBody>(); rigidbody.LinearVelocity = Actor.Direction * _bulletSpeed; } }