CharacterController from demos has jumping deficiency

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
snoozbuster
Posts: 172
Joined: Sat Sep 24, 2011 7:31 am

CharacterController from demos has jumping deficiency

Post by snoozbuster »

I took the CharacterContoller from the demos and modified it a bit to offset the camera to an isometric-type view, which worked great, but I have a strange problem when I try to jump along the positive Y-axis: the jump is about half as powerful as it should be. It also tends to "stick" on neighboring walls, making it really hard to jump up onto ledges in that direction. It also happens when jumping along (0.5, -0.5). I assume this is related to my habit of using Z as up; but I couldn't find anything in the source that would cause this behavior. Do you have any ideas? I can post relevant source if you need me to.

EDIT: Actually, I can do you one better, I have the source for this particular project on GitHub; I don't expect you to look through all of it but this way I don't have to post snippets. https://github.com/snoozbuster/ld30/tre ... Controller is the CharacterController code, and https://github.com/snoozbuster/ld30/blo ... aracter.cs is where it's used from (I can't see that being a useful piece of information, but you never know).
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CharacterController from demos has jumping deficiency

Post by Norbo »

"Sticking" on walls sounds like it is getting traction on the wall somehow, and underpowered jumps sound like the character lacks traction (CharacterController.SlidingJumpSpeed defines the strength of jumps when the character does not have traction; it defaults to a lower value than JumpSpeed). So it seems related to traction in some way.

One possible culprit would be a CharacterController.Down direction that isn't aligned with gravity. The resulting behavior would be very difficult to intuit.

Another weaker possibility is wonky values on the CharacterController.ContactCategorizer thresholds. This doesn't have as much explanatory power as a misaligned Down, though.

If the above don't appear to be related, I'll probably need a reproduction in the latest BEPUphysicsDemos to be of any help.
snoozbuster
Posts: 172
Joined: Sat Sep 24, 2011 7:31 am

Re: CharacterController from demos has jumping deficiency

Post by snoozbuster »

Norbo wrote:One possible culprit would be a CharacterController.Down direction that isn't aligned with gravity.
That was my first reaction too, but I didn't think it was that (although I guess I never checked). I went to go check, but apparently I never got around to it because I came back and this post was still here, waiting.

I'll let you know if I figure it out; I was asking because I'm doing Ludum Dare but the submission deadline just hit so it's not a big priority. I might go back and try to fix it, we'll see.
snoozbuster
Posts: 172
Joined: Sat Sep 24, 2011 7:31 am

Re: CharacterController from demos has jumping deficiency

Post by snoozbuster »

I figured it out, thought you might like to know what the problem was. Basically, at the end of CharacterControllerInput.Update() we have the line CharacterController.ViewDirection = Camera.WorldMatrix.Forward, but my camera doesn't use the world matrix, just a view matrix. So, ViewDirection was always being set to (0, 0, -1), which had some pretty weird behavior inside UpdateHorizontalViewDirection(). The only reason it didn't completely crash and burn was because Down was juuuuuust barely not (0, 0, -1), and because of the way the numbers worked out, horizontalViewDirection usually ended up around something like (0, 0.46, 0.84) or another similarly senseless number. Changing the line to use the view matrix's forward worked great, though.
To be honest, I don't actually know enough about the code to understand why this works, though! ^^;
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CharacterController from demos has jumping deficiency

Post by Norbo »

Careful- a view matrix typically refers to the transform which pulls objects from world space into camera space, which means it is the inverse of the camera's world matrix. It may appear to work acceptably since it's an isometric camera that presumably isn't rotating all the time.

If the camera isn't actually directly following the character, the character's view direction probably should not be based on the camera anyway. The character just needs to know which direction is forward/back versus side to side. If these stay constant over time due to the perspective, you could just assign the view direction once up front to (0,0,1) or whatever produces the desired move directions.
snoozbuster
Posts: 172
Joined: Sat Sep 24, 2011 7:31 am

Re: CharacterController from demos has jumping deficiency

Post by snoozbuster »

Norbo wrote:Careful- a view matrix typically refers to the transform which pulls objects from world space into camera space, which means it is the inverse of the camera's world matrix.
You're right, I actually had to do the negative of the view matrix. I did learn that the view is the inverse of the world recently, though, when I was working on the editor for the game. I didn't realize that relationship existed, so that was neat.
Norbo wrote:If the camera isn't actually directly following the character, the character's view direction probably should not be based on the camera anyway. The character just needs to know which direction is forward/back versus side to side. If these stay constant over time due to the perspective, you could just assign the view direction once up front to (0,0,1) or whatever produces the desired move directions.
I did add camera rotation but only by multiples of 90 degrees; either way it's working now so I'm happy. I'll keep this in mind for future projects, though.

Actually, come to think of it, it might actually be trying to move at an angle into the ground. I should take a look at that.
EDIT: the ViewDirection does have a Z component but it doesn't seem to change anything to strip it out.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: CharacterController from demos has jumping deficiency

Post by Norbo »

EDIT: the ViewDirection does have a Z component but it doesn't seem to change anything to strip it out.
The ViewDirection is used to compute a HorizontalViewDirection and StrafeDirection based on the Down direction. It does this by projecting the ViewDirection onto a plane defined by the Down direction, so any component of the ViewDirection along Down will be removed.
snoozbuster
Posts: 172
Joined: Sat Sep 24, 2011 7:31 am

Re: CharacterController from demos has jumping deficiency

Post by snoozbuster »

Norbo wrote:The ViewDirection is used to compute a HorizontalViewDirection and StrafeDirection based on the Down direction. It does this by projecting the ViewDirection onto a plane defined by the Down direction, so any component of the ViewDirection along Down will be removed.
Yeah, I figured that might be the case.
Post Reply