Angle of Character Again

Oct 27, 2009 at 1:38 AM
Edited Oct 27, 2009 at 1:40 AM

Hello everyone! I have talked about this for so long and I have found ways to go about finding the angle of the character but I hate how it's done. What my code does is check between ALL geoms in the game. This would ruin having a big game and cause HUGE slowdown.  Plus, with the RayTester class being updated in 2.1.2, I figured it's best to make something that works a little better. If anyone wants to see the code for what I used in the previous version, I can pass it along. Here it is working: http://picasaweb.google.com/dcoulson3rd/Game#5397087218080366194

ANYWAYS,

I have thought of a way to find the angle of the character by finding the angle of the slope directly below it. What I've done is made a line segment geom that juts out of the bottom of the character. I still use the same design as I have before:

But now instead of the line jutting out the bottom being so short, it is a lot longer (about 50 pixels below the bottom of the circle). It still does determine if a collision has happened but when a collision is true, it is to calculate the angle of what it is colliding with.

Here is where I need help. I want to use the RayTester class to find out what two vertices it is hitting between and then finding the slope of those two vertices. I have thought of two possible ways of finding this which are shown 

                RayHelper.LineSegmentVerticesIntersect(ref geom.WorldVertices[0], ref geom.WorldVertices[1], collisionGeom.WorldVertices, intersectingPoints2);

 

                RayHelper.LineSegmentGeomIntersect(ref geom.WorldVertices[0], ref geom.WorldVertices[1], collisionGeom, false, intersectingPoints1);
                RayHelper.LineSegmentVerticesIntersect(ref geom.WorldVertices[0], ref geom.WorldVertices[1], collisionGeom.WorldVertices, intersectingPoints2);

 

These are two ways I have thought of finding out what vertices it hits between. Problem is I don't know what to do from here. If I could find out what vertices the geom line segment is between, I could calculate the slope. Heck, these two possible lines of code may not even be the best way to do it. I don't know how they work. Again, finding the vertices it is between is my main problem. Any help would be amazing and probably beneficial to a LOT of people on here (lot of people wanting to find a good way of doing this).

Oct 30, 2009 at 6:43 PM

Can someone PLEASE help me?

 

Oct 31, 2009 at 12:15 PM

This problem could be divided in two smaller problems:

- The floor angle detection.
- The proper rotation of the character.

For the floor angle detection, you can cast two rays to the bottom of the character, like the way explained in this thread.

Rotating the character is a little mor tricky though, because as I said in another thread, you shouldn't rotate the character around the rectangle's center position, but around the circle (feet) position. Tips for doing that.

Oct 31, 2009 at 3:40 PM

What if I rotate around the line segments I use for finding out whether the player can jump or not. I have code working right now but it VERY slow. I made it a static class so anything can use it but I'm thinking of getting rid of that. It just makes the game run way too slow. It works though at least.

Oct 31, 2009 at 5:24 PM

If the line segment is centered at the bottom circle's position, it should work. Make shure that the line is fixed with an angle joint with the rectangle, so when you rotate the line, the rectangle rotates too.