1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

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

  1. May 30, 2017 #1
    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
     

    Attached Files:

  2. jcsd
  3. May 30, 2017 #2

    mfb

    User Avatar
    2016 Award

    Staff: Mentor

    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.
     
  4. May 30, 2017 #3
    Do you have a coordinate system in the game ?
     
  5. May 30, 2017 #4
    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, lets just say 1 )
     
  6. May 30, 2017 #5

    Drakkith

    User Avatar

    Staff: Mentor

    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.
     
  7. May 30, 2017 #6

    jedishrfu

    Staff: Mentor

    Also take care that ##x_2 - x_1## is not zero.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Find line slope based on degrees (for video game programming)
Loading...