PDA

View Full Version : How to point where you shut ?


Mark_Tempe
04-17-2007, 10:49 AM
I am thinking of an algorithm which allows a player seen from above to point w in the direction he is shooting. Like in Crimson Land or R.I.P.

Just to relax everybody , I am not planning to make a clone, I need this in case one of the next installments of 1000 crystals of altaxia (http://www.verybiggames.com/) will have a possibility of landing on planets.

Also if anybody can recommend a good book on AI and game algorithms I’m all ears.

Nexic
04-17-2007, 12:46 PM
I am thinking of an algorithm which allows a player seen from above to point w in the direction he is shooting. Like in Crimson Land or R.I.P.

Huh? You're asking how to make a game where your character faces towards the mouse pointer? This is basic trigonometry and is all over the internet. If the engine you're using has forums go there, no doubt it's been covered. A lot of engines have built in functions to deal with this if you're not so good with math.

Pyabo
04-17-2007, 12:47 PM
Slightly confused... what exactly are you needing help with? This is simple geometry... which I'm sure you've done before. The keywords here being sine, cosine, and tangent...

And there's nothing wrong with making a clone. :)

Mark_Tempe
04-17-2007, 01:17 PM
I have done a little searching using google before I posted here. I guess I just used wrong key wards , and I am not using a engine, my game is a sort of Frankenstein monster comprising of my own code , peaces of code I found on the internet and in books, but thanks I will look around.

RinkuHero
04-17-2007, 01:26 PM
Most engines have some command like this (this is Game Maker's):

point_direction(x1, y1, x2, y2);

That will return the direction (in degrees or, alternatively, radians) from the first point to the second point.

I believe it's actually equivalent to:

atan2(y2-y1, x2-x1);

Therion
04-18-2007, 02:02 PM
I just posted a solution to your problem here

http://forums.indiegamer.com/showthread.php?t=10459

hope it helps...

Bad Sector
04-18-2007, 04:26 PM
which I'm sure you've done before.

Don't be.

I didn't knew a slight about trigonometry until i decided to get my hands dirty with 3d game programming. I never paid any attention in math at school (in fact i got a mark "1" in math in the finals - with the maximum being "20"). I learned myself later via the net and by 3d programming, but it wasn't easy because everyone (in 3d tutorials, etc) assumed that i already knew these.

Mark_Tempe
04-18-2007, 08:53 PM
Thanks Therion , I read your thread before I noticed you posted hear.
I also found some staff on the net after I included in key wards : sine, cosine, and tangent.

thanks again

Pyabo
04-19-2007, 12:49 PM
OK, maybe I should have said, "I'm sure this was covered in your basic math education..." Whether or not you actually paid attention is another matter.

Probably 95% of people (in the US) could not answer Mark's original question, despite 99% of them having at least 4 or 5 years of math education past grade school. Kind of sad, really.

soniCron
04-19-2007, 01:06 PM
Until 3 years ago, I wouldn't have been able to answer, either. And this is coming from a guy who graduated at 16 and was placed in Cal 2 in college. Go figure. :p

Karja
04-19-2007, 01:20 PM
I think I'd like to split those 95%: 80% couldn't answer due to lacking maths skills, and 15% couldn't answer due to the incoherent question. :)

But yes, I'm with soniCron - I had to look it up as well when I needed a function like this. (Then again, I suck at trig.)

electronicStar
04-19-2007, 05:17 PM
OK, maybe I should have said, "I'm sure this was covered in your basic math education..." Whether or not you actually paid attention is another matter.

Probably 95% of people (in the US) could not answer Mark's original question, despite 99% of them having at least 4 or 5 years of math education past grade school. Kind of sad, really.
I don't really think it's sad. The only reason why I can answer these question is because programming game engines is my hobby. But the majority of people doesn't need this knowledge so they don't need to know it.
I wouldn't have been able to answer that either in the year 2000 despite my level of studies, but I had access to enough material to become competent so there is still hope.

Pyabo
04-20-2007, 12:54 AM
Well... in all honesty, I didn't just spit out "oh the answer is atan((y1-y2)/(x1-x2))" because even I didn't know it off the top of my head. But, like most of you, I knew how to *solve* the problem. That's the real issue...