Hello,
I discover Unity for its 2D physics. I used to use Algodoo and I would like to make the same animation as the one you will find on the videos below. The result I get in Unity is less realistic than in Algodoo (The rotating object goes through some balls which are rigidbody ). Knowing the capabilities of Unity, I am sure it is possible to do better but I don’t know how. Thank you in advance for your advice!
(The object rotates thanks to a script “bouge”)
Algodoo result:
Unity result:
The script showing what you’re doing is as important as showing the configuration of components btw.
That said, the “Rotating_Platform” doesn’t have a Rigidbody2D so it’s an implicitly Static (non-moving) Box which means to get it to “move” or “rotate”, you’re just writing to the Transform. You should never, ever do this.
This isn’t physics, this is just instantly changing the Box (it’ll be recreated at the new position/rotation). This means it’ll appear overlapping stuff because that’s what you asked for; you never asked that it move through space.
If you want any movement of any kind in 2D Physics then use a Rigidbody2D and use its API to cause movement. Its role is to write to the Transform the results of the physics simulation.
So in short, to your platform, add a Rigidbody2D, set it to be Kinematic (so there’s no forces that affect it) and then use its API i.e. Rigidbody2D.MoveRotation or set its Rigidbody2D.angularVelocity (set the angular drag to zero if you’re doing this).
Thank you for your quick response.
I will look into it!
1 Like
Indeed it is much better.
Thanks a lot!
The script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rotation : MonoBehaviour
{
private Rigidbody2D rb2D;
public float revSpeed;
void Start()
{
rb2D = gameObject.GetComponent();
}
void FixedUpdate()
{
rb2D.MoveRotation(rb2D.rotation + revSpeed * Time.fixedDeltaTime);
}
}
1 Like