ricardojmendez / UnitySteer

Steering, obstacle avoidance and path following behaviors for the Unity Game Engine
https://numergent.com/tags/unitysteer/
Other
1.2k stars 275 forks source link

About UnitySteer and Physics #54

Closed TCMOREIRA closed 5 years ago

TCMOREIRA commented 7 years ago

Introduction: First of all: Thank you so much for UnitySteer! It is great!

I'm working on a 2D Physics-based game with zero gravity (in space); My game will use Steering Behaviors heavily!

Issue: But I noticed that UnitySteer's Autonomous Vehicles conflict a little bit with Unity's Physics.

If I try to apply other forces externally (via some attached script for example), the Vehicle behaves strangely or the forces do not even apply.

This is most notable by the lack of Inertia. Since my game is in Space, this is really distracting.

Sometimes something collides with an Autonomous Vehicle and there's no Inertia from the Collision.

I also did an experiment where I would control an Autonomous Vehicle GameObject using WASD for Physics-Based movement:

Can you help me? Can you help me understand better the relationship between UnitySteer and Unity's Physics? Can you help me fix those mentioned issues?

Thank you for your time!

ricardojmendez commented 7 years ago

Hi,

There's no easy answer, since how physics are used and forced interpreted will likely depend on your game. I have myself used them more in games where the steering is not physics-based.

If you see function ApplySteeringForce in TickedVehicle, you'll notice that if the attached Rigidbody is not kinematic, then the vehicle will apply the force using Rigidbody.MovePosition. If this isn't enough for your case, then you may want to modify TickedVehicle (or create a subclass, although that function is currently not overridable) so that it interprets and applies the calculated forces in a game-specific manner.

Let me know if that helps. Cheers!

TCMOREIRA commented 7 years ago

I'm currently writing some other feature; However - I'll try to Modify TickedVehicle as soon as I get the chance! Thank you!

Then, I'll let you know what happened! =]

abdulazizali77 commented 5 years ago

Hi @ricardojmendez Thank you so much for UnitySteer Weve been trying out UnitySteer withh RBD2d dynamic and have been having similar issues (maybe) as @TCMOREIRA

Found a quick fix for it by changing the queue code from Update to FixedUpdate https://github.com/ricardojmendez/UnitySteer/blob/1a2404d50b911e4adab5c43ae92ec3e34de0ef2c/TickedPriorityQueue/UnityTickedQueue.cs#L132

ref: https://unity3d.com/learn/tutorials/modules/beginner/scripting/update-and-fixedupdate

Still playing around with it, not completely sure of the ramifications of the changes, probably need to make it configurable in the next UnitySteer release?

ricardojmendez commented 5 years ago

Hi,

I'm not actively developing UnitySteer right now, as I'm not doing anything in Unity. Feel free to send a PR with your rationale and I'll review it when I get a breather. Cheers!

spikything commented 4 years ago

Combining RigiBody physics with steering behaviours used to work for me, but not since the last 2 major Unity releases. The Update / FixedUpdate trick didn't work for me, so I added the ability to blend steering forces with non-kinematic RigidBody forces, rather than simply moving the object. Since I haven't battle tested this in my game yet, I'm not creating a pull request yet - but you can see the tiny change here: https://github.com/spikything/UnitySteer/commit/6172185b4926ef3777c0c066843b71608a4a2ec8