Question by
TheScarred · Feb 13, 2020 at 02:36 PM ·
inputlerpinputmanageraccelerationsensitivity
How can I apply "sensitivity" in the new input system to lerp a Vector2 composite?
I want to be able to 'accelerate' the rotation and movement with the rotationInput from the input system, however it goes straight to -1 or 1, is there a defined way to do it if not maybe a workaround? Thank you all for your time!
using UnityEngine;
using UnityEngine.InputSystem;
public class Controller : MonoBehaviour
{
public TankSettings tank;
public InputMaster controls;
Vector2 rotationInput;
private void Awake()
{
controls = new InputMaster();
controls.Tank.Shoot.performed += ctx => Shoot();
controls.Tank.Rotation.performed += ctx => rotationInput = ctx.ReadValue<Vector2>();
}
private void OnEnable()
{
controls.Enable();
}
private void OnDisable()
{
controls.Disable();
}
// Start is called before the first frame update
void Start()
{
tank = ScriptableObject.CreateInstance<TankSettings>();
tank.hp = 100;
tank.speed = 5;
tank.turningSpeed = 50;
}
// Update is called once per frame
void Update()
{
if (rotationInput.x != 0)
Rotation(rotationInput.x);
if (rotationInput.y != 0)
Thrust(rotationInput.y);
}
void Rotation(float value)
{
transform.Rotate(new Vector3(0, value * tank.turningSpeed * Time.deltaTime, 0));
}
void Thrust(float value)
{
transform.Translate(new Vector3(0, 0, value * tank.speed * Time.deltaTime));
}
void Shoot()
{
Debug.Log("Boom!");
}
}
capture.png
(32.6 kB)
Comment
Answer by KokodokoGames · Jul 26, 2020 at 12:51 PM
I was able to get tweened values between 0 and 1 using Mathf.MoveTowards!
// input is 0 or 1
float inputValue = controls.Driving.Speed.ReadValue<float>();
// get value between 0 and 1
currentValue = Mathf.MoveTowards(inputValue, currentValue, 0.25f * Time.deltaTime);
// apply to transform
transform.Translate(Vector3.forward * Time.deltaTime * currentValue * speed);