B Find line slope based on degrees (for video game programming)

kolleamm
Messages
476
Reaction score
44
I'm trying to code a script for a character in my game. This will tell the character if the player is in front or behind them.

Basically I know the coordinates of the character and their angle of rotation (if rotated 45 deg, that is where they are looking)

Perpendicular to their angle is a line that defines the location that is out of view to them. How can I find the slope of this line with just a single point and an angle?

Thanks in advance
 

Attachments

  • IMG_2961.jpg
    IMG_2961.jpg
    33.6 KB · Views: 582
Mathematics news on Phys.org
The dot product of two vectors (e. g. your direction of view and the direction to the object) is positive if the angle between them is smaller than 90 degree.

If you want different angles, you can also calculate the angle explicitly based on the dot product.
 
kolleamm said:
I'm trying to code a script for a character in my game. This will tell the character if the player is in front or behind them.

Basically I know the coordinates of the character and their angle of rotation (if rotated 45 deg, that is where they are looking)

Perpendicular to their angle is a line that defines the location that is out of view to them. How can I find the slope of this line with just a single point and an angle?

Thanks in advance

Do you have a coordinate system in the game ?
 
Buffu said:
Do you have a coordinate system in the game ?
Yes I do. I'm guessing I will have to use the law of sines since I know all of the angles and only one side (who's value does not matter, let's just say 1 )
 
If you already know the angle of the character, then simply compare that angle with the angle of a line drawn between the character and the player.

To get the slope of the line: ##\frac{Y_2-Y_1}{X_2-X_1}##, where 1 is the character and 2 is the player.
Then find the tangent of the slope to get the angle.
 
Also take care that ##x_2 - x_1## is not zero.
 
Insights auto threads is broken atm, so I'm manually creating these for new Insight articles. In Dirac’s Principles of Quantum Mechanics published in 1930 he introduced a “convenient notation” he referred to as a “delta function” which he treated as a continuum analog to the discrete Kronecker delta. The Kronecker delta is simply the indexed components of the identity operator in matrix algebra Source: https://www.physicsforums.com/insights/what-exactly-is-diracs-delta-function/ by...
Fermat's Last Theorem has long been one of the most famous mathematical problems, and is now one of the most famous theorems. It simply states that the equation $$ a^n+b^n=c^n $$ has no solutions with positive integers if ##n>2.## It was named after Pierre de Fermat (1607-1665). The problem itself stems from the book Arithmetica by Diophantus of Alexandria. It gained popularity because Fermat noted in his copy "Cubum autem in duos cubos, aut quadratoquadratum in duos quadratoquadratos, et...
I'm interested to know whether the equation $$1 = 2 - \frac{1}{2 - \frac{1}{2 - \cdots}}$$ is true or not. It can be shown easily that if the continued fraction converges, it cannot converge to anything else than 1. It seems that if the continued fraction converges, the convergence is very slow. The apparent slowness of the convergence makes it difficult to estimate the presence of true convergence numerically. At the moment I don't know whether this converges or not.
Back
Top