|
-
Senior Member
Tonypa's Vectors
I just got through playing around with Tonypa's vector tutorials, but I can't figure one thing out. The code seems to be setup so that the lines extend on forever. How would I go about testing to make sure objects only rebound if there is an actual line?
"If I have seen further it is by standing on the shoulders of giants." Isaac Newton
------------------------------------------------------------------------------
-
Senior Member
The intersection between 2 vectors is calculated for line segments:
http://www.tonypa.pri.ee/vectors/tut05.html
If t>0 and t<1, the intersection point is on the line segment between start point and end point. If t=0 then intersection point is at starting point. If t=1 the ip is on end point.
If t<0 or t>1 then ip is not on line segment.
The ball vs line segment is covered here:
http://www.tonypa.pri.ee/vectors/tut08.html
For AS3 you may want to look at my attempt to update the tutorials (includes source files for vector class, only have first 6 chapters so far):
http://www.tonypa.pri.ee/vectors/as3/
Last edited by tonypa; 12-29-2007 at 05:06 AM.
-
Senior Member
Ok, thanks Tonypa. I missed the "t" part on my first read through. I do have a couple more questions now though.
Question 1:
My object only bounces off of the lines, if the two vectors intersect, however, it treats my object as if it were a single point and really, my object has a radius of 10. How would I figure this into the equation?
Question 2:
My object bounces off one side of the wall correctly, however, it goes through the other side. Why is this? I have used Tonypa's ball vs. line tutorial almost line for line. Let me know if I need to paste code, though.
A swf of the two problems can be found here:
http://tlgames.siteburg.com/frictionless.htm
"If I have seen further it is by standing on the shoulders of giants." Isaac Newton
------------------------------------------------------------------------------
-
Senior Member
Yes, the lines in my examples only work from one side. If you want to have line that bounces from both sides, you need to create another vector at exact same points but with opposite direction and then detect collision with both of these vectors.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|