- Home /
Sphere behaves strange by jumping on diagonal Plattforms or at terrain
Hey, im using this code:
public int lifepoints;
public float speed;
public float jumpheight;
private float h;
private Rigidbody rb;
public bool grounded;
void Start () {
rb = GetComponent<Rigidbody>();
}
//Grounded
void OnCollisionEnter(Collision other)
{
if(other.gameObject.tag == "Plattform")
{
grounded = true;
}
}
void OnCollisionStay(Collision other)
{
if (other.gameObject.tag == "Plattform" && grounded == false)
{
grounded = true;
}
}
void OnCollisionExit(Collision other)
{
grounded = false;
}
void FixedUpdate ()
{
/* ************Movements*************/
// Move
h = Input.GetAxis("Horizontal");
Vector3 move = new Vector3(h, 0, 0);
rb.AddForce(move * speed);
// Jump
if (Input.GetButtonDown("Jump") && grounded)
{
rb.AddForce(0,jumpheight,0);
}
}
}
Grounded works pretty well, thats not the problem. The problem is, if my sphere is on a horizontal plattform without any rotation it works like it should. But if the sphere is on a diagonal plattform it sometimes jumps as twice as high as it usally does and should. This happens aswell if the sphere felt down on terrain under the diagonal Plattform.
I already tried different forcemodes and tried to multiply with Time.DeltaTime. Both did not really work.
Any ideas?
Maybe its not the code i dont know.
And im not sure but seems this first happend after patch 5.5
Help would be Great! Thanks!
Your answer
Follow this Question
Related Questions
AddForce to sphere 1 Answer
Marble refuses to jump sometimes 3 Answers
re-orienting velocity 1 Answer
addforce jump sometimes long,sometimes short 1 Answer
Rotate around object then leave at realistic angle 0 Answers