Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Discussion / AI for 'scorched earth' style game...

Author
Message
FROGGIE!
21
Years of Service
User Offline
Joined: 4th Oct 2003
Location: in front of my computer
Posted: 30th Jul 2004 01:22
Obviously i wont ask you for code with this being for the comp, but i just need some help on how to do this. How do you get the computer to work out the angle and speed it needs to shoot something including considering the wind speed.

I should have changed my signature when asked
Mattman
21
Years of Service
User Offline
Joined: 5th Jun 2003
Location: East Lansing
Posted: 30th Jul 2004 01:25
I would say have them try random stuff, and then remember it. Like if they have it too high and it misses, have them lower it. If it it too far to the right, have them aim to the left, etc.

"Could you do something where you don't need a video card cause i don't have one" - Program Expert
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 31st Jul 2004 07:48
Actually, the formula is a simple matter of physics....
Though I'm afraid I do not remember it. (It's in the book Applied Mathematics.)

Basically, it's a function of the angle of fire (up to 45 degrees for the maximum distance, versus the wind speed and atmosphere drag applied to the power of the firing charge,) and is a fixed quality for any distance to be computed. I'm not sure how Scorched Earth managed the formula, but recall that Di Vinci did a study on the subject.

Like I said, it's a standard formula; would that I could remember it....
S.

Any truly great code should be indisguishable from magic.
BearCDPOLD
21
Years of Service
User Offline
Joined: 16th Oct 2003
Location: AZ,USA
Posted: 31st Jul 2004 15:42
An easy way to do it would be to use a hyperbola. You plug in different values to its equation and it gets taller, shorter, thinner, or wider. Then you use the curvevalue() command to slowly come to the top of the arch then accelerate toward the ground. As for the hyperbola equation.........I gotta look through my math notes.

Crazy Donut Productions, Current Project: Project Starbuks
Sony stole our name!
AsriCE
22
Years of Service
User Offline
Joined: 10th Jan 2003
Location: Brunei
Posted: 1st Aug 2004 15:59 Edited at: 1st Aug 2004 16:00
Hi,

Here's the formula on how to do 3D projectile or should I say, path of bullets based on the initial speed and angles :

Quote: "
Pos(X) = (U * COS(AngleX) * SIN(AngleY) * Time
Pos(Y) = (U * SIN(AngleX) * Time) - ((9.8*Time*Time)/2)
Pos(Z) = (U * COS(AngleX) * COS(AngleY) * Time

Where, U = Initial Velocity
Pos = Current position of object through time of projectile.
Time = The incremented time by small time steps.
9.8 = A constant gravitational earth acceleration in (m/s²). For a moon, it would 1.6m/s². The higher this value is, the greater the gravitational pull."


If you wanted to add some A.I, then just do random angles and initial velocities for the computer. I've got the whole code for this, and I can share it with all of you if you want. But since you mentioned that you don't want the code for this and you're doing this for the compo, I suspect that you would want to learn it and not expecting any spoilers. But still, I'll post it up if I get any request Hope that helps.

AsriCE Crew,
- Adi

There's only one hope.
NathanF
21
Years of Service
User Offline
Joined: 24th Mar 2004
Location:
Posted: 1st Aug 2004 18:53 Edited at: 1st Aug 2004 18:54
Is this assuming the buulet is launched from 0,0,0?
If so, then you would go:

Pos(X) = (U * COS(AngleX) * SIN(AngleY) * Time
Pos(Y) = (U * SIN(AngleX) * Time) - ((9.8*Time*Time)/2)
Pos(Z) = (U * COS(AngleX) * COS(AngleY) * Time
position object obj,oldx+Pos(X),oldy+Pos(Y),oldz+Pos(Z)

With oldx, oldy, and oldz as the position of the bullet when launched.
Am I right?

"I....I like rice?"
Arkheii
21
Years of Service
User Offline
Joined: 15th Jun 2003
Location: QC, Philippines
Posted: 1st Aug 2004 20:46
Mmmm... Really tempting to put our projectile motion lessons to use.

I'd vote for the trial and error thing so that it doesn't look like the AI is cheating. You'd have the initial aim look something like:

if heIsAboveMe()
increaseShotAngle()
increaseShotPower()
...
endif

If the shot misses, then adjust it accordingly. But you could add an "impatience" level to the AI, so if it's been taking too long then you could let it use the equations for perfect aim.

AsriCE
22
Years of Service
User Offline
Joined: 10th Jan 2003
Location: Brunei
Posted: 2nd Aug 2004 03:37
@Dark Sephiroth,

Umm not exactly. The equations I've provided above computes the Current position based from the Time. So by incrementing(progressing) the time, you're actually computing the positions at that instant time. So there's no actually need to add/subtract from the old position, but you need to increment the time though to update the projectile motion. As follows:

Quote: "
Starting From Zero Seconds
Compute Position At Zero Seconds
REM Assuming Every Loop Is 15 Millisecond
TimeStep Is 0.015
Begin Loop
Increment Time By TimeStep
Compute Position At New Time And Store Values(X, Y, Z)
Position Object Based From The Calculated Data
End Loop"


Does that make any sense? Or non-sense? hehe

AsriCE Crew,
- Adi

There's only one hope.
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Aug 2004 05:09
What he means is that your code will project a bullet from the origin (0,0,0). But if your standing at (100,0,0) and shoot, the bullet's position will be based on the (0,0,0) origin. So you're right Sephiroth.

"eureka" - Archimedes
NathanF
21
Years of Service
User Offline
Joined: 24th Mar 2004
Location:
Posted: 2nd Aug 2004 14:28
Hey, it worked!
It looks really cool too. It fires the bullet, hits the matrix, and bang, big explosion, matrix goes down. Made a whole function for it.
Thanks AsriCE, you've saved me a lot of work

"I....I like rice?"
AsriCE
22
Years of Service
User Offline
Joined: 10th Jan 2003
Location: Brunei
Posted: 2nd Aug 2004 14:43
No prob, I'm glad it helped But if you want the ball to shoot from an offset position rather than the origin, it's kinda simple too. You just have to make a new variable called the "Initial Position" and add the calculated values from the origin to the Initial Position.

Begin Loop
Increment Time By TimeStep
Compute Position At New Time And Store Values(X, Y, Z)
New Position = Initial Position + Stored Values
Position Object Based From New Position
End Loop

AsriCE Crew,
- Adi

There's only one hope.
NathanF
21
Years of Service
User Offline
Joined: 24th Mar 2004
Location:
Posted: 2nd Aug 2004 15:39
Quote: "What he means is that your code will project a bullet from the origin (0,0,0)"


Quote: "position object obj,oldx+Pos(X),oldy+Pos(Y),oldz+Pos(Z)
With oldx, oldy, and oldz as the position of the bullet when launched.
Am I right?"




"I....I like rice?"
AsriCE
22
Years of Service
User Offline
Joined: 10th Jan 2003
Location: Brunei
Posted: 2nd Aug 2004 15:48
wahaha .. yeah you're right. How can one be so careless in reading? I missed the "When launched" part lalala~~

AsriCE Crew,
- Adi

There's only one hope.
NathanF
21
Years of Service
User Offline
Joined: 24th Mar 2004
Location:
Posted: 17th Aug 2004 19:45
Umm, I know this post is pretty old and all, but I had just one last question on this topic. Would anyone know how to work out the reverse? Getting the angles based on positions? Then you could add like 'rnd(20)-10' to each angle, to give it some randomness. I'm really stuck...

Normal:
Quote: "
Pos(X) = (U * COS(AngleX) * SIN(AngleY) * Time
Pos(Y) = (U * SIN(AngleX) * Time) - ((9.8*Time*Time)/2)
Pos(Z) = (U * COS(AngleX) * COS(AngleY) * Time
"


Reverse:
Quote: "
AngleX=???
AngleY=???
"


Anyone...?

"I....I like rice?"
Izzy545
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 17th Aug 2004 23:08
I can't seem to get this to work... I'm using the following code:



They return wierd values and it won't shoot correctly...
NathanF
21
Years of Service
User Offline
Joined: 24th Mar 2004
Location:
Posted: 18th Aug 2004 17:13
Are you trying to normally fire? Or to find the angles?
If it's firing, then switch the z and y, and change all ^s to *s.

Just another thing, if I'm trying to find a set of x/y angles to match the inputted positions, I would have to input players x/y/z and target x/y/z, so to make my question a bit simpler:

Quote: "
AngleX=??? (player x/y/z) (target x/y/z)
AngleY=??? (player x/y/z) (target x/y/z)
"


I can't do the checking thing, because this is turn based and the enemy only gets one turn at it.

"I....I like rice?"
JerBil
21
Years of Service
User Offline
Joined: 8th May 2004
Location: Somewhere along the Z axis...
Posted: 19th Aug 2004 11:26
@ Izzy545
Here's a sample of my code for moving an object in a trajectory.
Notice that xt# is applied to the Z axis of the object (obj), even though I have called it x.

All values are Real numbers, not Integers.
We are moving down the Z Axis.

z_obj# is the launch point on the Z axis.
y_obj# is the launch point on the Y axis.

The math, then, is ADDED to the launch point with each INCrement of time#. Notice it does not take a very big change in time.

Variables cosangleF# and sinangleF# I assigned at the start of the program so I don't have to do them over and over.

energyF# is the starting energy at launch, and
angleF# is the elevation in Degrees at launch.

cosangleF#=energyF#*cos(angleF#) `where along path
sinangleF#=energyF#*sin(angleF#) `height on path

They are referenced in the code below. If variable moveA=1, then
the code is executed. Gravity is 32.2, but you can use 9.8 as well.


`move code
if moveA
`increment time
inc time#,0.003
tsqr#=time#*time# `square time (time * time)
xt#=cosangleF#*time#+z_obj# `figure where object is along x
yt#=sinangleF#*time#-(gravity#*tsqr#)/2+y_obj# `height of object
position object obj,object position x(obj),yt#,xt#
endif
Izzy545
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 21st Aug 2004 01:05
It doesn't seem to work... Here's my bullet code:

JerBil
21
Years of Service
User Offline
Joined: 8th May 2004
Location: Somewhere along the Z axis...
Posted: 21st Aug 2004 11:48
Izzy454,
Thanks for trying my code. I have made a couple changes to show you it can work, but I rem'ed out some of your code cause I didn't have your objects & so on.

The Move command is not needed with my code, as it moves the bullet on it's own, and you must use bullettime# instead of bullettime. The same with oldx#,oldy# and oldz#.

In fact, anytime you want to use a fractional number, like 1.5 in a variable, make sure you use # at the end of the variable.

You also needed a return at the end of your subroutine.
For this test, I use a right click to "set" the trigger,
then left click to fire. This is just to make sure it works ok.
I have a text statement that shows TimeToShoot as 1 when
you right click first so you can see what's happening.

I changed the fireing angle to zero degrees, and my bullet I
made from a cube will go off into the distance. You had it at 90 degrees, and it went straight up, of course.

Good luck,
-JerBil

Login to post a reply

Server time is: 2025-05-25 13:13:48
Your offset time is: 2025-05-25 13:13:48