Jump to content

  • Log In with Google      Sign In   
  • Create Account


Direction Vector not working correctly


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 infectedbrain   Members   -  Reputation: 157

Like
0Likes
Like

Posted 03 September 2012 - 07:51 AM

I am making a little Missile Control clone and I need the missiles to move tward the point where the cursor clicks. I take that point put it into a vector and normalize it (I tested it with a built in function and one that I wrote and it works the same) now the missiles won't show unless I click somewhere on the right side of the screen and will only aim at a 45 degree andgle from the bottom middle of the screen (where the turret is).

Does anyone know what to do. I am writing this is AS3 but I got this system working before in C# with XNA.

thanks in advance,
Ben

Sponsor:

#2 Nickie   Members   -  Reputation: 315

Like
0Likes
Like

Posted 03 September 2012 - 09:53 AM

Vector2 target, Vector2 position; // think for those a locations only
Vector2 direction = position - target; // this is actually the direction, from missle to target

Edited by Nickie, 03 September 2012 - 10:16 AM.


#3 infectedbrain   Members   -  Reputation: 157

Like
0Likes
Like

Posted 03 September 2012 - 03:32 PM

I tried it that way but the rockets slow down as they move toward the target. That makes sense because of the math but it's not what i want to happen.

#4 dimitri.adamou   Members   -  Reputation: 329

Like
0Likes
Like

Posted 03 September 2012 - 04:04 PM

Whats your movement code?

#5 Labouts   Members   -  Reputation: 133

Like
0Likes
Like

Posted 03 September 2012 - 06:48 PM

I think I understand your problem. Try normalizing the direction vector and multiplying it by the desired speed.

[source lang="csharp"]Vector2 direction = target - position;direction.normalize( );missleVelocity = missle_speed * direction[/source]

Edited by Labouts, 03 September 2012 - 06:52 PM.


#6 Postie   Members   -  Reputation: 857

Like
0Likes
Like

Posted 03 September 2012 - 07:01 PM

What's your code for forming the direction vector look like?

Once the missile is launched are you keeping track of the missile's original direction vector or are you recalculating it as you go?
Currently working on an open world survival RPG - For info check out my Development blog: ByteWrangler

#7 infectedbrain   Members   -  Reputation: 157

Like
0Likes
Like

Posted 03 September 2012 - 08:27 PM

my code look just like labouts. It worked in C# but not in AS3




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS