Random loop rigidbody?
User presses key, force acts on rigidbody, rigidbody stops. User presses other key, other force acts on rigidbody, rigidbody stops.
public class thingBumps : MonoBehaviour {
public float thrust;
public Rigidbody rb;
void Start() {
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
rb.AddForce (transform.up * thrust, ForceMode.Impulse);
if (Input.GetKey(KeyCode.DownArrow))
rb.AddForce(-transform.up * thrust,ForceMode.Impulse);
}
}
I'm trying to make the first force (transform.up) occur in a loop, and at random times within a set range.
I have tried:
InvokeRepeating Invokes the method methodName in time seconds, then repeatedly every repeatRate seconds. A coroutine is a function that can suspend its execution (yield) until the given given YieldInstruction finishes.
and several other methods.
The code as I have it now does not allow me to use the DownArrow command. I am finding it difficult to work with two different commands in the same FixedUpdate.
I appreciate any advice. Thanks.
Your answer
Follow this Question
Related Questions
change rigidbodies in all objects to kinematic 1 Answer
How to Make A Character Stop At Wall? 0 Answers
Random.range game object destroying itself before reaching destroy position.Please help. 1 Answer
How do you fix a Rigidbody stopping quickly after the addforce stops being called? 1 Answer
Need help with snapping Prefab assets to grid in game 2 Answers