New character controller

Share with us how are you using the powerrrr of the force

Moderator: Alain

Re: New character controller

Postby Leadwerks » Thu Jan 22, 2009 12:26 pm

When you get that dotproduct, should the velocity be normalized?

The way I am calculating the velocity is this:

1. Translate the controller by the velocity.
2. Save the controller position in a temporary variable.

Perform steps 3 and 4 ten times:
3. Perform collision tests and calculate the collision push vector.
4. Translate the controller by the collision push vector.

5. Subtract the saved position from the current position. This is the velocity.


I think I need to combine that reflectance vector with the collision push vector to make this work? Any thoughts?
User avatar
Leadwerks
 
Posts: 515
Joined: Fri Oct 27, 2006 2:54 pm

Re: New character controller

Postby Yezide » Thu Jan 22, 2009 2:21 pm

Velocity is not normalized.

Should not be force to do step 3 and 4 several times, the push vector should be final.

Use the reflection at step 5 (replace it what u are currently doing).

Also remember that velocity is not the same as the step made by the character (your step 1), but rather velocity * timestep. Just remember to take this into account.
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Re: New character controller

Postby Leadwerks » Thu Jan 22, 2009 3:02 pm

I performed steps 3 and 4 multiple times because I found some situations like when the player pushes into a corner, or pushes under a sloping ledge, where one pass would be inaccurate. I am getting perfectly clean collisions in these situations now. Are you?
User avatar
Leadwerks
 
Posts: 515
Joined: Fri Oct 27, 2006 2:54 pm

Re: New character controller

Postby Leadwerks » Thu Jan 22, 2009 3:32 pm

Let's talk about stair-stepping. I implemented one version, but it has problems in certain situations. I don't think the convex cast routine is returning accurate results. How are you doing yours?

I got rid of the raycast and tried a purely collision-based approach. You can see here it works great, except that Newton isn't returning all the collisions that occur, so the controller doesn't detect the step until it is penetrating it quite a bit:
http://www.leadwerks.com/post/controller3.wmv
Last edited by Leadwerks on Thu Jan 22, 2009 5:33 pm, edited 1 time in total.
User avatar
Leadwerks
 
Posts: 515
Joined: Fri Oct 27, 2006 2:54 pm

Re: New character controller

Postby Yezide » Thu Jan 22, 2009 4:23 pm

Yeah, all my push back vectors are as they should!

For step climbing cast one or several rays and find the highest position in front of the character. I cast the rays the distance of the full movement (since there was a collision before step climb is checked, characterhas not moved fully this time step) and then check for the highest point in front of the player. I now test this position with the the character shape and see if it fits and if it so, then I start moving the character a little bit upwards, so that it climbs the step insteads of teleports on top of it (check video for example of this).
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Re: New character controller

Postby Leadwerks » Thu Jan 22, 2009 5:35 pm

I think a combination of the method I used in the video above, and a convex cast performed once each frame, will give the most accurate results. For some reason the convex cast function is causing some really bizarre errors right now.
User avatar
Leadwerks
 
Posts: 515
Joined: Fri Oct 27, 2006 2:54 pm

Re: New character controller

Postby Leadwerks » Thu Jan 22, 2009 6:52 pm

All my stair-stepping techniques are producing bad results in certain situations, so I just took it out. Here's a demo:
http://www.leadwerks.com/post/controller2.zip

-Movement can start and stop very quickly, and doesn't need to be smoothed.
-The player can walk on the ramp with no jumping or bumping, or sliding down it.
-The player instantly slides off the steep ramp.
-If the player tries to walk up the steep ramp, there is no bumping at all, it just acts like a wall.
-The player can walk under the overhang and push into it without collision errors.

It still needs a way to step over obstacles, and interaction with other bodies.
User avatar
Leadwerks
 
Posts: 515
Joined: Fri Oct 27, 2006 2:54 pm

Re: New character controller

Postby Leadwerks » Thu Jan 22, 2009 11:02 pm

I added stair-stepping as well, using my original multiple raycast. I am going to take another try using the convex raycast.

Since there is code around here I wrote for adding a force to a body at a position, it should not be too hard to make the controller interact with objects.
I also found I can use as few as 1 iteration of those steps I was repeating, but using a few passes gives perfectly smooth results in all situations. Thanks again for the good advice.
User avatar
Leadwerks
 
Posts: 515
Joined: Fri Oct 27, 2006 2:54 pm

Re: New character controller

Postby hpesoj » Sun Feb 08, 2009 9:42 pm

This thread has been very helpful for me so far. I now have a character controller with smooth collisions and slope detection (as Leadwerks described). However, I'm not sure how to go about making the character stick to a slope on the way down. I have tried multiple techniques, but none have been perfect. Could either of you give me any pointers? Cheers.
hpesoj
 
Posts: 90
Joined: Sun Jan 09, 2005 4:36 pm
Location: Cambridge/Bristol, UK

Re: New character controller

Postby Leadwerks » Sun Feb 08, 2009 11:22 pm

I overshot the ray a little bit and aligned the player if a hit occurs. If you jump, that will be enough speed to move you so that extra length of the raycast won't hit the slope that frame. I also did something so the downward velocity was retained when you walked down a ramp. I forget exactly how, but the general idea was if the y velocity is <0, don't reset it to 0.
User avatar
Leadwerks
 
Posts: 515
Joined: Fri Oct 27, 2006 2:54 pm

Re: New character controller

Postby Yezide » Mon Feb 09, 2009 6:22 am

hpesoj wrote:This thread has been very helpful for me so far. I now have a character controller with smooth collisions and slope detection (as Leadwerks described). However, I'm not sure how to go about making the character stick to a slope on the way down. I have tried multiple techniques, but none have been perfect. Could either of you give me any pointers? Cheers.


What I do is that I check the ground normal and then align the forward vector so it is orthogonal to the ground normal. That way the character will ride along with the slope. The equation for this is:
right = forward cross normal
forward = normal cross right
User avatar
Yezide
 
Posts: 173
Joined: Tue Oct 18, 2005 4:31 am

Previous

Return to User Gallery

Who is online

Users browsing this forum: No registered users and 2 guests