# How to Change Angle of Character

 sonic4305 Jul 28, 2009 at 8:55 PM Hi there everybody! I am in the making of a platformer and have come to another bump. I need a way to make my character change his angle of positioning to whatever he is standing on. So if he were standing on a slope, he would be at an angle to the slope and not standing straight. I have seen the way Boxycraft (http://boxycraft.wordpress.com/) did it which was by using three rays and then calculating the slope through that but I have no clue how to do that. If anyone can give me advice on this, that would be great!     My second thing that I am needing help on is that my jumping is not working properly. I needed a way to check and make sure he is on the ground so what I did was attached a circle to a rectangle with a revolute joint and made the circles radius smaller than the width so that whenever the circle is colliding, I know it's the ground. My problem is that because it is not a perfect circle it doesn't always collide.     ```//This is how I perform the jump using the OnCollision of the circle //All it does is reference to whether the circle is colliding and makes canJump true. if (currentGamePadState.IsButtonDown(Buttons.RightShoulder) && previousGamePadState.IsButtonUp(Buttons.RightShoulder)) { this.circleGeom.OnCollision += this.OnCollision; this.circleGeom.OnSeparation += this.OnSeparation; if (canJump) { this.squareBody.ApplyImpulse(ConvertUnits.ToSimUnits(0f, -1750f)); } } //These are the simple OnCollision & OnSeparations I made private bool OnCollision(Geom g1, Geom g2, ContactList contactList) { if (!canJump) { canJump = true; } return true; } private void OnSeparation(Geom g1, Geom g2) { if (canJump) { canJump = false; } } ```     What doesn't work about this is the fact that the circle is not always colliding with the ground. So whenever I move it lifts off for a short while and then allows my character not to jump. Is there a way I could get this to not happen. I was thinking of just making a small line segment that would jut out the bottom to where the circle should reach down to but I want to hear everyone's opinion first. Thanks to all who can help me! <(0 0,)> sonic4305 Jul 28, 2009 at 9:22 PM http://www.youtube.com/watch?v=RbHEWEkPZ0s This is the video of my game to give an example. Keep in mind that I am hitting the jump button the whole time overall. At some points I don't but most of the time I am. sonic4305 Jul 28, 2009 at 10:16 PM Edited Jul 28, 2009 at 10:18 PM Something is wrong with my OnCollision and OnSeparation. They are not working properly at all. Especially the OnSeparation. Sorry for all these post in a row from me. I just try something and think it was working and then realize it isn't. My bad genbox Coordinator Jul 29, 2009 at 12:38 AM The jumping issue is due to the OnCollision and OnSeparation event subscriptions you made. Each time you update the physics engine it will check for collisions, if any collisions are found, they are reported by the OnCollision callback. That is why the OnCollision event is fired all the time. The OnSeparation even is fired when there are no more contacts left between two geometries. That means they are not touching anymore. Because the engine is based on and sequential impulse design, geometries jitter a little. So even if you have a geometry standing on the ground, it will fire the OnSeparation even sometimes. It is up to you to take the data the engine gives you and use it in such a way that it is reliable for your game. One way of doing it is to look at the events fired over time. I have thought of several ways of changing this so it can be reliable for all games, but it is not an easy task. It is something I will look into when we are in the final stages of FPE 3.0. As for the other questions, you might find some help in our community created FAQ sonic4305 Aug 1, 2009 at 5:09 PM Thank you for the info genbox, it was very helpful. I officially have the jump working ^_^   The only thing left which I'm still hoping I could get help on is how to have your sprite change it's angle to what it is standing on : http://picasaweb.google.com/dcoulson3rd/Game#5365027330562528610   Boxycraft (http://boxycraft.wordpress.com/) is the only thing that I have seen that has done this and shows you how but I don't know how to implement that :( Any help would be nice :) genbox Coordinator Aug 1, 2009 at 6:14 PM Boxycraft uses Physics2d.net, but it is also possible with Farseer Physics. The main difference is that Physics2d.net has motor joints, but robertdodd created a patch (ID 3009) that gives you a revolute joint with motor, so you also have the option. What exactly do you have trouble implementing? Try creating a circle attached to a box using a fixed angle joint and attach the revolute join to the center of the circle. Then you attach the fixed angle joint to the box. As explained on the site, the joints works as follows: 1. Revolute joint make sure that he can roll on the ground. This is the whole movement system. 2. Fixed angle joint make sure that the box can be fixed in an angle. This gives the illusion that he is standing on a slope. 3. The angle joint make sure that he does not roll down hill when he stands on a slope. When you have created the circle and box with all the joints, you can start creating the rays. Use the RayTester class to do this. You simply give it two points: one from the bottom left of the box, one from the bottom middle of the box and one from the bottom right of the box. The end points of the lines are just offset n units on the Y axis. Use LineSegmentGeomIntersect() to accomplish the line work. You give it a line (start point + end point) the geometry to check against (the ground right under it), a boolean if it should use AABBs (set it to false) and a referenced list of intersection points. There is a demo in our AdvancedSamples on how to use the RayHelper class. sonic4305 Aug 1, 2009 at 10:20 PM This is how my character is made: http://picasaweb.google.com/dcoulson3rd/Game#5365107327945553762 I'll look into what you gave me to go off by though as well :) thanks for all the help and hopefully I won't be bothering you again anytime soon. robertdodd Aug 2, 2009 at 7:43 AM Hi Sonic Someone emailed me recently about how I got the angle, was it you? If it wasnt: I can send you some modified LineSegmentGeomIntersect code that returns the normal of the ground, and also my player code which uses it. Just email me if you want it. Cheers. sonic4305 Aug 2, 2009 at 10:28 PM Definitely robertdodd. I think that was me by the way. I'll send you another email to get the info and thanks ^_^ pnikosis Aug 5, 2009 at 3:22 PM I would love to see that code too :) sonic4305 Oct 19, 2009 at 3:13 AM Oh wow, I just saw this message pnikosis. I can still put it up if you're interested in it. slapgw Oct 19, 2009 at 4:53 AM This post has been very helpful to me. I'm interested seeing that code too if possible pnikosis Oct 19, 2009 at 8:17 AM sonic4305 wrote: Oh wow, I just saw this message pnikosis. I can still put it up if you're interested in it. Yes, please! I have my own code for checking the ground's normal, but as I'm a lousy programmer, I'm not sure if I'm doing it right enough. sonic4305 Oct 19, 2009 at 8:55 PM I'll send it to you in an email. Just give me your email and I'll send it. Also it would be cool if I could see your way as well. I'm using Gleed2D for my map creation and my character like very high slopes or it glitches. I'll post a video of it. Also I know you've said that you've talked to the creator of Gleed2D and I have no clue how to get a hold of him. His forums are full of spam post and I really want to offer to him the idea of removing the circle primitive and making it an ellipse tool instead. I really could use that for my game but just don't know how to go around doing it. If he can't do it, I'll probably just make a special function with using the rectangle primitive but I'd rather not. sonic4305 Oct 19, 2009 at 9:19 PM Edited Oct 19, 2009 at 10:23 PM I guess I could post the whole thing on here but I would rather load the file up or something. Plus I don't want to give you guys anything that isn't very good. I'm going to look at editing it and everything. I'll post the video of why I don't want to give it yet shortly. Uploading it as I type lol.   UPDATE: I have the video up. It should be finished processing before anyone sees it. http://www.youtube.com/watch?v=bWNSrY1Ysiw Sorry about the quality. Still getting used to how to work with Expression Encoder 3 pnikosis Oct 19, 2009 at 11:07 PM I think I know what produces your glitch. I see that your character has two geoms (circle and rectangle), which geom is the one you are rotating? I guess you are rotating the rectangle using its center as the pivot point. The problem is that if you do that, the circle which is attached to the rectangle moves around the rectangle and "enters"  onto the floor... I'll explain this better with an image: When rotating your character, do it using the bottom circle as a pivot point. pnikosis Oct 19, 2009 at 11:14 PM sonic4305 wrote: I'll send it to you in an email. Just give me your email and I'll send it. Also it would be cool if I could see your way as well. I'm using Gleed2D for my map creation and my character like very high slopes or it glitches. I'll post a video of it. Also I know you've said that you've talked to the creator of Gleed2D and I have no clue how to get a hold of him. His forums are full of spam post and I really want to offer to him the idea of removing the circle primitive and making it an ellipse tool instead. I really could use that for my game but just don't know how to go around doing it. If he can't do it, I'll probably just make a special function with using the rectangle primitive but I'd rather not. The GLEED2D page seems to be abandoned, I'm still using the editor (I don't have time neither the skills for creating a map editor). For the ellipses I do them with the path primitive, did you manage to work with them? Anyway, my email is my forum's username @ gmail.com (I try not to write it directly because of the spambots). Cheers, if you have more questions, just ask :) sonic4305 Oct 20, 2009 at 3:27 AM Edited Oct 20, 2009 at 3:29 AM Well I'm rotating the circle to move. I guess I don't fully understand what you mean with your idea. I did try one thing though. I have noticed strange things happen when two lines are too close to each other that my character is standing on and he takes the average of more than just the line he is under. Your picture actually shows the geom a little bit differently (which is fine). From what I've seen when testing it, if there is another line too close below the character (besides the one he is on), it is also calculated into the angle joint. If you look at 20 sec. on my video, you'll see that the geom actually is about 50 pixels below the character. If I lower that down 50 pixels (which I did in one of my test) it works fine. You can even see an example of it working fine on the angle at the beginning of the video and there is a 100 pixel difference between those two lines. I'll have to post a video of it later but I'll definately get back to you guys about calculating the angle. I need some fixing up of the code myself before I embarass myself giving you guys something that doesn't even work :)   By the way, if none of that made sense I can put up pictures showing what I mean (sometimes I talk in a mess of words that only makes sense to me lol). pnikosis Oct 27, 2009 at 9:15 AM Hi, sorry for the delay in the answer. The difference on using one pivot point or another is that if you rotate around the rectangle (the upper geometry), its feets (the circle) will move around the rectangle, and we don't want that. What we want is to keep the feet at the same world place, and rotate the rest of the body. I'm not sure if I'm explaining myself. sonic4305 Oct 27, 2009 at 3:48 PM Edited Oct 27, 2009 at 3:50 PM Wait so how would I do this then? I can post my code if you want but I'm at school right now so I'll have to wait until I get home.   By the way, I made a new Discussion here about angles of character that talks about a different way of finding the angle: http://farseerphysics.codeplex.com/Thread/View.aspx?ThreadId=73172