I have a script:
public float CharacterWalkSpeed;
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
{
if (rb.velocity<CharacterWalkSpeed)
{
rb.AddForce(transform.forward * CharacterWalkSpeed, ForceMode.Impulse);
}
and it’s assigned to a cube. What I want to happen when the up arrow or the w key is pressed, for there to be a specific amount of force (CharacterWalkSpeed) to be applied to the cube. However, if the amount of velocity is greater than my original speed, the force will stop being applied. The problem though is that the if (rb.velocity<CharacterWalkSpeed)
does not work. Once again, I’m trying to see if the objects velocity is less than the CharacterWalkSpeed.