Advertisement
DugganSC

Tank Control Code

Feb 12th, 2025
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TankControls : MonoBehaviour
  6. {
  7.     [SerializeField] WheelCollider[] _leftWheels;
  8.     [SerializeField] WheelCollider[] _rightWheels;
  9.  
  10.     TankControlInputs _tankControlInputs;
  11.     [SerializeField] private float _tankTorque = 5000f;
  12.  
  13.     private void Start()
  14.     {
  15.         _tankControlInputs = new TankControlInputs();
  16.         _tankControlInputs.Tank.Enable();
  17.     }
  18.  
  19.     private void Update()
  20.     {
  21.         float _lTreadInput = _tankControlInputs.Tank.LeftTread.ReadValue<float>();
  22.         float _rTreadInput = _tankControlInputs.Tank.RightTread.ReadValue<float>();
  23.  
  24.         Debug.Log($"L: {_lTreadInput} R: {_rTreadInput}");
  25.  
  26.         foreach (var wheel in _leftWheels)
  27.         {
  28.             wheel.motorTorque = _lTreadInput * _tankTorque;
  29.         }
  30.  
  31.         foreach (var wheel in _rightWheels)
  32.         {
  33.             wheel.motorTorque = _rTreadInput * _tankTorque;
  34.         }
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement