- Home /
Moving rigidbody upwards
I know there are mulitple threads about this and I've been through almost every one of them for hours now, but either the solution doesn't work (the object will not move at all) or the code just comes up with an error.
I am trying to move a rigidbody object quickly up by clicking 1 on the keyboard (not instantly, just quickly), and then come back down to where it was, although I am having a lot of trouble doing so. Honestly, I don't have much code to start with, but this is what I've done so far.
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
}
}
Any help would be greatly appreciated as I'm new to all this.
Answer by mbro514 · Sep 05, 2020 at 04:00 PM
Try this:
float jumpSpeed = 5; //It could be any number that you need.
Rigidbody rb = GetComponent<Rigidbody>();
void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
rb.velocity = Vector3.up * jumpSpeed;
}
}
Your answer
Follow this Question
Related Questions
Restrict a Players Movement Up a Slope 1 Answer
Rigidbody movement conflict? 1 Answer
Convert rigidbody velocity to home in on target when it gets close 1 Answer
How to make a gamebject wiggle slowly as it moves forward ? 1 Answer
How to make an object moving in a certain direction, move in specific steps like 0.1f 1 Answer