private void Update() { if (UI.PauseMenu.GamePaused || !ball.isLocalPlayer) { return; //Short circuit if paused } //GO FAST const float weight = 0.5f; var targetVector = GameInput.MovementVector(ball.CtrlType); rawDirection = Vector3.MoveTowards(rawDirection, targetVector, weight); Vector3 directionVector = rawDirection; if (directionVector != Vector3.zero) { //Modify direction vector to be more controller-friendly (And normalize it) var directionLength = directionVector.magnitude; directionVector = directionVector / directionLength; directionLength = Mathf.Min(1, directionLength); directionLength = directionLength * directionLength; directionVector = directionVector * directionLength; } directionVector = LookDirection * Quaternion.Euler(0f, 90f, 0) * directionVector; //Multiply vector by camera rotation ball.DirectionVector = directionVector; //BRAKE FAST ball.Brake = GameInput.IsBraking(ball.CtrlType); //JUMP FAST if (GameInput.IsJumping(ball.CtrlType)) { if (!hasJumped) { ball.Jump(); hasJumped = true; } } else { if (hasJumped) { hasJumped = false; } } //Switch Camera Fast if (GameInput.IsSwitchingCameras(ball.CtrlType) && ball.CanMove) { ball.SwitchCameraBall(); } // //RESPAWN FAST // if (GameInput.IsRespawning(ball.CtrlType) && ball.CanMove) // { // ball.RequestRespawn(); // } }
private void Update() { var bci = Target.GetComponent <BallControlInput>(); if (bci) { bci.LookDirection = transform.rotation * Quaternion.Euler(0, -90, 0); } var bciLocal = Target.GetComponent <BallControlInputLocal>(); if (bciLocal) { bciLocal.LookDirection = transform.rotation * Quaternion.Euler(0, -90, 0); } //Mouse look if (UseMouse) { if (Input.GetMouseButtonDown(0) && !GameInput.KeyboardDisabled && !UI.PauseMenu.GamePaused) { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; } if (Input.GetKeyDown(KeyCode.LeftAlt)) { Cursor.lockState = CursorLockMode.None; Cursor.visible = true; } if (Cursor.lockState == CursorLockMode.Locked && CtrlType == ControlType.Keyboard) { // Debug.Log("KEyboard Gura camara"); float yAxisMove = Input.GetAxis("Mouse Y") * sensitivityMouse; ytargetRotation += -yAxisMove; float xAxisMove = Input.GetAxis("Mouse X") * sensitivityMouse; xtargetRotation += xAxisMove; } } //Keyboard controls var cameraVector = GameInput.CameraVector(CtrlType); /*if (cameraVector.x < 0) * xtargetRotation -= 20 * sensitivityKeyboard * Time.deltaTime; * if (cameraVector.x > 0) * xtargetRotation += 20 * sensitivityKeyboard * Time.deltaTime; * if (cameraVector.y > 0) * ytargetRotation -= 20 * sensitivityKeyboard * Time.deltaTime; * if (cameraVector.y < 0) * ytargetRotation += 20 * sensitivityKeyboard * Time.deltaTime;*/ xtargetRotation += cameraVector.x * 20 * sensitivityKeyboard * Time.deltaTime; ytargetRotation -= cameraVector.y * 20 * sensitivityKeyboard * Time.deltaTime; ytargetRotation = Mathf.Clamp(ytargetRotation, yMin, yMax); xtargetRotation = xtargetRotation % 360; ytargetRotation = ytargetRotation % 360; transform.localRotation = Quaternion.Lerp(transform.localRotation, Quaternion.Euler(0, xtargetRotation, ytargetRotation), Time.deltaTime * 10 / smoothing); }
private void Update() { if (type == BallType.AI && isServer && !isClient) { //Rolling sounds if (grounded) { float rollSpd = Mathf.Clamp(rb.angularVelocity.magnitude / 230, 0, 16); float vel = (-128f + rb.velocity.magnitude) / 256; //Start at 128 fph, end at 256 vel = Mathf.Clamp(vel, 0, 1); if (sounds.Roll != null) { sounds.Roll.pitch = Mathf.Max(rollSpd, 0.8f); sounds.Roll.volume = Mathf.Min(rollSpd, 1); } if (sounds.SpeedNoise != null) { sounds.SpeedNoise.pitch = 0.8f + vel; sounds.SpeedNoise.volume = vel; } } else { //Fade sounds out when in the air if (sounds.Roll != null && sounds.Roll.volume > 0) { sounds.Roll.volume = Mathf.Max(0, sounds.Roll.volume - 0.2f); } if (sounds.SpeedNoise != null && sounds.SpeedNoise.volume > 0) { sounds.SpeedNoise.volume = Mathf.Max(0, sounds.SpeedNoise.volume - 0.01f); } } //Grounded timer if (groundedTimer > 0) { groundedTimer = Mathf.Max(0, groundedTimer - Time.deltaTime); if (groundedTimer <= 0) { grounded = false; Up = Vector3.up; } } //Smoke if (smoke != null) { smoke.grounded = grounded; } } if (!isLocalPlayer) { return; } if (GameInput.IsRespawning(ctrlType)) { if (NetworkManager.singleton.GetComponent <SanicNetworkManager>().isSpawning != true) { if (!isServer) { CmdToggleReady(Sanicball.Data.ActiveData.GameSettings.nickname); LobbyReferences.Active.CountdownField.enabled = true; LobbyReferences.Active.CountdownField.text = "Wait Until the Race Begin..."; } else { Debug.Log("Ready ?? + " + isServer); if (NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager != null && (NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.serverConnections + 1) > 1) { // for( int i =0 ; i< NetworkServer.connections.Count; i ++ ){ for (int i = 0; i < NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.Players.Count; i++) { if (this.connectionToClient.connectionId == NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.Players[i].ConnectionSelf.connectionId) { NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.Players[i].ReadyToRace = !NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.Players[i].ReadyToRace; if (NetworkManager.singleton.GetComponent <SanicNetworkManager>().matchManager.Players[i].ReadyToRace) { ChatRelayer.Instance.SetLogMessage(Sanicball.Data.ActiveData.GameSettings.nickname + " is READY to RACE"); } else { ChatRelayer.Instance.SetLogMessage(Sanicball.Data.ActiveData.GameSettings.nickname + " is NOT READY to RACE"); } } } } } } else { if (this.CanMove) { if (isServer) { this.RequestRespawn(); } else { CmdRequestSpawn(currentCheckPoin, netId); } } } } //Rolling sounds if (grounded) { float rollSpd = Mathf.Clamp(rb.angularVelocity.magnitude / 230, 0, 16); float vel = (-128f + rb.velocity.magnitude) / 256; //Start at 128 fph, end at 256 vel = Mathf.Clamp(vel, 0, 1); if (sounds.Roll != null) { sounds.Roll.pitch = Mathf.Max(rollSpd, 0.8f); sounds.Roll.volume = Mathf.Min(rollSpd, 1); } if (sounds.SpeedNoise != null) { sounds.SpeedNoise.pitch = 0.8f + vel; sounds.SpeedNoise.volume = vel; } } else { //Fade sounds out when in the air if (sounds.Roll != null && sounds.Roll.volume > 0) { sounds.Roll.volume = Mathf.Max(0, sounds.Roll.volume - 0.2f); } if (sounds.SpeedNoise != null && sounds.SpeedNoise.volume > 0) { sounds.SpeedNoise.volume = Mathf.Max(0, sounds.SpeedNoise.volume - 0.01f); } } //Grounded timer if (groundedTimer > 0) { groundedTimer = Mathf.Max(0, groundedTimer - Time.deltaTime); if (groundedTimer <= 0) { grounded = false; Up = Vector3.up; } } //Smoke if (smoke != null) { smoke.grounded = grounded; } }
private void Update() { //Input var targetDirectionOffset = Quaternion.identity; Vector2 camVector = GameInput.CameraVector(CtrlType); Vector3 orientedCamVector = new Vector3(camVector.x, 0, camVector.y); if (orientedCamVector != Vector3.zero) { Quaternion camQuaternion = Quaternion.Slerp(Quaternion.identity, Quaternion.LookRotation(orientedCamVector), orientedCamVector.magnitude); targetDirectionOffset = camQuaternion; } if (Target != null) { //Rotate the camera towards the velocity of the rigidbody //Set the up vector, and make it lerp towards the target's up vector if the target has a Ball Vector3 targetUp = Vector3.up; Ball bc = Target.GetComponent <Ball>(); if (bc) { targetUp = bc.Up; } BallLocal bcLocal = Target.GetComponent <BallLocal>(); if (bcLocal) { targetUp = bcLocal.Up; } up = Vector3.Lerp(up, targetUp, Time.deltaTime * 10); //Based on how fast the target is moving, create a rotation bending towards its velocity. Quaternion towardsVelocity = (Target.velocity != Vector3.zero) ? Quaternion.LookRotation(Target.velocity, up) : Quaternion.identity; const float maxTrans = 20f; Quaternion finalTargetDir = Quaternion.Slerp(currentDirection, towardsVelocity, Mathf.Max(0, Mathf.Min(-10 + Target.velocity.magnitude, maxTrans) / maxTrans)); //Lerp towards the final rotation currentDirection = Quaternion.Slerp(currentDirection, finalTargetDir, Time.deltaTime * 2); //Look for a BallControlInput and set its look direction BallControlInput bci = Target.GetComponent <BallControlInput>(); if (bci != null) { bci.LookDirection = currentDirection; } BallControlInputLocal bciLocal = Target.GetComponent <BallControlInputLocal>(); if (bciLocal != null) { bciLocal.LookDirection = currentDirection; } //Set camera FOV to get higher with more velocity AttachedCamera.fieldOfView = Mathf.Lerp(AttachedCamera.fieldOfView, Mathf.Min(60f + (Target.velocity.magnitude), 100f), Time.deltaTime * 4); currentDirectionWithOffset = Quaternion.Slerp(currentDirectionWithOffset, currentDirection * targetDirectionOffset, Time.deltaTime * 2); transform.position = Target.transform.position + Vector3.up * orbitHeight + currentDirectionWithOffset * (Vector3.back * orbitDistance); transform.rotation = currentDirectionWithOffset; } }