Dynamic Swivel Camera with a Limited Range

0 favourites
  • 3 posts
From the Asset Store
Medieval Weapon Sound Effects Collection serves as a resource providing a range of top notch recordings.
  • PROJECT

    I'm attempting to make a simple "open world" racer with a 3D camera pinned behind the Car object. The 3D Camera (hereafter, Cam) is attached to an Arm sprite object (a long, thin rectangle) at image point 1. The Arm's origin point is at the far right of the sprite and image point 1 is at the first left. The Cam is pinned to the Arm and the Arm is pinned to the Car

    The idea is that as the Car moves along (using the Car behavior, naturally), the Cam will be dragged along. An event line will have the angle of the Arm set to a fraction of its current angle between itself and the Car's Car.MovingAngle via lerp.

    EVENT-> ACTION: Set Arm.Angle to lerp( Self.Angle , Car.Car.MovingAngle , 0.03 )

    IMAGE 1: The Car (black rectangle with the green triangle) connected to the Cam (blue image) via the Arm (red, dotted line). The red dot on the Arm is the origin point and the white dot on the blue Cam is image point 1.

    IMAGE 2: The Arm rotates so that it is the same angle as the Car via lerp. The Cam is always facing the Car.

    IMAGE 3: The Arm is limited to a range it can go regardless of how intense the Car turns.

    Now, for the practical part, this works. As the Car turns and drifts, the Arm is "rotated" gradually and relative to the angle and closes the gap so that the angle of the Arm becomes (virtually) zero-sum to the Car.Angle.

    PROBLEM

    The issue I'm having is that if I maintain a constant turn/drift, the turning rate will overtake the Arm and it will look like the Car does a massive spinout. I attempted to use a clamp() expression...

    clamp( Arm.Angle , Car.Car.MovingAngle - 45 , Car.Car.MovingAngle + 45 )

    But for some reason, this results in a similar issue. The Arm will "lock" against the clamp() range limit but if the turning rate of the Car is still too much, it will "clip" as if breaking past the boundaries of the clamp() and spinout again.

    GOAL

    The ultimate goal I'm trying to accomplish is to get the Cam to "dynamically" and smoothly update its position while maintaining an overall behind-the-Car fixed area.

    Any suggestions would be greatly appreciated. Thank you!

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Using anglelerp() instead of lerp() probably will help. Sounds like the issue is when crossing the 0 seam, like going from 0 to say 359. With lerp it takes the long way around but anglelerp will use the shortest angle.

  • R0J0hound - Ooooh, snap, I think you're right. I totally forgot there even was an anglelerp. And I agree about the 0-seam you mentioned. That does seem to be precisely the case.

    Thank you, good sir!!

    Your help is always invaluable and appreciated.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)