[TUTORIAL] Getting Hit Position from testSegment

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Kuromeku
Party member
Posts: 166
Joined: Sun Jul 20, 2008 5:45 pm

[TUTORIAL] Getting Hit Position from testSegment

Post by Kuromeku »

I struggled at first, and then I found this:

Code: Select all

http://www.box2d.org/wiki/index.php?title=TestSegment
This link basically says that to find the point of intersection, you do:

Code: Select all

b2Vec2 intersectionPoint = (1 - lambda) * segment.p1 + lambda * segment.p2;
Where 'lambda' is the impactTime and where the 'segment' values are both vectors.

To do this tutorial correctly you'll either want to use kudoLib (LÖVE Library)'s vector library or the one that comes with ËNVY (LÖVE Framework).

ËNVY (LÖVE Framework): http://love2d.org/forum/viewtopic.php?f=5&t=172
kudoLib (LÖVE Library) : http://love2d.org/forum/viewtopic.php?f=5&t=160

Once you have either one of them vector libraries, or you have your own that supports doing arithmetic to vectors, you do the following code.

Code: Select all

local hitPosition = (1 - impactTime) * startVector + impactTime * finishVector;
I hope this helps.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 209 guests