Navigation

    Fuze Arena Logo
    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Help
    • Discord

    How to make the a 3d object point towards a location without using objectPointAt()

    Help
    2
    3
    32
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • HeyoMayo
      HeyoMayo last edited by HeyoMayo

      I'm trying to make a 3D racer game by expanding the kat racer template/demo. I have a couple of collision boxes/points on the track set up. The only thing is that I can't track the angle while using objectPointAt() to point/move to a random track Point. How do I make my own function that has the same effect, but tracks the angle.

      1 Reply Last reply Reply Quote 0
      • Gothon
        Gothon F last edited by Gothon

        The elevation in Kat Racer is the same everywhere on the track, this means that you can do this with a 2D (Y axis) rotation. It is a good thing too because otherwise you might need to keep track of 3 angles or a unit quaternion or a rotation matrix. With one angle it is simple to find it with atan2(), and apply it with rotateObject(). You also will need to keep track of your object's position so that you can reset it's facing direction with objectPointAt() before calling rotateObject() since rotations accumulate with rotateObject().

        // Find the angle from the object at objPosition to a target point and look at it
        float angle = -atan2(target.z - objPosition.z, target.x - objPosition.x)
        //objectPointAt(obj, target)
        objectPointAt(obj, objPosition + {1, 0, 0})
        rotateObject(obj, {0, 1, 0}, angle)
        
        HeyoMayo 1 Reply Last reply Reply Quote 4
        • HeyoMayo
          HeyoMayo @Gothon last edited by HeyoMayo

          @gothon Thank you so much! This will be very useful for coding the kart AI. I'll be using a 2D vector for the angle from now on.

          1 Reply Last reply Reply Quote 0
          • First post
            Last post