• Advertisement
Sign in to follow this  

Predictive aim with a parable in Tower defense game

This topic is 914 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Im developing a tower defense, so ive got this archer tower that shoots arrows in a parable. Ive got the method that calculates the needed parable to get from the tower to any ponint. Ive got the enemy speed in x and y, and position. The problem cames when i need to do the predictive aim.

I used the following equations to make it and im really close because it works sometimes but i dont know why it doesnt work always.

Ptarget impact = Ptarget now + t × vtarget
Pshot impact = Pplayer + t × vshot
Ptarget impact = Pshot impact
Ptarget now + t × vtarget = Pplayer + t × vshot
Ptarget now - Pplayer = t × vshot - t × vtarget
t × (vshot - vtarget) = Ptarget now - Pplayer
t = (Ptarget now - Pplayer) / (vshot - vtarget)
t = ?position / ?velocity
Ptarget impact = Ptarget now + (?position / ?velocity) × vtarget

I think the problem is on vshot, because i move the arrow like this:

if(!objectiveOnFront)
{
xPos = xPos - (Time.deltaTime*speed);
} else
{
xPos = xPos + (Time.deltaTime*speed);
}
transform.position = new Vector3(xPos, ParableY(xPos),transform.position.z);

So, i dont know how to express vshot in x and y.

Can somebody help me?

Thanks in advance!

Edited by fausto1124

Share this post


Link to post
Share on other sites
Advertisement
Unless you have Jesus towers dispatching wisdom in the form of short exemplary tales, you probably want to use the word "parabola". smile.png

So thinking back to the problem where the enemy doesn't move, there is a one-parameter family of solutions to the problem of hitting the target with a projectile in the absence of drag. Do you also try to hit the target as soon as possible (equivalently, with as shallow a parabola as possible)?

Share this post


Link to post
Share on other sites
Unless you have Jesus towers dispatching wisdom in the form of short exemplary tales, you probably want to use the word "parabola". smile.png

 

Sorry man! I speak spanish so my translate isnt so good.

 

So thinking back to the problem where the enemy doesn't move, there is a one-parameter family of solutions to the problem of hitting the target with a projectile in the absence of drag. Do you also try to hit the target as soon as possible (equivalently, with as shallow a parabola as possible)? 

 

The problem is that my objective is moving, as i said, ive got the x and y components of the enemys speed.

Share this post


Link to post
Share on other sites

Unless you have Jesus towers dispatching wisdom in the form of short exemplary tales, you probably want to use the word "parabola".

Sorry man! I speak spanish so my translate isnt so good.


I completely understand. I speak Spanish too! (not surprising with a name like Álvaro).
 

The problem is that my objective is moving, as i said, ive got the x and y components of the enemys speed.

Hmmm... Try to read what I said again.

There are infinitely many ways of drawing a parabola that joins your tower and your target, if you are willing to change the angle and the initial speed of the projectile. That means you can in principle hit the moving target at any of its future positions. If your projectile's initial speed is fixed, there are only two solutions. But I don't know exactly what constraints you have.

Share this post


Link to post
Share on other sites

predictive aim and parabolic arc of fire on a given point:

 

you already have parabolic arc of fire to a give point right?

 

and that point is where the target is, right?

 

plug in target location, everything works great, right?

 

ok, now, all you do is plug in where the target will be when the shot lands, not where the target is when you fire.

 

to figure out where it will be:

 

take the range, and divide by the speed of the bullet to get the approximate travel time in turns to the target, which we will call T.

 

when you fire, first move the target forward for T turns to determine approximately where it will be when the shot lands, and shoot at that spot, not where the target is now. this is what's known as "leading the target".

Edited by Norman Barrows

Share this post


Link to post
Share on other sites

fausto1124, on 19 Oct 2015 - 6:11 PM, said:snapback.png

 

Quote

Unless you have Jesus towers dispatching wisdom in the form of short exemplary tales, you probably want to use the word "parabola".

Sorry man! I speak spanish so my translate isnt so good.

 

I completely understand. I speak Spanish too! (not surprising with a name like Álvaro).
 

Mine is Fausto! Haha

 

 

 

Quote

The problem is that my objective is moving, as i said, ive got the x and y components of the enemys speed.

Hmmm... Try to read what I said again.

There are infinitely many ways of drawing a parabola that joins your tower and your target, if you are willing to change the angle and the initial speed of the projectile. That means you can in principle hit the moving target at any of its future positions. If your projectile's initial speed is fixed, there are only two solutions. But I don't know exactly what constraints you have. 

 

Here is what ive got:

- A method that giving it a position to fire to, it will give me a parabola, from the tower to that position. So i can follow that parable in order to make the parabola effect.

- The enemy x and y speed and actual position.

- The speed that the x component of the parable moves. I dont know if i make myself clear at this point.

   Ive got an xPos variable that starts at the origin x position of the tower, so in every tick, i make xPos = xPos + Time.deltaTime * speed;

   and then i make the arrow be at the position xPos, Parable(xPos).

 

So, giving this things i dont know how to do it.

 

 

you already have parabolic arc of fire to a give point right?

Yes!

 

and that point is where the target is, right?

 

I want to have a predictive aim, so that point should be the point where the target will get together with the arrow, thats what i want to calculate.

 

plug in target location, everything works great, right?

 

ok, now, all you do is plug in where the target will be when the shot lands, not where the target is when you fire.

 

to figure out where it will be:

 

take the range, and divide by the speed of the bullet to get the approximate travel time in turns to the target, which we will call T.

 

when you fire, first move the target forward for turns to determine approximately where it will be when the shot lands, and shoot at that spot, not where the target is now. this is what's known as "leading the target".

Thats my problem, because i use a parabola and i move the x variable of the parabola, i dont really have the two components of the speed, i only got the x speed component and i dont know how to calculate the y speed for this. I think thats the only thing that i dont have for this to work

 

Thanks guys!

Share this post


Link to post
Share on other sites
I'll give you the general structure for solving all of these "leading the target" problems.

First you need to figure out how long it takes you to hit the target, as a function of its position; let's call this function Delay. You then need a formula for the position of the target as a function of time; call it Position.

Now you need to find a time t such that Delay(Position(t)) = t. Once you have formulas for everything, you can solve that equation. Then see where the target is at the solution time, and just shoot there.

If you need help figuring out the details, ask again. But please be as descriptive as possible about the exact conditions of your problem.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement