Home Game Development 2nd – How to calculate the publish Rigidbody2D velocity vector earlier than making use of a selected pressure in Unity?

2nd – How to calculate the publish Rigidbody2D velocity vector earlier than making use of a selected pressure in Unity?

0
2nd – How to calculate the publish Rigidbody2D velocity vector earlier than making use of a selected pressure in Unity?

[ad_1]

I’m attempting to implement an area rocket in 2D. Whenever the participant presses a button, a continuing pressure (Both vertical and horizontal) is being added to that rocket. What I need to add is a most pace, the rocket cant exceed because the rocket will proceed accelerating to infinity. The participant may select to not speed up, which might result in the rocket beginning to fall down resulting from gravity. Thus, I cant simply Clamp the rigidbody.velocity of the rocket every time the magnitude of it exceeds max pace as it can additionally restrict the autumn velocity which isn’t as restricted. Thus, I’m attempting to foretell whether or not the participant will exceed the utmost velocity when attempting to speed up, so as to not add the pressure.

So far, I’ve tried doing this however the velocity vector doesn’t appear to alter instantly, so vel is the same as postVel:

Vector2 vel = rigidbody.velocity;
rigidbody.AddRelativeForce(Force); // Add pressure
Vector2 postVel = rigidbody.velocity;
rigidbody.AddRelativeForce(-Force); // Undo pressure

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here