Our new Indie Games subforum is now open for business in G&T. Go and check it out, you might land a code for a free game. If you're developing an indie game and want to post about it, follow these directions. If you don't, he'll break your legs! Hahaha! Seriously though.

Our rules have been updated and given their own forum. Go and look at them! They are nice, and there may be new ones that you didn't know about! Hooray for rules! Hooray for The System! Hooray for Conforming!

## Posts

[ed] Oh, crap. It won't even install. Hmmmmm. That might be more of an issue.

This was the article I was thinking of. It's from a google cache, 'cause the guy's changed his site since he posted the article.

iTunesIsEvilonMichael HonRobots Will Be Our Superiors (Blog)

http://michaelhermes.com

I said to myself "I'll use math, and I'll cheat." I constructed a scenario.

Bullet emitter at (ex,ey), target at (tx,ty). Not shown is the intercept point for the fired bullet, (ix,iy). Coordinate system uses screen coordinates, so the top left is 0,0 and positive Y goes down instead of up. For a given angle of movement

theta, the X deflection is cosine(theta) and the Y deflection is sine(theta), with theta 0 pointing to the right.So I tried to get Mathematica to do all the work.

I ended up with output in disjunctive normal form -- a bunch of either-or situations. Problem is, I got 28 different scenarios, many of them special cases where the target is not moving or is moving directly toward or away from the emitter.

http://mspencer.net/PA_XNA/TargetLeading2.pdf

The plan is to interpret these as code for a branching tree of execution: some conditions will be tested to tell the difference between special cases, and some conditions will be go/no-go and will tell me if a firing solution even exists.

mspenceronMEMBER OF THE PARANOIA GM GUILDXBL Michael Spencer || Wii 6007 6812 1605 7315 || PSN MichaelSpencerJr || Steam Michael_Spencer || Ham NOØK

QRZ || My last known GPS coordinates: FindU or APRS.fi (Car antenna feed line busted -- no ham radio for me X__X )

MKRonHowever, it's a lot simpler than that, it forms a triangle TEI where the ratio of sides EI and TI are the ratio of the speeds of the bullet target respectively (since there is no acceleration) and angle ETI is known (as the direction of travel is known and fixed.

Now, to calculate the optimal intercept point, you require minimal deflection from a straight shot at your target so we will be calculating the minimum internal angle TEI which is given by the smallest possible length of side TI

Distance of any point k along line TI from E is given by the law of cosines: EI² = k² + ET² - 2k*ET*cos(ETI)

You are looking for the smallest k where: sqrt(k² + ET² - 2k*ET*cos(ETI)) == k * ratio

Where ratio is speed of bullet / speed of ship

k² + ET² - 2k*ET*cos(ETI) == k² * ratio²

k²(1 - ratio²) -2k*ET*cos(ETI) + ET²

k = (2*ET*cos(ETI) +- sqrt(4*ET²*cos²(ETI) - 4ET² + 4ET²*ratio²)) / (2-2ratio²)

There are some restrictions on the result. k should be chosen as the smallest positive result. Only negative k indicates that there was a solution in the past but none in the future. Imaginary k indicates no solution.

The angle is trival to calculate given the intercept point.

Example

E is at 0,0

T is at 0,5

T is moving horizontally at 5 units/s therefore ETI = 90 degrees

Bullets move at 10 units/s

k²(1 - ratio²) -2k*ET*cos(ETI) + ET²

k²(1 - 4) -2k*5*0 + 25

-3k² + 25

Ratio is 2

k = 2.8867

We would expect the length of EI to be double that or 5.7735

Since it's a right triangle, 5² + 2.8867² = 5.7735²

edit: I suppose there's also the case where E, T and I are collinear and so don't actually form a triangle, however the in that case you always shoot directly at them if bullet speed + closing velocity is positive

PhyphoronAcademician Prokhor "Phyphor" Zakharov, Chief Scientist of China, Provost of the University of Planet - SE++ Megagame

I messed with it a couple of years ago trying to make a single-player Wurm clone, but my head exploded when I started trying to learn about drawing a 3D landscape, specifically one that used square tiles and was deformable. Are there any good resources for doing that kind of stuff, preferably specifically for XNA? Or hell, some sort of library that does that stuff for me?

Sir CarcassonSteam Support is the worst. Seriously,

the worstStarting tonight: a tile-based map editor! oooooooooooooooexciting.

FearghaillonI have a book

XNA 3.0 Game Programming Recipes: A Problem-Solution Approachby Riemer Grootjans with a chapter about something like that. This book assumes you already understand the basics and essentially discusses individual problems to solve and how you solve them. I don't think it covers deformation, but you could try modifying the terrain heightmap array dynamically and see if anything breaks. The author's web site is here: http://www.riemers.net/Specifically two sections seem applicable to 3D terrain rendering:

2-10: Use a Quadtree to Hide Parts of a Grid That Are Not In Sight

2-11: Create a Real-Time Camera-Dependent Optimally Adapting Mesh (ROAM) Terrain

At the end of 2-10 the author talks about terrain being such a large subject he could fill an entire book with it.

mspenceronMEMBER OF THE PARANOIA GM GUILDXBL Michael Spencer || Wii 6007 6812 1605 7315 || PSN MichaelSpencerJr || Steam Michael_Spencer || Ham NOØK

QRZ || My last known GPS coordinates: FindU or APRS.fi (Car antenna feed line busted -- no ham radio for me X__X )

Yeah, that's kinda the impression I got when I was doing my research. I'll look around some more.

Edit: Looking at his website, I actually remember following those tutorials. They were pretty awesome.

Sir CarcassonSteam Support is the worst. Seriously,

the worstI did initially try using geometry and trig, but all I could remember required use of right triangles. I had this construction where I took a tangent line to the target's movement vector and constructed a right triangle there. I used the ratio of the triangle's legs as the ratio of the speeds, but I couldn't figure out how to handle the case where the target is behind or in front of the 90-degree part of the right triangle. I ended up having to add or subtract the offset, and the offset didn't scale with the speeds.

It's so much easier when the triangle doesn't have to be a right triangle!

Thank you kindly. I'm still working through and absorbing what you wrote, charting it out with paper and pen.

mspenceronMEMBER OF THE PARANOIA GM GUILDXBL Michael Spencer || Wii 6007 6812 1605 7315 || PSN MichaelSpencerJr || Steam Michael_Spencer || Ham NOØK

QRZ || My last known GPS coordinates: FindU or APRS.fi (Car antenna feed line busted -- no ham radio for me X__X )

Also, I learned C# from the "Head First C#" book, which was really nice because the end project is to build a Space Invaders clone (they provide the sprites).

pheknoonPhyphoronAcademician Prokhor "Phyphor" Zakharov, Chief Scientist of China, Provost of the University of Planet - SE++ Megagame

Yeah I sat down with XNA last night and I was amazed at how simple it was to make a guy move around the screen.

Back in the day it took me a half a week to write something that good, but I did it in about 2 minutes.

bowenonKyanilisonThe second page of that document is in disjunctive normal form (like: A-and-B, or A-and-C-and-D, or A-and-C-and-E, or . . .) and it lists only nine scenarios. I've been studying them and so far they make sense.

The beginning of the expression (tx=0) is the first scenario, and then each time you see OR (huge letter V like symbol) c1 subset of

Z(set of integers), that's a new scenario.Scenario 2: if the target is on the X axis (ty == 0) and is not moving, fire directly at it.

Scenario 3: if the target is on top of the cannon, fire to the left. (Weird duplicate of scenario 1.)

Scenarios 4 and 5: these cover most non-special-case scenarios and will be explained later. (once I figure out how they work and what each expression means.)

Scenario 6: if the target is headed toward the x-axis, timed just right so a bullet fired along the x-axis will reach the target, go ahead and fire directly along the x-axis. Must be a special case that avoids making another formula divide by zero.

Scenario 7: if the target is on the X axis and is not moving, fire directly at it. (Opposite of Scenario 2.)

Scenario 8: if the target is on the Y axis and is heading toward the X axis at just the right angle that the horizontal component of motion exactly matches a bullet's speed, fire directly along the X axis.

Scenario 9: if the target is on a collision course with the origin (flying directly at the emitter) then fire directly at the target. (Edit: on closer examination, I don't think this does what I think it does. theta is 2*arctan. Something is weird.)

mspenceronMEMBER OF THE PARANOIA GM GUILDhategame math, just throwing that out there.bowenonPhyphoronAcademician Prokhor "Phyphor" Zakharov, Chief Scientist of China, Provost of the University of Planet - SE++ Megagame

mspenceronMEMBER OF THE PARANOIA GM GUILDScroffusonThat's probably how I'd do it. That's also how you'd probably do it in terms of 3d space too.

http://cs.fit.edu/~wds/classes/cse5255/thesis/lineEqn/lineEqn.html

Use those.

bowenonYeah, that's what I figured. I'm so glad my high school math is useful. Screw those other kids who said I'd never use it, now who's laughing!

ScroffusonbowenonScroffusonmspenceronMEMBER OF THE PARANOIA GM GUILDbowenonDon't worry, soon you will do something with the content pipeline that's not loading a texture and then the true horror will begin.

Alistair HuttononI made a game, it has penguins in it. It's pay what you like on Gumroad.Currently Ebaying Nothing at all but I might do in the future.

bowenonHaving been laoding information as both ContentPipeline serialised XML and my own free form effort parsed with LINQ I would say the LINQ method did not cause me to tweet offensive message at Shawn Hargreaves.

(Overall the ContentPipeline method is better but the fucking invisible hoops you have to jump through first!)

Alistair HuttononI made a game, it has penguins in it. It's pay what you like on Gumroad.Currently Ebaying Nothing at all but I might do in the future.

bowenonmspenceronMEMBER OF THE PARANOIA GM GUILD