Quick Start Guide
Eidolon.Newton2D
is a convenient utility provided by Eidolon, designed to simplify and enhance the usage of Unity Physics 2D. This static class offers a set of methods to streamline common operations on 2D rigidbodies, providing a more straightforward and expressive API for game developers.
1. Applying Force
Newton 2D’s ApplyForce
method simplifies the process of applying a force to a 2D rigidbody. Specify the direction and magnitude, and let Newton 2D handle the rest, making your code clean and efficient.
// Apply a force in a specified direction with a given magnitudeNewton2D.ApplyForce(rigidbody2D, new Vector2(1f, 0f), 10f);
2. Setting Velocity
With SetVelocity
, controlling the velocity of a 2D rigidbody becomes a breeze. Provide the new velocity, and Newton 2D takes care of the assignment, enhancing the readability of your code.
// Set the velocity of a 2D rigidbodyNewton2D.SetVelocity(rigidbody2D, new Vector2(5f, 2f));
3. Simulating a Jump
Simulating a jump is straightforward using Newton 2D’s Jump
method. Specify the rigidbody and the jump force, and watch your character soar. No need for complex calculations – just a simple, intuitive function.
// Simulate a jump by applying an upward forceNewton2D.Jump(rigidbody2D, 20f);
4. Setting Constraints
The SetConstraints
method in Newton 2D offers a human-friendly approach to managing constraints on a 2D rigidbody. Easily freeze or unfreeze the X-axis, Y-axis, and rotation with clear and concise parameters.
// Set constraints on a 2D rigidbodyNewton2D.SetConstraints(rigidbody2D, true, false, true);
5. Applying Torque
Applying torque to a 2D rigidbody is made simple with the ApplyTorque
method. Provide the rigidbody and torque value, and Newton 2D handles the rest, making your code expressive and easy to understand.
// Apply torque to a 2D rigidbodyNewton2D.ApplyTorque(rigidbody2D, 5f);
6. Applying Linear Damping
Newton 2D’s ApplyLinearDamping
method allows you to apply linear damping to a 2D rigidbody effortlessly. Manage damping factors with clarity, enhancing the control and readability of your code.
// Apply linear damping to a 2D rigidbodyNewton2D.ApplyLinearDamping(rigidbody2D, 2f);
7. Applying Angular Damping
The ApplyAngularDamping
method in Newton 2D streamlines the application of angular damping to a 2D rigidbody. Set the damping factor easily, making your code clean and comprehensible.
// Apply angular damping to a 2D rigidbodyNewton2D.ApplyAngularDamping(rigidbody2D, 1f);
8. Applying Force at Position
Newton 2D’s ApplyForceAtPosition
method lets you apply force to a 2D rigidbody at a specific position with ease. Enhance the precision of your game physics without compromising on clarity.
// Apply a force to a 2D rigidbody at a specific positionNewton2D.ApplyForceAtPosition(rigidbody2D, new Vector2(2f, 1f), new Vector2(3f, 2f));
9. Applying Torque at Position
ApplyTorqueAtPosition
in Newton 2D enables precise torque application around a specific point on a 2D rigidbody. Fine-tune your game’s rotational dynamics without sacrificing readability.
// Apply torque to a 2D rigidbody around a specific pointNewton2D.ApplyTorqueAtPosition(rigidbody2D, 3f, new Vector2(1f, 2f));
10. Simulating Linear and Angular Drag
Newton 2D provides ApplyLinearDrag
and ApplyAngularDrag
methods, allowing you to simulate linear and angular drag effortlessly. Fine-tune your game’s drag effects with clear and concise functions.
// Apply linear drag to simulate linear dragNewton2D.ApplyLinearDrag(rigidbody2D, 0.1f);
// Apply angular drag to simulate rotational dragNewton2D.ApplyAngularDrag(rigidbody2D, 0.05f);
Conclusion
Newton 2D acts as your go-to companion for Unity Physics 2D, offering a more human-readable and convenient interface for handling common rigidbody operations. Whether you’re a seasoned developer or just starting, Newton 2D makes your code cleaner and your game physics interactions smoother. Happy coding! 🚀