- Home /
My ball stops bounching at certain hight
I have a movement script, and a 2d physic material attached to my sprite ball. The material does so it constantly bounches without stopping. But the problem is, it only can jump to a certain point on the y axis. for example when i jump on a platform which is higher than the previous it doesen't jump that high anymore only to that point on the y axis. How can i fix this?
Answer by diegzumillo · Nov 25, 2013 at 12:09 PM
If I understand what you are describing, this is the intended behavior of a physics object. Jumping higher would be like creating energy from thin air :)
My suggestion is: don't use a bouncy material! in fact, use a material that completes eliminates bouncing. Then you add force at each impact directly from script. Each time the ball touches the ground, you apply an F amount of force upwards. I think this would get you the effect you want.
Okay so im new to scripting and started 10 days ago. But i managed to make a movement script in a previous project. I took the jump from that script and made some few modifications. But the ball seems to ''lag'' alot.
transform.Translate(Vector3.up jumpSpeed Time.deltaTime);
Physics.gravity = Vector3(0, -30, 0);
}
}
Oh, that's because you're using translate() on a rigidbody. You should avoid that. Use Rigidbody.AddForce( direction *intensity ) (look at the documentation for the correct syntax)
I don't know if this is correct:
rigidbody.AddForce (0, 50, 0); } Also, its a 2d rigidbody attached to my ball, so it says: $$anonymous$$issingComponentException: There is no 'Rigidbody' attached to the "Ball"function FixedUpdate () {
From what I gathered in your question, your ball has a rigidbody2d attached, so you should use Rigidbody2D.AddForce. I know it may sound a little confusing but things will become clear with time and practice. physics and physics2d are pretty much equivalent but are different components.
Now in order for you to apply force only when it impacts the floor, I would suggest also looking up the OnCollisionEnter2D function. Here's a link: http://docs.unity3d.com/Documentation/ScriptReference/Collider2D.OnCollisionEnter2D.html
Yeah it does sound confusing :-)! But im learning, not fast but im learning! So i combined the scripts to this:
function OnCollisionEnter2D(coll: Collision2D) {
if (coll.gameObject.tag == "Ground")
rigidbody2D.AddForce(Vector3.up * 10);
}
But as you probably can see it does not work ..
Your answer
Follow this Question
Related Questions
Sphere get stuck in floor and fails to jump? 1 Answer
How can I make a physics object jump a given height on collision regardless of current velocity? 1 Answer
Interpolate problem? Jump isn't smooth... 1 Answer
Hinge Joint Segments rotating offscreen 0 Answers
Keep Horizontal Momentum after Jump 2 Answers