Page 1 of 1

Can't Get Camera/SimpleCharacterController to Work

Posted: Sat Sep 17, 2011 10:25 pm
by Cheeser12
Hi,

I just started using BepuPhysics and I'm loving it so far. I was going to work on trying to make a character controller class, but then I saw there was one already in the demos so I've been trying to take advantage of it.

I used the regular SimpleCharacterController class first, because I wanted to do input myself and I already had a camera class set up. I created the controller, added it to a Space, and called Activate on it, but I couldn't get it to be affected by gravity or by changes to say, linear velocity. The only way I could get it to work was to add the Body to the Space, but then when I tried to use the MovementDirection and Acceleration properties (which I suspect is what I need to do to get the controller to work right), they didn't seem to have any effect.

So instead of that , I decided to try the class that handles input as well, since it automatically adds the controller to the space. To use it, I had to use the Demo's Camera class. However, the camera doesn't seem to be drawing anything that the camera I made drew, so I can't even see the geometry of the space to test out if this method works.

I'm pretty new to this, so I was wondering if anyone can point out where I'm going wrong in this. Also, as a side question, would you foresee any problems if I wired up my camera class to SimpleCharacterControllerInput instead of the Demo's Camera class? Any help would be appreciated :)

Relevant code stuff:
http://pastebin.com/R2xQwiHA Game1.cs
http://pastebin.com/WjcZXX1v TexturedBox.cs (This is the class I use to draw a Box with textures)

Re: Can't Get Camera/SimpleCharacterController to Work

Posted: Sat Sep 17, 2011 10:53 pm
by Norbo
I just started using BepuPhysics and I'm loving it so far.
Good to hear :)
I created the controller, added it to a Space, and called Activate on it, but I couldn't get it to be affected by gravity or by changes to say, linear velocity. The only way I could get it to work was to add the Body to the Space, but then when I tried to use the MovementDirection and Acceleration properties (which I suspect is what I need to do to get the controller to work right), they didn't seem to have any effect.
The Input classes provide an example of how to tell the character to move. Just set the MovementDirection to the desired value. The acceleration value is how fast the character accelerates; usually this is set only one time, if ever. The character will try to fight changes to its body's LinearVelocity property as well, so stick with the MovementDirection property and Jump function.

Do not add the character's body to the space manually. The SimpleCharacterController does it automatically when added to a space (or when activated, if previously deactivated).

I would recommend looking at how the StandardDemo uses the CharacterController. Adding the prefix "Simple" to the CharacterControllerInput class references will make the demos use the SimpleCharacterController instead with no other changes. Fiddling with the character in the context of the demos ensures that external factors won't prematurely interfere with testing. Once you've got a solid handle on how it all hooks together, it will be easier to determine if something else is wrong.

If you're curious about the difference between the Simple and non-Simple character controllers, this post contains some information: http://www.bepuphysics.com/blog/2011/8/ ... tails.html
Also, as a side question, would you foresee any problems if I wired up my camera class to SimpleCharacterControllerInput instead of the Demo's Camera class?
It'll be fine- the Camera class and (Simple)CharacterControllerInput are just things used by the demos application. They are not important to the functioning of the engine or characters; the character doesn't care where it gets its orders from.

Re: Can't Get Camera/SimpleCharacterController to Work

Posted: Mon Sep 19, 2011 12:48 am
by Cheeser12
Thanks for the response,

When I try to build the source code solution (which I'm guessing is how I'm supposed to modify the demos) I get an error that says that my installation of XNA Game Studio doesn't support WP7. I have 4.0 so I don't know why it's saying that....so I guess my question is do I need to specify what specific platform I'm going to be targeting in this build? I'm sorry if this is a noob question, but I've never really messed with a solution that built to more than one platform.

Re: Can't Get Camera/SimpleCharacterController to Work

Posted: Mon Sep 19, 2011 12:55 am
by Norbo
That could be because the XNA installation you got did not include the phone tools. The main source download contains a WP7 version of the core library, but you can just right click on it and exclude it from the project.

Re: Can't Get Camera/SimpleCharacterController to Work

Posted: Mon Sep 19, 2011 1:21 am
by Cheeser12
Ok got everything to build. I switched the demos to the SimpleCharacterController and they all worked fine. I guess it's something in my code, because when I add the controller to my space it doesn't seem to be affected by gravity (even when I set IsAffectedByGravity to true) and the movement direction property seems to have no effect.
Am I supposed to set some setting in the Space itself maybe?

Here's what I currently have, I used my camera and just the controller itself and I set the camera's position to the character's body's position each frame, and no movement occurs:

http://pastebin.com/vcJBghW8

By the way, I ran through all the demos, and it's really amazing what you guys have done. They all ran super fast and were a lot of fun to play around with. Thanks for making this library available to coding noobs like me :)

Re: Can't Get Camera/SimpleCharacterController to Work

Posted: Mon Sep 19, 2011 2:09 am
by Norbo
A slight oddity in the initialization process is masked by the way the demo handles the character. The IsUpdating property of the SimpleCharacterController is true by default. The demos deactivates the character right after creating it, since it's only used when the user presses C. That deactivation puts the character in the appropriate state for calling Activate later. You can bypass this initialization oddity by adding IsUpdating = false to the SimpleCharacterController's constructor.

So there's a few ways to do it. You can do it the "Demos way" which involves the initial deactivation:

Code: Select all

            var character = new SimpleCharacterController(Vector3.Zero, 2, .8f, 1f, 20);
            character.Deactivate();

            character.Body.Position = new Vector3(0, 20, 0);
            Space.Add(character);
            character.MovementDirection = new Vector2(1, 0);
Or you can add the IsUpdating = false line to the SimpleCharacterController constructor and do it slightly more directly:

Code: Select all

            var character = new SimpleCharacterController(new Vector3(0, 20, 0), 2, .8f, 1f, 20);
            Space.Add(character);
            character.MovementDirection = new Vector2(1, 0);
And the equivalent method using the non-Simple character controller, which requires no constructor modifications to work properly:

Code: Select all

            var character = new CharacterController();
            character.Body.Position = new Vector3(0, 20, 0);
            Space.Add(character);
            character.HorizontalMotionConstraint.MovementDirection = new Vector2(1, 0);
By the way, in the pastebin code, the character.Activate() is superfluous just before the character gets added to the space. Activate gets called when added. The IsAffectedByGravity is true by default as well. Additionally, the character dimensions in the pastebin produce a very fat character with a very tall step height.
By the way, I ran through all the demos, and it's really amazing what you guys have done. They all ran super fast and were a lot of fun to play around with. Thanks for making this library available to coding noobs like me
Thanks and you're welcome :)

Re: Can't Get Camera/SimpleCharacterController to Work

Posted: Tue Sep 20, 2011 11:44 pm
by Cheeser12
Everything works great now, thanks a bunch! :D