Page 1 of 2
Gradually rotating a character
Posted: Sun Apr 22, 2012 9:05 am
by Peter Prins
I have a world where the direction of gravity gradually changes direction and magnitude, and I want my character to always have it's feet in the direction in which gravity is pulling. From what I've seen from how to work kinematic entities the best way to do this would be to manipulate the angular velocity rather than changing the orientation directly, correct?
I noticed that it says in the ExpandBoundingBox method that it needs to be changed to facilitate this. How would it need to be changed exactly? Also are there any other methods that would need to be changed to make this work properly?
Re: Gradually rotating a character
Posted: Sun Apr 22, 2012 9:16 am
by Peter Prins
Also, would it be best to change the angular velocity in IBeforeSolverUpdateable.Update or in some other update?
Re: Gradually rotating a character
Posted: Sun Apr 22, 2012 3:55 pm
by Norbo
From what I've seen from how to work kinematic entities the best way to do this would be to manipulate the angular velocity rather than changing the orientation directly, correct?
Under normal circumstances, using velocity is indeed better than teleportation. However, characters have infinite inertia tensors and cannot be rotated by any regular force. Assigning a velocity to such an entity could result it in applying immense forces to the environment. In this case, it might actually be better to discontinuously change the orientation, letting it interpenetrate the environment a little as it does so.
I noticed that it says in the ExpandBoundingBox method that it needs to be changed to facilitate this. How would it need to be changed exactly? Also are there any other methods that would need to be changed to make this work properly?
It would just involve creating a bounding box around the rotated body of the character. The current implementation assumes an axis aligned orientation. There are scattered sections of the character which refer to down or up directions; these parts would need to be modified to use a dynamic value.
However, while it would be possible to adapt it, I would recommend not using the CharacterController if gravity (and the 'down' direction) changes. The SphereCharacterController is significantly easier to handle because you don't have to worry about rotating the body at all. You'll still need to change things in the HorizontalMotionConstraint and such to make it understand the new gravity, though.
Check out this thread (especially the last 4 posts or so) for a little more information:
viewtopic.php?f=4&t=1538&p=9078
Re: Gradually rotating a character
Posted: Wed May 23, 2012 3:00 pm
by Peter Prins
I would like to use the CharacterControler, even if it is more work to change it.
However, I have already run into a problem. Since I want to have a different gravity in different areas of the space I can't use the engine's normal gravity. Instead I use an IDuringForcesUpdateable that applies a force to all entities in the space. At the moment this force still points downward. Mostly, this seems to work normally, but sometimes when the character hits a dynamic object both the character and the object are launched vertically into the air at significant speeds.
Do you have any idea what may cause this?
Re: Gradually rotating a character
Posted: Wed May 23, 2012 3:04 pm
by Norbo
There's nothing special about the regular gravity, so setting it to zero and applying your own forces is perfectly fine. Doing it in the IDuringForcesUpdateable stage is probably the best spot too. The launching effect is likely caused by something else; if the character has already been modified for differing gravity, there may be an inconsistency somewhere leading to extraneous impulses.
Re: Gradually rotating a character
Posted: Wed May 23, 2012 6:25 pm
by Peter Prins
Well, I haven't changed anything about the character yet, and I've already narrowed it down to the IDuringForcesUpdateable, by testing the game with both kinds of gravity.
Re: Gradually rotating a character
Posted: Wed May 23, 2012 6:28 pm
by Norbo
I do not have any theories at the moment, unfortunately. If the problem can be reproduced in an isolated BEPUphysicsDemos demo I could take a closer look.
Re: Gradually rotating a character
Posted: Mon Jun 18, 2012 2:31 pm
by Peter Prins
Well I found some time to try to recreate the problem in the demo but no luck so far.
Re: Gradually rotating a character
Posted: Tue Jun 19, 2012 2:01 am
by Norbo
If it can't be reproduced in the demos, there's a small chance that it was something that was fixed. Is the main project (that still exhibits the issue) using the latest version of the engine and character?
Re: Gradually rotating a character
Posted: Mon Jun 25, 2012 12:23 pm
by Peter Prins
Well, it's not the latest version, but they both use the same version (v1.1.0). The problem is that my project is already quite large and complex and it's not easy figuring out what other things might contribute to the problem. For instance the project currently runs two physics simulations at the same time.
I've made a copy of that project, and I'm trying to narrow down the possible causes by removing any unnecessary parts.
Re: Gradually rotating a character
Posted: Mon Jun 25, 2012 4:16 pm
by Norbo
Do the simulations run in parallel? There was a bug in v1.1.0 which made that unsafe. Upgrading to v1.2.0 should fix that particular issue.
There were also some changes in v1.2.0 to the character to make it work better in the presence of multithreaded character updates.
Re: Gradually rotating a character
Posted: Tue Aug 28, 2012 12:13 pm
by Peter Prins
Thank you, I'll try that.
Re: Gradually rotating a character
Posted: Mon Sep 03, 2012 12:22 pm
by Peter Prins
I've updated to v1.2.0 but unfortunately this only makes the problem worse. The game now runs at half the framerate as it did before. And the box, rather than being launched into the air is teleported under the platform it sits on.
Re: Gradually rotating a character
Posted: Mon Sep 03, 2012 4:17 pm
by Norbo
There are no known issues or changes in v1.2.0 which would easily explain that, unfortunately.
A large performance drop and a bunch of weird behavior sounds like it's worth running with the MathChecker enabled. It will find any instances of infinities or NaNs in the common interaction spots. To use it, compile BEPUphysics with the CHECKMATH compilation symbol.
Other than that, I don't really have enough information to provide better advice. Reproducing it in an isolated project would be very useful.
Re: Gradually rotating a character
Posted: Fri Oct 19, 2012 11:23 am
by Peter Prins
I'm not that familiar with compilation symbols, where and how would I have to specify this?