Rotate object only on player input

I’m creating a kart game with the go kart being pedal powered and so far I have a script that allows me to rotate the pedals when I start the game and that’s all good.

but what I want to do is to be able to only have them rotate once I start moving the kart.

This is the pedal script I have working at the moment

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PedalScript : MonoBehaviour {
     public float rotationSpeed = 10f;
     public Transform leftPedal, rightPedal;
     // Use this for initialization
     void Start () {
        
     }
    
     // Update is called once per frame
     void Update () {
         transform.Rotate (Vector3.right * Time.deltaTime * rotationSpeed);
         leftPedal.rotation = Quaternion.LookRotation (Vector3.right);
         rightPedal.rotation = Quaternion.LookRotation (Vector3.right);
     }
}

This is the car moment script

using System.Collections;
using UnityEngine;
public class Car : MonoBehaviour
{
     public float maxTorque = 5000f;
     public float speed;
     public Transform centerofMass;
     public WheelCollider[] wheelColliders = new WheelCollider[4];
     public Transform[] tireMeshes = new Transform[4];
     private Rigidbody m_rigidBody;
     void Start()
     {
         m_rigidBody = GetComponent<Rigidbody>();
         m_rigidBody.centerOfMass = centerofMass.localPosition;
     }
     void Update()
     {
         UpdateMeshesPositions();
     }
     void FixedUpdate()
     {
         float steer = Input.GetAxis ("Horizontal");
         float accelrate = Input.GetAxis ("Vertical");
         float finalAngle = steer * 45f;
         wheelColliders [0].steerAngle = finalAngle;
         wheelColliders [1].steerAngle = finalAngle;
         for (int i = 0; i < 4; i++)
         {
             wheelColliders[i].motorTorque = accelrate * maxTorque;
         }
     }
     void UpdateMeshesPositions()
     {
         for(int i = 0; i < 4; i++)
         {
             Quaternion quat;
             Vector3 pos;
             wheelColliders[i].GetWorldPose(out pos, out quat);
             tireMeshes[i].position = pos;
             tireMeshes[i].rotation = quat;
         }
     }
}

Bump!!!

If I understand you correctly, you want to give the impression that you’re pushing the pedal when you’re accelerating and releasing the pedal when you lift off the gas?

If so, may I suggest the following:

  1. The pedal script has “up” and “down” rotations. That is, the “up” rotation should be used when the kart is sitting idle, and “down” is when the pedal is fully pressed.

  2. Use Quaternion.RotateTowards to update the pedal’s current rotation between the up and down rotations based on whether you’re accelerating or not.

thanks for that i’ll give it a go