- Home /
Rigidbody, jumping and gravity help
Hi,
I'm making a small 2d game where you start on a small platform in the center of the screen with 4 other platforms, 1 in each corner. The aim of the game is to collect fruit while avoiding falling rocks.
I need help with a couple things.
I need help with adding the jump code.
I want to have the rocks fall from the top of the screen slowly then hit a collider that makes them speed up.
This is my current code for moving:
public int speed = 5;
float moveInput = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
transform.Translate(moveInput, 0, 0);
//Restrict the x movement between 2 values
if (transform.position.x <= 1086.0f || transform.position.x >= 1104.0f)
{
// Clamp between min -2.5 and max 2.5
float xPos = Mathf.Clamp(transform.position.x, 1086.0f, 1104.0f);
transform.position = new Vector3(xPos, transform.position.y,
transform.position.z);
}
Thanks in advance.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613095736im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Rigidbody--Addforce on a Spherical Platform(A Globe) 2 Answers
Make A Cube 'Sticky' 4 Answers
Rigidbody AddForce/Velocity & gravity - mysterious interference 1 Answer
Rigidbody2D Grounded 4 Answers
Check if Rigidbody collider is grounded 3 Answers