Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  aiming? could call it homing missiled I guess  (Read 4548 times)
0 Members and 1 Guest are viewing this topic.
Offline Ranger
« Reply #30 - Posted 2009-03-20 04:48:59 »

It is slightly slower to no real detriment, but I was just telling the noobs to stay away from it because it was giving them the wrong idea of how they should be approaching this.  Tongue
Oh, cool.  No worries.  That makes sense.  Cheers.  Smiley
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #31 - Posted 2009-03-20 07:28:11 »

to clarify, the only differenec I can notice in vector2D's, and my messed up slopes, is that waht you did was in a seperate class, and it was normalized. I did not know how to normalize. so I was just picking a directoin and firing away.
Offline Hansdampf

Senior Member


Projects: 3


too offending?


« Reply #32 - Posted 2009-03-20 09:01:43 »

You don't want to use atan at all and you never want to use the slope at all. Use vectors.
Ok, forget about the slope thing.
I dont think that using atan2 is evil (unless you move 1 million missiles).
Using atan doesn't prevent you from using vectors. In the case of a homing missile you SHOULD use an angle if you want to have it easy.
Here the pseudo code (I did not test it) for a homing missile with a maximum turn speed:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
class Missile{
  V2 pos;
  double angle,turnspeed,frontspeed;

  public void turnTo(V2 target,float deltaTime){
     double angleToTarget=getAngle(pos,targetPos);  //getAngle uses atan2 here
    double delta=angle-angleToTarget;
     if(delta>0)angle-=turnspeed*deltaTime;
     else angle+=turnspeed*deltaTime;
  }

 void move(float deltaTime){
    V2 speed=new V2(0,frontspeed*deltaTime);
    speed.rotate(angle);  //thats what I meant by 'rotating the speed'
   pos.add(speed);
  }
}

lots of sillystupid games: http://www.emaggame.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Hansdampf

Senior Member


Projects: 3


too offending?


« Reply #33 - Posted 2009-03-20 09:06:23 »

Here's what you do for a homing missile, in pseudo-code.
1  
2  
3  
4  
Vector2 velAdjustment = missilePos - missileTargetPos;
velAdjustment.normalize;
velAdjustment *= missileSpeed;
missileVelocity += velAdjustment;


A homing missile is exactly the same as a ballistic missile except that it can constantly adjust its velocity. A ballistic missile only gets fired once using a given velocity, then stays on that course forever.
This will work for an accelerating homing load of mud, don't do that for a homing missile, that will look very unrealistic.

lots of sillystupid games: http://www.emaggame.com
Offline cylab

JGO Ninja


Medals: 38



« Reply #34 - Posted 2009-03-20 12:27:25 »

This will work for an accelerating homing load of mud, don't do that for a homing missile, that will look very unrealistic.
You might need to dampen die velAdjustment change a bit, to make look more realistic, but otherwise it's a reasonalbe approach.

Mathias - I Know What [you] Did Last Summer!
Offline Hansdampf

Senior Member


Projects: 3


too offending?


« Reply #35 - Posted 2009-03-20 13:23:25 »

But not if you want a fixed turnspeed. Homing missiles don't acc/decelerate, they chance the direction.
If you fire a missile in the direction (1,0) and want to hit a target in (-1,0):

demonpants missile will stay in the same 1-dimensional 'line' and will decelerate until it has speed(0,0), then accelerate again.

my missile makes an elliptical turn

lots of sillystupid games: http://www.emaggame.com
Offline cylab

JGO Ninja


Medals: 38



« Reply #36 - Posted 2009-03-20 13:38:59 »

Ah ok, you are right. I overlooked the "missileVelocity += velAdjustment" line. I think this was a type - this way the missile would accelerate to light speed anyway Smiley it should of course be

1  
2  
3  
4  
Vector2 v = missilePos - missileTargetPos;
v.normalize();
v *= missileSpeed;
missilePos += v;


This equation does not have a fixed turn rate, but you could have some good effects with applying the exponential smoothing (thanks bleb Wink)to the velocity change:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
float a = 0.7f; // smoothing factor
Vector2 v = missilePos - missileTargetPos;
v.normalize();
v.x = a*v.x+(1-a)*lastV.x;
v.y = a*v.y+(1-a)*lastV.y;
v.z = a*v.z+(1-a)*lastV.z;
v.normalize();
v *= missileSpeed;
missilePos += v;
lastV = v;



Mathias - I Know What [you] Did Last Summer!
Offline Hansdampf

Senior Member


Projects: 3


too offending?


« Reply #37 - Posted 2009-03-20 17:22:51 »

hm... I don't think that will solve that 'missile moves like a magnet' thing, but who cares how a missile moves as long as it hits the target Smiley

lots of sillystupid games: http://www.emaggame.com
Offline cylab

JGO Ninja


Medals: 38



« Reply #38 - Posted 2009-03-20 17:41:48 »

it will, since the direction change is smoothed. Actually it will look more realistic than limited turn radious, since it's turn rate adjustes with the target movement.

Mathias - I Know What [you] Did Last Summer!
Offline Hansdampf

Senior Member


Projects: 3


too offending?


« Reply #39 - Posted 2009-03-20 17:54:27 »

Quote
If you fire a missile in the direction (1,0) and want to hit a target in (-1,0):
demonpants missile will stay in the same 1-dimensional 'line' and will decelerate until it has speed(0,0), then accelerate again.
my missile makes an elliptical turn

I can't see see the y (or in 3D including z) component of speed change with your method, it will always be 0.
Maybe I'm wrong, just tell me. Of course you could add some jitter/chaos to prevent that case.

lots of sillystupid games: http://www.emaggame.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline h3ckboy

JGO Coder


Medals: 5



« Reply #40 - Posted 2009-03-20 17:56:28 »

haha, this has gotten so complicated and stuff.
Offline cylab

JGO Ninja


Medals: 38



« Reply #41 - Posted 2009-03-20 18:12:53 »

I can't see see the y (or in 3D including z) component of speed change with your method, it will always be 0.
Maybe I'm wrong, just tell me. Of course you could add some jitter/chaos to prevent that case.

Yep, you are right. This needs some extra tweak, didn't thought of that - good catch! But otherwise this case also has to be treated special with fixed turn rate (left or right turn)

Mathias - I Know What [you] Did Last Summer!
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11


Game Engineer


« Reply #42 - Posted 2009-03-20 18:34:15 »

No, the thing I posted is just fine. I've used that exact code elsewhere. You're not taking into account that it gets called every single time step. Theoretically you make the speed value small (probably < 1) so that it never has too large of an adjustment at one time.

The "velAdjustment" can be seen as the acceleration. If you changed my code to "missilePos += v" as cylab suggested, then it would just move in a straight line towards the target.

This is what happens:
1) The missile gets fired at an initial velocity.
2) The missile's velocity gets adjusted as per the code below, so now it's flying more in the direction of its target.
3) The missile's position gets adjusted by by its velocity (missilePos += missileVel).
4) Go back to #2, repeat.

In a ballistic situation, you should never be adjusting the position of something directly. Instead, you adjust the velocity and that in turn gets carried to the position at the update. When you change the velocity, you're doing so with a given acceleration. Logically that makes sense - you can only ever accelerate something, you can never magically teleport its position somewhere.

If you took my exact code and applied gravity to it, the object would not fall at 9.8 meters per second, it would continue to accelerate at 9.8 meters per second. You're adjusting the velocity by the acceleration of gravity.

Second 0: Object vel = 0.0 m/s. Object pos = 0,0
Second 1: Object vel = -9.8 m/s. Object pos = 0,-9.8
Second 2: Object vel = -19.6 m/s. Object pos = 0,-29.4
Second 3: Object vel = -29.4 m/s. Object pos = 0,-39.2
etc.

It's not moving like a "ball of mud," it's moving dynamically like a real object would. Adjusting the velocity so that it's pointing at a given object is exactly the same process.

And as for damping, usually you have a delta involved that does that for you. Like with gravity, you don't want to be updating only once per second. So if you were updating 60 frames per second, your delta would be 1/60 and so you would apply (1/6) * -9.8 for the acceleration to the object.

Obviously the above would work for something that would need directional rockets on the side as well, but really all homing missiles would need to work that way. You can't turn the thing by applying different force from the back. Say the missile is going at (-1000,500) but the target is behind it and below it. Its next velocity might become (-950, 450). As long as you point the image of the rocket the right way (and yes, you'll need atan2 to do that), then it will look like a completely smooth parabolic turn, because although the acceleration is linear the velocity is exponential. If you know your derivatives, this makes sense: x^2' == x^1.

See my work:
OTC Software
Offline Sanzeinga

Senior Newbie





« Reply #43 - Posted 2009-03-20 19:47:33 »

I haven't thoroughly understood everything said here (YET) but i think these alternative suggestions are important and i will try them all because i plan to have MANY MANY MANY MANY types of projectiles with different homing or quasi homing properties that all behave differently.  If these alternatives allow me to produce different "looking" behaviors that cannot be (easily) reproduced with the original method then thats very good.  The projectiles will often be destroyable, so having a different "approach" and movement behaviors towards their targets can mean a lot in my game.  Actually even if the original claim that the missile would move like a ball of mud isn't true thats actually a behavior i might want to try to create... so yeah, thanks a lot for all the extra details, i actually will need it (probably)
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11


Game Engineer


« Reply #44 - Posted 2009-03-21 08:46:56 »

I think the ball of mud thing was referring to the missile being able to accelerate in any direction, rather than being constrained by a certain angle around its current velocity. If you wanted to get that, then I would probably use the dot product and cosine rather than atan, but it will all work out the same in the end anyway.


See my work:
OTC Software
Pages: 1 [2]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (37 views)
2014-07-18 06:55:21

Zero Volt (35 views)
2014-07-17 23:47:54

danieldean (28 views)
2014-07-17 23:41:23

MustardPeter (31 views)
2014-07-16 23:30:00

Cero (46 views)
2014-07-16 00:42:17

Riven (47 views)
2014-07-14 18:02:53

OpenGLShaders (36 views)
2014-07-14 16:23:47

Riven (36 views)
2014-07-14 11:51:35

quew8 (32 views)
2014-07-13 13:57:52

SHC (69 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!