コード例 #1
0
ファイル: Car.cs プロジェクト: tobhil98/MastersProject-AirSim
        public new void FixedUpdate()
        {
            // Debug.LogWarning("A warning assigned to this transform!");
            if (destroySelf_)
            {
                AirSimServer.vehicleList.Remove(transform);
                Destroy(gameObject);
            }
            if (isServerStarted)
            {
                if (resetVehicle)
                {
                    resetVehicle = false;
                    carData.Reset();
                    carControls.Reset();
                    rcData.Reset();
                    DataManager.SetToUnity(poseFromAirLib.position, ref position);
                    DataManager.SetToUnity(poseFromAirLib.orientation, ref rotation);
                    transform.position = position;
                    transform.rotation = rotation;
                    currentPose        = poseFromAirLib;
                    steering           = 0;
                    throttle           = 0;
                    footBreak          = 0;
                    handBrake          = 0;

                    var rb = GetComponent <Rigidbody>();
                    rb.constraints = RigidbodyConstraints.FreezeAll;
                    rb.constraints = RigidbodyConstraints.None;
                }
                else
                {
                    base.FixedUpdate();
                    if (isApiEnabled)
                    {
                        throttle  = carControls.throttle;
                        handBrake = carControls.handbrake ? 1 : 0;
                        footBreak = carControls.brake;
                        steering  = carControls.steering;
                    }
                    else
                    {
                        steering  = Input.GetAxis("Horizontal");
                        throttle  = Input.GetAxis("Vertical");
                        handBrake = Input.GetAxis("Jump");
                        footBreak = throttle;
                    }

                    carController.Move(steering, throttle, footBreak, handBrake);
                    carController.UpdateCarData(ref carData);
                    carData.throttle = throttle;
                    carData.brake    = footBreak;
                    carData.steering = steering;
                }
            }
        }
コード例 #2
0
ファイル: Car.cs プロジェクト: gardman/Simulator
        private new void FixedUpdate()
        {
            if (resetVehicle)
            {
                resetVehicle = false;
                carData.Reset();
                carControls.Reset();
                rcData.Reset();
                DataManager.SetToUnity(poseFromAirLib.position, ref position);
                DataManager.SetToUnity(poseFromAirLib.orientation, ref rotation);
                transform.position = position;
                transform.rotation = rotation;
                currentPose        = poseFromAirLib;
                steering           = 0;
                throttle           = 0;
                footBreak          = 0;
                handBrake          = 0;

                var rb = GetComponent <Rigidbody>();
                rb.constraints = RigidbodyConstraints.FreezeAll;
                rb.constraints = RigidbodyConstraints.None;
            }
            else
            {
                base.FixedUpdate();

                if (isApiEnabled)
                {
                    throttle  = carControls.throttle;
                    handBrake = carControls.handbrake ? 1 : 0;
                    footBreak = carControls.brake;
                    steering  = carControls.steering;
                }
                else
                {
                    steering  = Input.GetAxis("Horizontal");
                    throttle  = Input.GetAxis("Vertical");
                    handBrake = Input.GetAxis("Jump");
                    footBreak = throttle;
                }

                carController.Move(steering, throttle, footBreak, handBrake);
                carController.UpdateCarData(ref carData);
                carData.throttle = throttle;
                carData.brake    = footBreak;
                carData.steering = steering;
            }
        }
コード例 #3
0
        private new void FixedUpdate()
        {
            Debug.Log($"Car fixed update {Time.time}");
            if (isServerStarted)
            {
                if (resetVehicle)
                {
                    resetVehicle = false;
                    carData.Reset();
                    carControls.Reset();
                    rcData.Reset();
                    DataManager.SetToUnity(poseFromAirLib.position, ref position);
                    DataManager.SetToUnity(poseFromAirLib.orientation, ref rotation);
                    transform.position = position;
                    transform.rotation = rotation;
                    currentPose        = poseFromAirLib;
                    steering           = 0;
                    throttle           = 0;
                    footBreak          = 0;
                    handBrake          = 0;

                    var rb = GetComponent <Rigidbody>();
                    rb.constraints = RigidbodyConstraints.FreezeAll;
                    rb.constraints = RigidbodyConstraints.None;
                }
                else
                {
                    base.FixedUpdate();

                    if (isApiEnabled)
                    {
                        throttle  = carControls.throttle;
                        handBrake = carControls.handbrake ? 1 : 0;
                        footBreak = carControls.brake;
                        steering  = carControls.steering;
                    }
                    else
                    {
                        steering  = Input.GetAxis("Horizontal");
                        throttle  = Input.GetAxis("Vertical");
                        handBrake = Input.GetAxis("Jump");
                        footBreak = throttle;
                        Debug.Log($"Steering:{steering} throttle:{throttle} handbrake:{handBrake}");
                    }
                    if (tryOutrcData)
                    {
                        rcData.is_initialized = true;
                        rcData.is_valid       = true;
                        rcData.throttle       = throttle * 100;
                        rcData.yaw            = steering * 100;
                    }
                    else
                    {
                        carController.Move(steering, throttle, footBreak, handBrake);
                        carController.UpdateCarData(ref carData);
                        carData.throttle = throttle;
                        carData.brake    = footBreak;
                        carData.steering = steering;
                    }
                }
            }
        }