| 07-15-2008, 09:47 AM | #1 |
I'm planning on making a spell involving a homing projectile, but I want to allow it to 'miss', and I can't really figure out how I'm going to tell if it's missed, and how to slow it down, and make it turn back correctly. I'll try and make an example :D Projectile - Fireball Target - Peasant So, the fireball is flying towards the peasant, gradually gaining speed. As the fireball nears the peasant, the peasant moves to the side. The fireball attempts to turn to follow the unit, but it doesn't succeed. As a result, it travels beyond the peasant, but gradually slows down (doesn't stop moving at any point) to try and turn to face the peasant, and when it's facing the peasant, it begins to speed up again. Fireball travels towards the peasant again, and the peasant moves slightly, but not enough. Fireball is just about able to turn towards the peasant, and BOOM! Peasant explodes! (If you have played Hungry Hungry Felhounds, you might know what I'm on about :P) What I need to figure out: 1) How will I know when the fireball is out of reach of the target, and must turn around? 2) Some ideas on values e.g. what should be the maximum turn speed/sec (in degrees) at full speed and minimum speed, how fast should the fireball accelerate/decelerate? (I'm planning on 300 min speed, 700 max speed) |
| 07-15-2008, 10:01 AM | #2 |
All you have to do is to separate speed from accelleration. You keep the fireballs x and y speed. Each interval you calculate the x and y accelleration towards the peasant, and add that to the speed. |
| 07-15-2008, 10:08 AM | #3 |
I know that much, but I don't know how to tell when he has missed the target, or how to make it so that high movement speed = low turning speed, and low movement speed = high turning speed. My idea on move speed -> turning speed is (Minimum turn speed)/(Current speed/Maximum speed). And if min turn spd was 5 At maximum speed, you would only be able to turn 5 deg/sec (I think) 5/(800/800) 5/1 5 But, at half max speed, you should be able to turn 10 deg/sec 5/(400/800) 5/(0.5) 10 But that's awfully slow turning at low speed. I was hoping that around 30-40 degrees could be covered at 400spd, and 800spd would be only 5-10 degrees |
| 07-15-2008, 10:10 AM | #4 |
You have two vectors; a and b. Vector a is the missiles velocity, vector b is the displacement of the target from the missile. If the dot product of a and b is less than 0, the angle between the two vectors is greater than 90 degrees, so the missile has past the target. |
| 07-15-2008, 10:13 AM | #5 | |
Dot product? Quote:
Wouldn't that only allow for misses at the left side? |
| 07-15-2008, 10:20 AM | #6 | |
Dot product: (x1*x2+y1*y2+z1*z2) Quote:
Edit: some crappy drawings |
| 07-15-2008, 10:33 AM | #7 |
Ahm, for the z1*z2, can I just put in 0? I don't plan on factoring in Z height And your drawings confuse me. What's the red dot signify, and what does the black dot signify? |
| 07-15-2008, 10:34 AM | #8 | |
Red dot = target, black dot = missile. Quote:
|
| 07-15-2008, 01:03 PM | #9 |
Yeah, dot product is the easiest way to go, however in order to be really able to control the way the missile flies it might be better to get the exact angle between the projectile velocity and the line between the projectile and the target. That way, you could make the projectile start accelerating again only when the target is, for example, within 60 degrees of the projectile's facing vector; otherwise, depending on the turn rate and the acceleration, the projectile might accelerate too fast and then not be able to turn towards the target quickly enough, resulting in it spinning around the target endlessly. You can still use just the dot product, though, if you calibrate your turn rates and acceleration correctly this might not happen even if the projectile starts accelerating again the moment the target is in front of it. |
