public void FixedUpdate() { if (PhotonEngine.Instance.IsServer) { _networkInterface.RequestClientInputs(); UpdateInputs(); _networkInterface.SendServerTransform(); } else { _networkInterface.RequestServerTransform(); UpdateTransform(); if (_networkInterface.IsLocalPeer) { GetPlayerInputs(); } _networkInterface.SendClientInputs(_powerInput, _turnInput, _isJumping); } _hoverMotor.Move(_powerInput, _turnInput); if (_isJumping) { _hoverMotor.Jump(); } }
void Update() { float xMov = Input.GetAxisRaw(inputSettings.xMovAxis); float zMov = Input.GetAxisRaw(inputSettings.zMovAxis); motor.Move(xMov, zMov); if (Input.GetButtonDown(inputSettings.sprintButton)) { motor.Boost(true); } if (Input.GetButtonUp(inputSettings.sprintButton)) { motor.Boost(false); } float xCam = Input.GetAxisRaw(inputSettings.xLookAxis); float yCam = Input.GetAxisRaw(inputSettings.yLookAxis); motor.Turn(xCam, yCam); if (Input.GetButtonDown(inputSettings.rightMouse)) { this.PostNotification(ControllerChangeNotification, null); } }
public void FixedUpdate() { GetPlayerInputs(); _hoverMotor.Move(_powerInput, _turnInput); if (_isJumping) { _hoverMotor.Jump(); } }
private void FixedUpdate() { float powerInput = Input.GetAxis("Vertical"); float turnInput = Input.GetAxis("Horizontal"); HoverCar.Move(powerInput, turnInput); if (Input.GetButtonDown("Jump")) { HoverCar.Jump(); } }
// Update is called once per frame void FixedUpdate() { if (_m_Target == null || !_m_Driving) { return; } Vector3 fwd = transform.forward; float desiredSpeed = _hoverMotor.MaxSpeed; // check out the angle of our target compared to the current direction of the car float approachingCornerAngle = Vector3.Angle(_m_Target.forward, fwd); // also consider the current amount we're turning, multiplied up and then compared in the same way as an upcoming corner angle float spinningAngle = _m_Rigidbody.angularVelocity.magnitude * _m_CautiousAngularVelocityFactor; // if it's different to our current angle, we need to be cautious (i.e. slow down) a certain amount float cautiousnessRequired = Mathf.InverseLerp(0, _m_CautiousMaxAngle, Mathf.Max(spinningAngle, approachingCornerAngle)); desiredSpeed = Mathf.Lerp(_hoverMotor.MaxSpeed, _hoverMotor.MaxSpeed * _m_CautiousSpeedFactor, cautiousnessRequired); // Evasive action due to collision with other cars: // our target position starts off as the 'real' target position Vector3 offsetTargetPos = _m_Target.position; // if are we currently taking evasive action to prevent being stuck against another car: if (Time.time < _m_AvoidOtherCarTime) { // slow down if necessary (if we were behind the other car when collision occured) desiredSpeed *= _m_AvoidOtherCarSlowdown; // and veer towards the side of our path-to-target that is away from the other car offsetTargetPos += _m_Target.right * _m_AvoidPathOffset; } else { // no need for evasive action, we can just wander across the path-to-target in a random way, // which can help prevent AI from seeming too uniform and robotic in their driving offsetTargetPos += _m_Target.right * (Mathf.PerlinNoise(Time.time * _m_LateralWanderSpeed, _m_RandomPerlin) * 2 - 1) * _m_LateralWanderDistance; } // use different sensitivity depending on whether accelerating or braking: float accelBrakeSensitivity = (desiredSpeed < _hoverMotor.CurrentSpeed) ? _m_BrakeSensitivity : _m_AccelSensitivity; // decide the actual amount of accel/brake input to achieve desired speed. float accel = Mathf.Clamp((desiredSpeed - _hoverMotor.CurrentSpeed) * accelBrakeSensitivity, -1, 1); // add acceleration 'wander', which also prevents AI from seeming too uniform and robotic in their driving // i.e. increasing the accel wander amount can introduce jostling and bumps between AI cars in a race accel *= (1 - _m_AccelWanderAmount) + (Mathf.PerlinNoise(Time.time * _m_AccelWanderSpeed, _m_RandomPerlin) * _m_AccelWanderAmount); // calculate the local-relative position of the target, to steer towards Vector3 localTarget = transform.InverseTransformPoint(offsetTargetPos); // work out the local angle towards the target float targetAngle = Mathf.Atan2(localTarget.x, localTarget.z) * Mathf.Rad2Deg; // get the amount of steering needed to aim the car towards the target float steer = Mathf.Clamp(targetAngle * _m_SteerSensitivity, -1, 1) * Mathf.Sign(_hoverMotor.CurrentSpeed); // feed input to the car controller. _hoverMotor.Move(-accel, steer); }