0
\$\begingroup\$

Unity provides a cool physics engine for game development and I want to utilize it in my game.

Shorter version

I want to use physics engine for everything else other than character movement because trying to use physics engine for player movement doesn't yield the perfectmovement speed that I want; move x units per second.

If I use physics engine for character movement, it gets complicated. I would rather just add "moved distance" to the position to have things done simple. Is doing something like this wrong? All the learning sources I read recommend to use physics engine for movement if the game incorporates physics engine. I am nervous; am I wrong?

Longer version

The following description is where I use "physics", why I need physics engine.

In my game a player fires a bullet. When enemies collide with bullet, they get pushed back slightly. A strong blast can push enemies far back so that they even bounce back from hitting wall.

A recommend, a proper way, I was told, to utilize this physics engine for character movement is to add force to the direction I want to move.

But doing so(adding force to the direction I want to move) will result in truck-like; slowly warming up by adding velocity. To avoid "truck like movement" I was told to apply greater force at the beginning. Doing so result in change in velocity like the below picture.

enter image description here

However problem is not over yet, you must consider a situation where you change direction of movement while the character is running.

If you started to move backward, all of the sudden while running forward, you will need to slow down forward movement burn velocity by adding backward force. Thus rotation burns velocity.

So a solution is to find out perpendicular velocity to your desired direction, then find out needed amount of force to "burn off" the undesired velocity.

This seems way too complicated for a character to simply move around. I would rather just move character to desired direction by simply adding "constant X distance" to the character's position.

But I can't find a source of example where it utilizes both "simple movement by directly adding moved distance to the position" and "using physics engine for the game". All the sources of learning(using Unity physics) I find say use this complicated way of having character to move around. I wonder is there a reason why people don't just add moved distance to the position?

\$\endgroup\$
1
\$\begingroup\$

AFAIK the standard way of doing things in Unity is to assign a (non physical) Character Controller to your player. The character controller just sets the velocity of a body with some simple rules (exactly as you want). Collisions with physical objects are faked by treating the character as a kinematic object that can't be affected by forces.

This can lead to some undesirable results, such as non-physical interactions between your player and physics objects. For instance, if your player is colliding with a dynamic physical object wedged in a static door, the fact that the player doesn't obey Newton's third law means that the dynamic object will get pushed into the static objects, resulting in physics glitches like teleports or very large forces.

To avoid things like this, you can force the character to maintain Newton's laws and behave as a dynamic object, but, as you say, it makes the character much more difficult to control.

\$\endgroup\$
0
\$\begingroup\$

I'm not entirely certain this will help with your physics problem, but I remember reading about two different types of force options when you use AddForce. One adds a ramping force and the other is an instantaneous impulse force. Might be worth reading into. :)

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.