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'!
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.
^ Marnix, 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 programming this scrape/drag nullifying script
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.
I should warn you that Unity's physics engine is hardly what I would call 'educational'!
– syclamoth