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

Click For Summary

Discussion Overview

The discussion revolves around calculating the slope of a line based on a character's angle of rotation in a video game programming context. Participants explore methods to determine whether a player is in front of or behind a character using angles and coordinates.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant seeks to find the slope of a line that is perpendicular to the character's angle of rotation, given a single point and an angle.
  • Another participant suggests using the dot product of vectors to determine the angle between the character's direction of view and the direction to the player.
  • A participant confirms the existence of a coordinate system in the game and proposes using the law of sines, assuming one side of the triangle is known.
  • One participant recommends comparing the character's angle with the angle of the line connecting the character and the player to find the slope using the formula for slope.
  • Another participant cautions to ensure that the difference in x-coordinates is not zero when calculating the slope.

Areas of Agreement / Disagreement

Participants present multiple approaches to the problem, indicating that there is no consensus on a single method for calculating the slope based on the character's angle and position.

Contextual Notes

Some assumptions about the coordinate system and the specific values of angles and coordinates are not fully detailed, which may affect the proposed methods.

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: 603
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.
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 47 ·
2
Replies
47
Views
6K
  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 10 ·
Replies
10
Views
3K