1

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)

1 Answers1

3

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

CeeJay
  • 1,626
  • 13
  • 14