- Home /
Question by
virtualproz · Apr 23, 2018 at 07:09 AM ·
physicsrigidbodyjumpingforce
Jump forward then back initial position
private Rigidbody rg;
public float gravity;
public float Jumpvelocity;
public float forwardVeocity;
// Use this for initialization
void Start () {
rg = GetComponent<Rigidbody>();
Physics.gravity = new Vector3(0, -gravity, -3);
}
// Update is called once per frame
void FixedUpdate () {
if(Mathf.Sign(rg.velocity.y) ==-1f){
transform.position = new Vector3(0, transform.position.y, 0);
}
}
private void OnCollisionEnter(Collision collision)
{
rg.velocity=new Vector3(0, Jumpvelocity, forwardVeocity);
}
}
here is my code that my trying to achieve this effect
As you can see that in gif, ball jump one disk to another disk but not collided with upper disk.how to make this jump, ball jump in y position and also in forward direction and then back to initial position on z..thanks in advance. @
webpnet-gifmaker.gif
(449.9 kB)
Comment
Your answer
Follow this Question
Related Questions
Returning a rigidbody back to its original x and z rotations through physics forces. 2 Answers
Get result (force & torque) of AddForceAtPosition? 2 Answers
Why is force only being added in the same direction? 1 Answer
How to get Satisfying Collision Physics 1 Answer
How to make a object jump constantly at y and move to the next position to z (perfectly) 0 Answers