JavaGuy4230 Posted June 11, 2003 I'm trying to learn how to program games (seriously now, since I have some partners). Right now I'm trying to figure out how a character who turns 360 degrees moves. It'll be 2D, but it's the same concept as the turning in a first person shooter. In any case, make a character on the screen turn is easy enough. However, once you hit that foward button, the character has to move in the direction of face. So how does this work? I've had a couple ideas of my own, but I haven't implemented them. Anyway, what I'm hoping is that someone can give me the file/s containing the source code for movement in Doom. By looking at it I can compare it to my ideas. And also although thing. Does the movement involve conditionals or is it just a pure algorithm thing? I don't know if they have it going though if then statements everytime some movement thread comes about. Help is appreciated, thanks. 0 Quote Share this post Link to post
Julian Posted June 11, 2003 JavaGuy4230 said: I'm trying to learn how to program games (seriously now, since I have some partners). Right now I'm trying to figure out how a character who turns 360 degrees moves. It'll be 2D, but it's the same concept as the turning in a first person shooter. Exactly like DOOM heh.JavaGuy4230 said: In any case, make a character on the screen turn is easy enough. However, once you hit that foward button, the character has to move in the direction of face. So how does this work? Keep an angle or a line direction as an info attached to the player structureJavaGuy4230 said: I've had a couple ideas of my own, but I haven't implemented them. Anyway, what I'm hoping is that someone can give me the file/s containing the source code for movement in Doom. By looking at it I can compare it to my ideas. It's pretty easy to get the DOOM source (or any other port), but I wouldn't recommand it. DOOM's code is a mess actually.JavaGuy4230 said: And also although thing. Does the movement involve conditionals or is it just a pure algorithm thing? I don't know if they have it going though if then statements everytime some movement thread comes about. Help is appreciated, thanks. The way you handle movements and collision detection is higly dependant on the underlying structures. I'd recommand to check some serious tutorial on the web before starting a game engine. And even if you have a straight-forward algorithm, I doubt it'll ever be conditional free. 0 Quote Share this post Link to post
JavaGuy4230 Posted June 11, 2003 Yeah. I wasn't sure if it would be conditional free. Thing is, with my ideas, it might take one or two if then statements in the midst of the movement code. The thing is I was wondering if there was a better way to do it for efficiency. 0 Quote Share this post Link to post
DarkWolf Posted June 11, 2003 Moving the player in the angle direction he's facing can be done with some simple trig. There are probably other ways to do it too. 0 Quote Share this post Link to post
JavaGuy4230 Posted June 12, 2003 Yeah. Like I said, I've got an idea, but I still have to implement it. I get the center of character, and two points on the radius (four all together for both x and y axis) and using the three points I can calculate the angle (through trig, since the angle always makes an isosceles triangle, which can be split into two right) and make him move proportional distances. But like I said, since I haven't gotten around to that yet I just wanted to see Doom's source code to see how they did it. Actually, before I figured out my own way of doing it, I tried going Sun's forums (they developed Java). It turns out nobody there is any help at all. 0 Quote Share this post Link to post
Julian Posted June 12, 2003 JavaGuy4230 said: It turns out nobody there is any help at all. Well, you problem has nothing to do with java. It is purely algorithmic (if you can use such a word for something that simple). 0 Quote Share this post Link to post
timmie Posted June 13, 2003 movex = distanceToMove * sin(viewangleInRadians); movey = distanceToMove * cos(viewangleInRadians); posx += movex; posy += movey; How's that? I might have the sin/cos mixed up, though... Oh, the Doom engine uses binary angles for everything, so it's probably not the best resource for this. 0 Quote Share this post Link to post
Fredrik Posted June 13, 2003 How's that? I might have the sin/cos mixed up, though...Yeah, I think you do. I've memorized that cos always goes for x and sin always goes for y ;) 0 Quote Share this post Link to post
DarkWolf Posted June 14, 2003 posx = distanceToMove * cos(viewangleInRadians) + posx; posy = distanceToMove * sin(viewangleInRadians) + posy; Save yourself some variables. 0 Quote Share this post Link to post
Fredrik Posted June 14, 2003 Or better yet: posx += distanceToMove * cos(viewangleInRadians); posy += distanceToMove * sin(viewangleInRadians); 0 Quote Share this post Link to post
JavaGuy4230 Posted June 16, 2003 Well, thanks for posting, but it doesn't matter because my idea worked. Actually I was suprised to come back here and find more replies. Well, whatever, done and over. On another note, the problem is not Java related, but since people there program games similar to those I wish to program, I thought that perhaps someone would have a good answer. 0 Quote Share this post Link to post
Lord FlatHead Posted June 17, 2003 Hey, I needed this too for a stupid little racing game I'm writing. Thanks. 0 Quote Share this post Link to post
JavaGuy4230 Posted June 26, 2003 Sorry for bumping this older thread, but I didn't see a reason to start a new one, since this is along the same lines. Anyway, I was hoping someone might be able to point me towards some comprehensive Trig lessons on the net. The thing is, I figure it'd be good to know a bit on how it works (I mean, I know about sin, cos, tan, and their inverses, but it get's rather complicated when I want to do various things for games). The thing of it is, my school doesn't teach trig, so my only method other than an internet lesson (or if I can find a decent book) is to pay $1200 for summer school at a local college. Any links? 0 Quote Share this post Link to post
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.