• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] HELP!
#1
I am using ColAndreas for raycasting.

I have 2 points, for instance (0, 0, 0) and (100, 100, 20)

It will cast a really long ray but i want to cast a small ray from one?point?in the 'direction' of the other but a smaller ray (like 4.0 to?5.0 meters or whatever measurement unit is used in this game).

It can be done by finding the coords between these two points. Any math genius here ?
  Reply
#2
Do you want a specific length of ray? Because that can be done with trigonometry, but is harder. Just a generic shorter one is easy - divide each coordinate by some number. So 0, 5, 11 to 100, 100, 100 is a difference of 100, 95, 89. Divide that difference by 5, add on the original point, and you have your new end point: 20, 24, 28.8
  Reply
#3
What you want is the concept of a?Unit Vector.?Simplified version: vectors have both direction (where?), and a magnitude (how large?). A unit vector is defined to connect two arbitrary points in space with a magnitude of length 1 -> it effectively gives us the "direction" of the destination point with respect to the origin.



You also have the option of then "scaling" the vector - somewhat along the lines of what Y_Less was saying. However, if you're interested in only getting the direction, use the unit vector. The reason behind this is that most of the vector algebra you can do (cross product, dot product, etc). will use the magnitude, and since it is literally 1 you're making the computations easier for the server to handle.
  Reply
#4
If i understood what he wants is:

lets say P1 and P2 are they points so



raycast = lenght_you_want * P2-P1/VectorSize(P2-P1)



Explain:

P2-P1 will give you the vector from p1 pointing to p2. Dividing it for his norm to make it unit (see maslag coment). And then multiply for the lenght you want to stretch it :)
  Reply
#5
Thanks Y_Less and maslag.

FIXED
  Reply


Forum Jump: