1
\$\begingroup\$

I want to create a Lightning Effect Like http://www.youtube.com/watch?feature=player_embedded&v=mmU2GAYGVSU for my game.

The following blog explains it briefly but I am not able to understand the following line:

midPoint += Perpendicular(Normalize(endPoint-startPoint))*RandomFloat(-offsetAmount,offsetAmount);

UPD: I went through older question posted at gamedev.stackexchange and found following explanation:


Normalize(endPoint-startPoint):

That line gets a unit vector (vector of length 1) from startPoint to endPoint


Perpendicular(Normalize(endPoint-startPoint))

then gets a vector perpendicular to that (i.e. at right angles to the line)


I want to know whether python has inbuilt function for

  • Getting a unit vector (vector of length 1) from startPoint to endPoint

  • Getting a vector perpendicular to that (i.e. at right angles to the line)

\$\endgroup\$

closed as not constructive by msell, Anko, bummzack, Josh, MichaelHouse Jun 6 '13 at 18:04

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ The code on that page is not C#, it's pseudocode. It should easily translate to Python. \$\endgroup\$ – msell Jun 3 '13 at 5:48
3
\$\begingroup\$

Pygame has a vector math module. There you have the methods normalize and rotate, which you can use to construct unit and perpendicular vectors respectively.

http://www.pygame.org/docs/ref/math.html

\$\endgroup\$

Not the answer you're looking for? Browse other questions tagged or ask your own question.