Skip to main content
GameDev.net gamedev.net
🔒 Locked

damn boolean logic...

Started by MillaTime Jul 23, 2003 at 2:00 AM 2 replies 1k views
Original Post
MillaTime
MillaTime
if(keys['A'])	//strafe left
	{
		if(xpos>-2.3 && xpos<2.3)xpos += (float)sin((heading-90)*piover180) * 0.25f;
		else if(xpos<-2.3 && ((90<=heading && heading<=270) || (heading<=-90 && heading>=-270)))
			xpos += (float)sin((heading-90)*piover180) * 0.25f;
		else if(xpos>2.3 && (abs(heading)<=90) || heading>=270 || heading<=-270)
			xpos += (float)sin((heading-90)*piover180) * 0.25f;

						
		zpos += (float)cos((heading-90)*piover180) * 0.25f;
	}  
Heading is the player's direction in degrees. And it resets when it hits 360 or -360. For some reason, when -270>=heading>=-360 it allows me to strafe left! Perhaps I'm missing something, but i was under the impression that the compiler did Nots, Ands, Ors in that order. So I added parentheses, and it still lets me strafe left! The conditions to strafe left aren't being met, so I don't know why it's changing xpos. This has me baffled, if you see something I don't, please point it out. Thanks. DON'T COPY THAT FLOPPY! [edited by - MillaTime on July 23, 2003 5:30:20 AM] [edited by - MillaTime on July 23, 2003 5:31:02 AM]
----------Invincible intelligence isn't evincible.
vanillacoke
vanillacoke
Why do you need all that code for strafing? couldnt you just do

pos += dir x up and
pos -= dir x up ?

I looked through the code, and it doesnt seem to need all that extra jazz. If it does, then why?
You know what I never noticed before?
MillaTime
MillaTime
omg, sry, forgot to include the fact that it''s for collision detection. I know there are better algorithms, and faster methods and such, but I wanted to make this program as much of my own as possible...

DON''T COPY THAT FLOPPY!
----------Invincible intelligence isn't evincible.
MillaTime
MillaTime
okay, yes, I''m stupid. That''s one of my problems, I always make things too complicated with unnecessary math. Here''s what my new code looks like, and it works flawlessly...

if (keys[VK_UP])
{
if(xpos>-2.3&&xpos<2.3) xpos-=(float)sin(heading*piover180)*0.25f;
else if(xpos<-2.3 && (xpos-(float)sin(heading*piover180)*0.25f>xpos))
xpos-=(float)sin(heading*piover180)*0.25f;
else if(xpos>2.3 && (xpos-(float)sin(heading*piover180)*0.25f xpos-=(float)sin(heading*piover180)*0.25f;

if(zpos>.7 && zpos<23.3)zpos -= (float)cos(heading*piover180) * 0.25f;
else if(zpos<.7 && (zpos-(float)cos(heading*piover180) * 0.25f>zpos))
zpos -= (float)cos(heading*piover180) * 0.25f;
else if(zpos>23.3 && (zpos-(float)cos(heading*piover180) * 0.25f zpos -= (float)cos(heading*piover180) * 0.25f;
}
----------Invincible intelligence isn't evincible.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.