Burgershot
  • Home
  • Members
  • Team
  • Help
  • Search
  • Register
  • Login
  • Home
  • Members
  • Help
  • Search
Burgershot SA-MP Pawn Scripting [Pawn] HELP!

 
  • 0 Vote(s) - 0 Average
Pawn HELP!
mouiz
Offline

Burgershot Member
Posts: 27
Threads: 11
Joined: May 2019
Reputation: 0
#1
2019-05-25, 08:14 PM (This post was last modified: 2019-05-25, 08:26 PM by mouiz.)
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 ?
Y_Less
Offline

Administrator

Posts: 323
Threads: 16
Joined: Feb 2019
Reputation: 90
#2
2019-05-25, 11:24 PM
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
maslag
Offline

Burgershot Member
Posts: 1
Threads: 0
Joined: May 2019
Reputation: 0
Location: Russian Federation
#3
2019-05-25, 11:55 PM
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.
Stanislav
Offline

Burgershot Member
Posts: 6
Threads: 0
Joined: Apr 2019
Reputation: 0
#4
2019-05-26, 12:27 AM
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 :)
mouiz
Offline

Burgershot Member
Posts: 27
Threads: 11
Joined: May 2019
Reputation: 0
#5
2019-05-26, 12:35 PM (This post was last modified: 2019-05-26, 01:37 PM by mouiz.)
Thanks Y_Less and maslag.

FIXED
« Next Oldest | Next Newest »



  • View a Printable Version
  • Subscribe to this thread
Forum Jump:

© Burgershot - Powered by our Community and MyBB Original Theme by Emerald

Linear Mode
Threaded Mode