[gameprogrammer] Re: How to lead off a bullet?
- From: Sami Näätänen <sn.ml@xxxxxxxxxxxx>
- To: gameprogrammer@xxxxxxxxxxxxx
- Date: Thu, 18 Jan 2007 12:54:30 +0200
On Wednesday 10 January 2007 20:50, Alan Wolfe wrote:
> Wow, this list never ceases to amaze (:
>
> Thank you David and Leighton, I'm going to play with both solutions
> and see what I can figure out, maybe even some kind of hybrid which
> does an aproximation like you were talking about David.
>
> Thanks again (:
> Alan
You get nice realism if you make small random changes to the real
direction and speed of the target (player). Make the changes depend
from the orientation of the target to add more realism.
What this random change mimics?
Well if you look human running in a direction, which is in 90 degree
angle from your line of sight, then the speed is easier to aproximate
than if the heading angle is closer to 0 degree. But for the angle it
holds the opposite.
So if you give these random "corrections" then the closer the target is
or the slower it moves the less the effect of the randomness kicks in
and thus the more accurate the shooter is.
There is one more good random correction too. The distance to the target
can be randomly adjusted in a function of the real distance.
This way the further away the target is the harder it is to know how far
exactly the target really is.
These random corrections should of course diminish for every completed
shot as long as the aspects of the targets movement and position stays
nearly the same. Testing is the key here.
> On 1/9/07, Leighton Haynes <dayta@xxxxxxxxxxxxxxxxx> wrote:
> > You're looking for the time 't' when the distance between the enemy
> > position and the player's predicted position equals the bullet
> > distance at time 't'.
> >
> > Assume enemy position at time zero is ex,ey
> > Assume player position at time zero is px,py
> > Bullet speed equals bs
> > Player speed equals ps
> > Normalised player direction is dx,dy
> >
> > Player position at time t, pos(t) = px + dx*t, py + dy*t
> > Vector from enemy position vec(t) = px + dx*t - ex, py+dy*t - ey
> > Distance from enemy position dis(t) = sqrt((px + dx * t -ex)^2 +
> > (py+dy*t-ey)^2)
> > Bullet distance bdis(t) = bs * t
> > equating dis(t) and bdis(t):
> > bs * t = sqrt((px + dx * t -ex)^2 +(py+dy*t-ey)^2)
> > You should simplify this equation by squaring both sides and
> > multiplying out the squared terms, then grouping them. This will
> > simplify to a quadratic equation of the form:
> > 0 = a*t^2 + b*t + c
> > the solution to which is t = (-b +- sqrt(b^2 - 4ac))/2a
> > This gives two times, pick the most appropriate one.
> >
> > Leighton...
> >
> > If it's in 3d, do the
> >
> > On Tue, Jan 09, 2007 at 09:48:17PM -0800, Alan Wolfe wrote:
> > > Hey guys,
> > >
> > > I'm trying to program something in a game of mine but am not
> > > having much luck.
> > >
> > > Basically what i'm trying to do is make an enemy be able to shoot
> > > a bullet that leads off on the player so that if the player
> > > doesnt change course it will hit them.
> > >
> > > I started working it out on paper but haven't gotten very far ):
> > >
> > > As far as i see it (i might be wrong) i know these things:
> > >
> > > *Player's current position
> > > *Player's direction
> > > *Player's speed
> > >
> > > *Bullet's current position (where the enemy is)
> > > *Bullet's speed (all bullets go the same speed)
> > >
> > > and i'm trying to find...
> > >
> > > *Bullet's direction
> > >
> > > Anyone have any idea how to do this? My solutions keep making
> > > the bullets go wierd ways heheh
> > >
> > > ---------------------
> > > To unsubscribe go to http://gameprogrammer.com/mailinglist.html
> >
> > --
> >
> > #0421 113 305 - dayta@xxxxxxxxxxxxxxxxx
> > "Linux is legacy, but it will be a start." Ken Kutaragi - SCE
> >
> > ---------------------
> > To unsubscribe go to http://gameprogrammer.com/mailinglist.html
>
> ---------------------
> To unsubscribe go to http://gameprogrammer.com/mailinglist.html
---------------------
To unsubscribe go to http://gameprogrammer.com/mailinglist.html
- References:
- [gameprogrammer] How to lead off a bullet?
- From: Alan Wolfe
- [gameprogrammer] Re: How to lead off a bullet?
- From: Leighton Haynes
- [gameprogrammer] Re: How to lead off a bullet?
- From: Alan Wolfe
Other related posts:
- » [gameprogrammer] How to lead off a bullet?
- » [gameprogrammer] Re: How to lead off a bullet?
- » [gameprogrammer] Re: How to lead off a bullet?
- » [gameprogrammer] Re: How to lead off a bullet?
- » [gameprogrammer] Re: How to lead off a bullet?
- [gameprogrammer] How to lead off a bullet?
- From: Alan Wolfe
- [gameprogrammer] Re: How to lead off a bullet?
- From: Leighton Haynes
- [gameprogrammer] Re: How to lead off a bullet?
- From: Alan Wolfe