Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Moving sprites problem  (Read 3465 times)

0 Members and 1 Guest are viewing this topic.

phear-

  • Jr. Member
  • **
  • Posts: 64
    • MSN Messenger - LOApokalypse@hotmail.com
    • View Profile
    • http://gtproductions.org
Moving sprites problem
« on: August 31, 2009, 03:03:04 am »
Alright so I finally got my unit movement algorithm right and my units move and stop perfectly. Now my problem lies in the fact that when my units move horizontally they move a LOT faster than in any other direction.
Partial source is here:
http://blog.gtproductions.org/unitmovement.txt

Any ideas?
Eugene Alfonso
GTP | Twitter

RixCoder

  • Newbie
  • *
  • Posts: 40
    • View Profile
Moving sprites problem
« Reply #1 on: August 31, 2009, 04:13:26 am »
im not sure what your normalize function is supposed to be doing but im guessing the

_Normal.y = (-(SlopeY / SlopeY));
 or
_Normal.y = (SlopeY / SlopeY);

might be part of the problem. Diving a number by itself seems pretty silly.

Heres a link to a simple 2D vector math class

Also when passing around vectors its usually best to pass em by reference instead of value since it will be that much faster by avoiding the whole copy process when passing by value.

Hope that helps!

phear-

  • Jr. Member
  • **
  • Posts: 64
    • MSN Messenger - LOApokalypse@hotmail.com
    • View Profile
    • http://gtproductions.org
Moving sprites problem
« Reply #2 on: August 31, 2009, 04:18:57 am »
Dividing a number by itself will always yield 1, which is what I need for a unit vector because it is a delta vector of 1.

But thanks for the link ill check it out.
Eugene Alfonso
GTP | Twitter

RixCoder

  • Newbie
  • *
  • Posts: 40
    • View Profile
Moving sprites problem
« Reply #3 on: August 31, 2009, 04:26:28 am »
Quote from: "phear-"
Dividing a number by itself will always yield 1, which is what I need for a unit vector because it is a delta vector of 1.

But thanks for the link ill check it out.


Setting it equal to 1 would be quicker no?

phear-

  • Jr. Member
  • **
  • Posts: 64
    • MSN Messenger - LOApokalypse@hotmail.com
    • View Profile
    • http://gtproductions.org
Moving sprites problem
« Reply #4 on: August 31, 2009, 04:50:26 am »
I guess that would be fine either way :)
Eugene Alfonso
GTP | Twitter

Astrof

  • Full Member
  • ***
  • Posts: 135
    • View Profile
Moving sprites problem
« Reply #5 on: August 31, 2009, 04:53:56 am »
Well you want the magnitude of the vector to be 1, not the components themselves.  To do that you take the vector components and divide it by the magnitude of the vector.

phear-

  • Jr. Member
  • **
  • Posts: 64
    • MSN Messenger - LOApokalypse@hotmail.com
    • View Profile
    • http://gtproductions.org
Moving sprites problem
« Reply #6 on: August 31, 2009, 05:03:51 am »
What do you mean by magnitude?

Edit: I figured it out and it works amazingly, thank you very much!
Eugene Alfonso
GTP | Twitter

 

anything