void Update() { //Calculate movement velocity as a 3D vector float _xMov = Input.GetAxisRaw("Horizontal"); float _zMov = Input.GetAxisRaw("Vertical"); Vector3 _movHorizontal = transform.right * _xMov; Vector3 _movVertical = transform.forward * _zMov; //Final movement vector Vector3 _velocity = (_movVertical + _movHorizontal).normalized * speed; //Apply movement motor.Move(_velocity); //Calculate rotation as a 3D vector (turning around) float _yRot = Input.GetAxisRaw("Mouse X"); Vector3 _rotation = new Vector3(0f, _yRot, 0f) * lookSensivity; //Apply rotation motor.Rotate(_rotation); //Calculate camera rotation as a 3D vector (turning around) float _xRot = Input.GetAxisRaw("Mouse Y"); Vector3 _cameraRotation = new Vector3(_xRot, 0f, 0f) * lookSensivity; //Apply camera rotation motor.RotateCamera(_cameraRotation); }
private void FixedUpdate() { float _xMov = Input.GetAxisRaw("Horizontal"); float _yMov = Input.GetAxisRaw("Vertical"); float _yRot = Input.GetAxisRaw("Mouse X"); float _xRot = Input.GetAxisRaw("Mouse Y"); float _cameraRotationX = _xRot * lookSensitivity; Vector3 _rotation = new Vector3(0f, _yRot, 0f) * lookSensitivity; Vector3 _movHorizontal = transform.right * _xMov; Vector3 _movVertical = transform.forward * _yMov; Vector3 _velocity = (_movHorizontal + _movVertical).normalized * speed; motor.Move(_velocity); motor.Rotate(_rotation); motor.RotateCamera(_cameraRotationX); //jump Vector3 _thrusterForce = Vector3.zero; // The avatar has the strengthh to jump if (Input.GetButton("Jump") && thrusterFuelAmount > 0f && ifJump == 1) { thrusterFuelAmount -= thrusterFuelBurnSpeed * Time.fixedDeltaTime; _thrusterForce = transform.up * thrusterForce; SetJointSettings(0f); ifFirst = 1; } else if (Input.GetButton("Jump")) // The avatar has no strength to jump { SetJointSettings(jointSpring); } else // The avatar stay to recover strength { thrusterFuelAmount += thrusterFuelBurnSpeed * Time.fixedDeltaTime; if (ifFirst == 1) { ifFirst = 0; SetJointSettings(jointSpring); } } SetJointAnchor(); thrusterFuelAmount = Mathf.Clamp(thrusterFuelAmount, 0f, thrusterFuelTotal); motor.ApplyThruster(_thrusterForce); }