1. #1

    How to make an object constantly aim at the rider?

    I basically need to copy the ball pitcher from the Homerun track. I want an object to rotate and aim at the rider as he goes in a circle around it.

    Does anyone know how to do it?
    Share this post

  2. #2
    Jarr3tt88's Avatar Senior Member
    Join Date
    Jan 2013
    Posts
    3,520

    Re: How to make an object constantly aim at the rider?

    Maybe have a dummy following the rider (with object position event) and have the ball pitcher target the rider with a physics tool (select target to follow) Turn force as low as you can or maybe the base glued to it would keep it stationary.
    Share this post

  3. #3

    Re: How to make an object constantly aim at the rider?

    Originally Posted by Jarr3tt88
    Maybe have a dummy following the rider (with object position event) and have the ball pitcher target the rider with a physics tool (select target to follow) Turn force as low as you can or maybe the base glued to it would keep it stationary.
    The dummy object is unnecessary because I can just choose the rider as the target. (My object won't actually be shooting things)

    I tried doing it with a pipe by gluing a physics force to it that points at the rider. I attached the pipe to a stationary object below it with a rotational physics hinge. This almost works. The object does rotate on one axis and it does follow the rider, however it is very, very sluggish in doing so and also has trouble stopping its rotation once it gets going. I tried messing with the settings on the hinge and physics force but it still rotates way too easily and "overshoots" what its aiming for.

    I'm guessing I'm gonna have to use object position events to make it look good.
    Share this post

  4. #4

    Re: How to make an object constantly aim at the rider?

    use a set_position_event to set the yaw of the object to atan2(z1-z2,x1-x2)
    where x1 and z1 are the x and z position of the object
    and x2 and z2 are the x and z position of the rider
    Share this post

  5. #5

    Re: How to make an object constantly aim at the rider?

    Originally Posted by kamesatlee
    use a set_position_event to set the yaw of the object to atan2(z1-z2,x1-x2)
    where x1 and z1 are the x and z position of the object
    and x2 and z2 are the x and z position of the rider
    Moar trigonometry?!?

    Can you explain this to someone who apparently didn't take enough math in College... :/
    Share this post

  6. #6

    Re: How to make an object constantly aim at the rider?

    Originally Posted by thebeardo
    Originally Posted by kamesatlee
    use a set_position_event to set the yaw of the object to atan2(z1-z2,x1-x2)
    where x1 and z1 are the x and z position of the object
    and x2 and z2 are the x and z position of the rider
    Moar trigonometry?!?

    Can you explain this to someone who apparently didn't take enough math in College... :/
    I didn't completely understand it either but with a little guessing I figured it out and it works. Unfortunately, the object I want to rotate is actually made up of a bunch of little different objects, all of which rotate independently. This causes my object to completely fall apart whenever it rotates. I guess my object is too complicated for this to work.

    Here's what I did: only did it on one axis)

    Stored the Z positions of the object and rider.

    Used a two-input operator, (Z Position of object - Z Position of rider)

    Used another two-input operator to multiply that number by another number. The bigger the number I multiplied by, the more the object seemed to rotate. (Sometimes too much)

    Took the arctangent of that number, and set it as the yaw of my object.
    Share this post

  7. #7

    Re: How to make an object constantly aim at the rider?

    Okay that kinda makes sense.. Still not sure what the arctangent does in that case. Maybe because I don't see what its doing.
    Is there an easy way to set up an arctangent linked object or movement that shows me what is happening.
    Share this post

  8. #8

    Re: How to make an object constantly aim at the rider?

    arctan2 uses the distance between two points on each axis to calculate the angle between them.

    It is not the same as arctan, which takes an angle and returns... the arctan of that angle.

    This page has an interactive arctan2 demo:
    http://polygeek.com/1819_flex_exploring-math-atan2
    (note the angles in this demo are in radians)
    Share this post