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

Collision Detection(Problem!)

Started by SimDemon Apr 8, 2002 at 12:04 PM 17 replies 850+ views
Original Post
SimDemon
SimDemon
Ok. I have this new game I am working on, called The Incoming. I am loading levels from files, and I sort of made my own classes in another .cpp file. They have all the function declarations. I need some collision detection for a collision.cpp file. I can''t find it anywhere. I want to be able to collide with the walls from any level loaded. I already have it to where it loads any level. Anyhow, thanks! If thispost = 0 Then GoBack() Else Read() End If
I'll have a link to the TriFaze website as soon as possible. It's still currently being designed, by myself of course! =) I'll update the URL and my signature as soon as possible.Feel free to send me a message on Yahoo! or AOL IM™. =)
RipTorn
RipTorn
you won''t learn anything copying someone else''s code. Try writing you own, and if it doesn''t work, then try re-writing it Until it works. that way, you will learn. And, if there is a fault in the code later on, you will Know how to fix it. You won''t if you blindly copy.
that goes for any code. not just collision detection.
Aim for your projects to be 100% your own code. Yes, they take a lot longer, but you LEARN 100 times as much. and in the long run, you will advance faster.
ando15
ando15
Thats the way i like to do things. Everyone has a different coding style and sometimes even reading through source code wont help you to understand whats going on. I like to read a bit of conceptual info and start coding it my way. I probably do it the less efficient or perhaps incorrect way but i understand the code and can fix it later if my program should so require. I remember i put an normal window style in the ex parameter of CreateWindowEx in a program i made once. It worked fine until i tried to run it on an NT system. My program kept bringing up the could not create window error message. I finally tracked it down and fixed it but if i had used code someone else had written i would still not know about that being a problem. I also want to know how to do collision detection as the tutorial on NeHe''s site is a bit too ''take my word for it it just has to be that way'' for me. :-)

-ando15
SimDemon
SimDemon
I didn''t exactly want a full copy. I want something to go by. I don''t know a lot of stuff like dot products. I need a website, if you could, that could show me these things.(I do know the basics though)

If thispost = 0 Then
GoBack()

Else
Read()
End If
I'll have a link to the TriFaze website as soon as possible. It's still currently being designed, by myself of course! =) I'll update the URL and my signature as soon as possible.Feel free to send me a message on Yahoo! or AOL IM™. =)
Novalis
Novalis
After trying several implementations of my own, I finally downloaded the Quake source to see how they did it. While it''s pretty far from an ideal solution, I did learn a lot from it.
If a man is talking in the forest, and there is no woman there to hear him, is he still wrong?
Kuros_overkill
Kuros_overkill
The way I''m doing it, is in the level file, I include data on boundries, basically areas thant the user can walk in, then my detection rutine just uns through the boundries to determine if the user is in one of the boundries, if it finds the user in a boundry, it quits looking through the boundrys, if it fails to find the player in a boundry, it dosn''t allow the user to move in that direction.

It still doesn''t quite work though, most walls do collition detect, but a few glitches happen around corners, and often I can walk through a wall, (going in one directiion only, as it I can only move parellel to the x or z axis once I''m through the wall)

If I figure out whats causing the glitch, I''ll post a reply here.
SimDemon
SimDemon
Ok. I am using NeHe basecode. In my level file, how would I add the boundaries? I have the format in the file like:

// 1
-1.0 0.0 3.0 6.0 0.0
-1.0 0.0 -3.0 6.0 6.0
-1.0 1.0 3.0 0.0 6.0

Also, I am formatting it to add it''s texture to load in each level file. That way it loads from a function and textures it. I don''t have to do something like:

if(loop_m == 1)
{
glBindTexture(GL_TEXTURE_2D, texture[whichtexture]);
}

Anyhow, thanks! A reply would help!

If thispost = 0 Then
GoBack()

Else
Read()
End If
I'll have a link to the TriFaze website as soon as possible. It's still currently being designed, by myself of course! =) I'll update the URL and my signature as soon as possible.Feel free to send me a message on Yahoo! or AOL IM™. =)
Dalkiel
Dalkiel
what do you mean ? if you just wanna read those coords, then you should use fscanf (in C) or ifstream (in C++). just do the loop till it finds the EOF. but you already know that, do you?

and what is that weird language in your sig ? shouldn''t it be


(thispost==0)?GoBack():Read();


shouldn''t it be ? your sig looks like VB but i guess it''s not... it''s just weird..


"Shadow of annoyance Ne''''er come hither! ...And when He falleth, He falleth like Lucifer, Ne''''er to ascend again..."


TOT
"Shadow of annoyance Ne''er come hither! ...And when He falleth, He falleth like Lucifer, Ne''er to ascend again..."
TOT
Keermalec
Keermalec
Simdemon, collision detection involves some pretty advanced vector maths if you want it to work in every direction and with every object in your scene. The reason you can''t find it easilly on the net is because few people are prepared to share what they took so long to make, unfortunately. What you will find, however, will be so specifically tailored to a specific application that you will have trouble using it in your own engine unless you really understand it, which, in that case, means you could have written it yourself...

If your level is flat you may want to use some simple boundary exclusion code like:

if (userpos = beyond boundary) usepos = last userpos;
SimDemon
SimDemon
Well, I gues it will wait a while. I am 15 and in 8th grade. I DO want to take math courses in HS and COLLEGE. Anyhow, thanks for trying to help.

If thispost = 0 Then
GoBack()

Else
Read()
End If
I'll have a link to the TriFaze website as soon as possible. It's still currently being designed, by myself of course! =) I'll update the URL and my signature as soon as possible.Feel free to send me a message on Yahoo! or AOL IM™. =)
NaliXL
NaliXL
Have you ever looked at gametutorials.com ? There are some pretty good tutors over there, amongst others involving collision detection. I think you''d best start with reading "Line Segment and Plane Collision", and then all the way down...
Newbie programmers think programming is hard.Amature programmers think programming is easy.Professional programmers know programming is hard.
Frank Henry
Frank Henry
yep, gametutorials has some very good tutorials on math and collision detection.

You could also check out OpenGL Game Programming. Writen by the guy''s that manage GameDev, it also includes Jeff''s demo''s and edited by La''mothe.
It has everything a beginner needs to build basic to advancev opengl games.

cu

frank
-----------
www.star-ship-captain.tk
haro
haro
I use spherical collision detection.. Probably not the most efficient, but its easy and it works fine for me. There is a downside, for every "thing" drawn, you have to treat it as an individual object, with a vertex representing its "center". From, then just take the distance between the player and the object (sqrt((x1-x2)^2 + (y1-y2)^2 + (z1-z2)^2)). If that distance is less than the "radius" of the object, compared to the "radius" of the player, then there is likely a collision. After detecting a basic spherical collision, I usually then have a more efficient collision detectiong algorithm to make sure they are definately hitting each other. This is since a radius can "lie".

Hope that makes sense..
masterg
masterg
Hm...15 in 8th grade? I feel so extremely young; I am 14 in 9th grade. Sorry, for that random thought. I am taking a geometry course, that has been consistently easy throughout the entire year, because I learned at the age of 13 from various books / websites "basic" Geometry. Check out the following web sites
http://archives.math.utk.edu/visual.calculus/
http://mathworld.wolfram.com/

If you have the money, buy the book OpenGL Game Programming, for a fairly comprehensive chapter on collision detection. You don''t sound like you have a strong grounding in programming though...so, I would review / read up if I was you. Good luck


masterghttp:/masterg.andyc.org
haro
haro
Collision maps aren''t an easy solution?
Jedi of Myth
Jedi of Myth
SimDemon, I''m not sure if you are aware, but gamasutra.com has decent articles discussing collision detection. This page http://www.gamasutra.com/features/20000210/lander_01.htm explains the various types of collision detection and provides some sample code.

I asked one of the Black Robes why the Deceiver wasn''''t going to stay to defend the dam, and he tersely replied: "He goes to warn the Emperor; moving through odd angles, faster than any man, and if unobserved, much faster than that."
I asked one of the Black Robes why the Deceiver wasn't going to stay to defend the dam, and he tersely replied: "He goes to warn the Emperor; moving through odd angles, faster than any man, and if unobserved, much faster than that."Elemental Engine: ryan_lurvey.tripod.com/engine.html

Topic Locked

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

Sign in to reply to this topic.