🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

How to block me away from the wall

Started by
6 comments, last by Jackyboy 18 years, 2 months ago
In Lesson 10,assume that I'm the person walking in the room.It's very exciting that I can go anywhere!Just like a superman,I'm able to go through the wall before me,and I can walk upstairs without limitation.Fascinating! But as a human not a angel,I really purchase the reality instead of the virtual world.I wish to be block away from the wall which I try to go through. How to solve the problem?
Advertisement
The solution is colition detection, which is tought in a later lesson.
You can use AABB collusion detection where you set the x,y, and z values and your x,y, and z values ;check them; and see if you've collided.

Such as:

float block_pos[3]; //x,y,zblock_pos[0] = 10;block_pos[1] = 0;block_pos[2] = -4;float player[3];player[0] = 5;player[1] = 0;player[2] = -3;.....//Check themif(player[2] > block_pos[2] && (player[0] > block_pos[0])) //The player has //walked in front of the block and on it's side{//Collusion occuredMessageBox(NULL,"Collusion!", "Collusion has occured between the block and player.", MB_OK);Class->QuitApp();}


Using it is easier (But not exact) and is pretty sikmple to handle.

Hope it helped!

~Axesor
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward
I'm afraid your idea maybe can't make effect.When we're walking,it's the surrounding which is rotating in the opposite direction from us,which makes us feel we are moving,in fact,we are at the same palce all the time without any movement.So the "player[]" can't do any thing.
no it isn't. in most games, they use a matrix or vector camera that moves around, not the world itself. a useful camera function in openGL (part of the GLU library) is:
gluLookAt(posX,posY,posZ,lookAtX,lookAtY,lookAtZ,upX,upY,upZ);//pos = position of camera//lookAT = camera is looking at those coordinates.//up = this is the up vector, normally the upY parameter would take 1, and X and Z would be 0

now just plug in variables to the parameters, perform some calculations, and you got a first person camera!
so now you would want to test for a collision with the wall with AABB. one way you could go about it is if the player collides with the wall, you could return the negative velocity, and another way would be to have the coordinates set equal to the coordinates of the wall everytime it collides so it can't go any farther.

hope that helps,
--nathan
Yes,using camera is a good way to approach.But it's more complex than rotating the world in opposite direction from the viewer.We just add one line to the program: glRotatef(xtrans,ytrans,ztrans),we can finish the moving.And in Lesson 9,I don't want to add some new complex components,but finding a easy way to solve that problem.
well im not to sure how to calculate the position of the object by rotating it, but i would think you want to research quaternions. they are 3d rotations, and that way you could compute the position of the object, and tell if it collided. basicly you would use AABB collision detection, to see if it collided with, let's say that your player is at (0,0,0). so if the calculated rotated and translated wall collides with the origin, you've got it :]

i've never really thought of this approach, since it can make the game actually a lot harder to make in a sense.

from a van halen lyric, this describes it - "working hard to make it easy."
basicly if you use a camera control technique, your life will be a lot easier, since you wont have to rotate every single object in the world, the enemies, the terrain...etc...

also, even if you learn how to calculate rotations, you can just use that for a camera, because all you have to do is rotate the lookAt points, and you've got a basic first person camera.

hope that helps

--nathan
I have missed many days here. Thanks for your explaination. I think it is better to use a camera instead of rotating the whole world. When objects are full of the world,it becomes a tough work to rotate every object,but a camera is so easy that I can rearch the aim very quickly. Doing my best to make it...

[Edited by - Jackyboy on May 3, 2006 7:40:01 PM]

This topic is closed to new replies.

Advertisement