- Home /
Frictionless physics
We are trying to create an educational game that only has very basic physics. Friction should be rejected. But somehow, objects still slow down when we put them in a half-pipe of planes.
Also, colliding two objects against one another will stop them both. As in: they absorb all energy, instead of bouncing back.
This are both two phenomenons that I cannot think of with my basic physics knowledge.
So my general question is: How do I make a physics system with the rigid bodies in unity that will keep all energy during collisions, instead of stopping the objects?
EDIT:
It seems that what I'm doing with the physics is not exactly how it works in physics. The problem is: I try to let my ball roll from a slope. The sharp angle that is made with the ground makes the ball lose energy. This is actually quite logical.
So I'm actually looking for a way to keep all energy in the ball when colliding against a wall.
I should warn you that Unity's physics engine is hardly what I would call 'educational'!
Answer by jtbentley · Oct 11, 2011 at 12:46 AM
As well as making the physics material and setting the bouncyness to a high value (1 will do crazy things), you need to remove drag from the equation, as this will make everything slow down. This is done on the rigidbody itself, not on the physic material.
Angular drag might also need to be tweaked, but if you don't (especially in a half pipe) have any, it might go absolute beserk after a few trips around the pipe :)
Yes I did that, but it's not what I'm looking for. I already made a frictionless material, but it doesn't fix my problem. See updated question.
Based on your edited question, sounds to me like you'll be forcing a velocity onto the ball with script, since it's not likely going to behave how you want it to otherwise.
Your comment is actually the correct answer. I created a script that maintains the speed of the object by adding some force in the direction of the tangent of my hill. It works perfect and contains a lot of cross-products, but it does do as I want. There is no energy lost when colliding anymore.
^ $$anonymous$$arnix, would you share your code with me? I am trying to achieve the same type of physics, but I don't know where to start with program$$anonymous$$g this scrape/drag nullifying script
Answer by Ludiares.du · Sep 19, 2011 at 07:31 PM
Create a physics material, set its friction to 0 and its bouncyness to 1
The bounciness is a bit scary. A bouncing object will obtain a greater height as where it has been dropped during a couple of bounces.
Write a script to lock the speed of a moving rigidbody to a maximum value.
Answer by Enniwhere · Jul 14, 2014 at 11:02 AM
I had the exact same problem, and I've found a somewhat simple way of guaranteeing the required behavior. I know it's an old post, but someone might get the same problem at some point. I figured, that what I really needed was energy conservation, since my ball lost energy in each collision. So what I did was use that fact that height, mass and other physical variables were already given courtesy of the fantastic physics engine, and I calculated my ball's total and potential energy at the start, and set the kinetic energy as required. The following short script seems to guarantee energy conservation.
public class EnergyConservationMovement : MonoBehaviour {
public Transform cannon;
private float speed;
private float totalEnergy;
private float potentialEnergy;
private float kineticEnergy;
// Use this for initialization
void Start () {
speed = cannon.GetComponent<Cannon> ().velocity;
potentialEnergy = rigidbody.mass * 9.82f * transform.position.y;
kineticEnergy = 0.5f * rigidbody.mass * Mathf.Pow (speed, 2);
totalEnergy = potentialEnergy + kineticEnergy;
}
// Update is called once per frame
void Update () {
potentialEnergy = rigidbody.mass * 9.82f * transform.position.y;
kineticEnergy = totalEnergy - potentialEnergy;
speed = Mathf.Sqrt (kineticEnergy * 2 * rigidbody.mass);
rigidbody.velocity = rigidbody.velocity.normalized * speed;
}
}
The cannon is the thing firing my ball, so just replace it with some other source of velocity or simply 0, if you want to start out with no speed.
Your answer
Follow this Question
Related Questions
Angular Friction 0 Answers
How to make moving objects stack, without sliding over each other? 0 Answers
Calculating required force for pushing a body to a desired position at once 0 Answers
What is the appropriate value of Friction Direction 2? 1 Answer
How can I change friction of a Physic material in script? 1 Answer