Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
JavaGuy4230

360 Turning

Recommended Posts

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.

Share this post


Link to post

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 structure

JavaGuy4230 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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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.

Share this post


Link to post

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).

Share this post


Link to post

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.

Share this post


Link to post

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 ;)

Share this post


Link to post

posx = distanceToMove * cos(viewangleInRadians) + posx;
posy = distanceToMove * sin(viewangleInRadians) + posy;

Save yourself some variables.

Share this post


Link to post

Or better yet:

posx += distanceToMove * cos(viewangleInRadians);
posy += distanceToMove * sin(viewangleInRadians);

Share this post


Link to post

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.

Share this post


Link to post

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?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×