Gradually rotating a character
-
- Posts: 54
- Joined: Fri Mar 11, 2011 11:44 pm
Gradually rotating a character
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?
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?
-
- Posts: 54
- Joined: Fri Mar 11, 2011 11:44 pm
Re: Gradually rotating a character
Also, would it be best to change the angular velocity in IBeforeSolverUpdateable.Update or in some other update?
Re: Gradually rotating a character
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.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?
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.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?
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
-
- Posts: 54
- Joined: Fri Mar 11, 2011 11:44 pm
Re: Gradually rotating a character
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?
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
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.
-
- Posts: 54
- Joined: Fri Mar 11, 2011 11:44 pm
Re: Gradually rotating a character
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
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.
-
- Posts: 54
- Joined: Fri Mar 11, 2011 11:44 pm
Re: Gradually rotating a character
Well I found some time to try to recreate the problem in the demo but no luck so far.
Re: Gradually rotating a character
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?
-
- Posts: 54
- Joined: Fri Mar 11, 2011 11:44 pm
Re: Gradually rotating a character
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.
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
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.
There were also some changes in v1.2.0 to the character to make it work better in the presence of multithreaded character updates.
-
- Posts: 54
- Joined: Fri Mar 11, 2011 11:44 pm
Re: Gradually rotating a character
Thank you, I'll try that.
-
- Posts: 54
- Joined: Fri Mar 11, 2011 11:44 pm
Re: Gradually rotating a character
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
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.
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.
-
- Posts: 54
- Joined: Fri Mar 11, 2011 11:44 pm
Re: Gradually rotating a character
I'm not that familiar with compilation symbols, where and how would I have to specify this?