Camera To a ball

So the basic idea of my game im trying to make is based on the Price is right Plinko. My issue is I cant get the camera to follow the dropped ball. Im hoping to make it so you can choose where you want to drop it, and have to camera zoom out as it goes down. Maybe allow the player to zoom out before they drop it. I just cant get the camera to follow the ball at all

Hey,

simple way to do this would be to set the ball as parent of the camera. The camera then moves with the ball without much effort. You can do this via code or BP once the ball starts dropping (player drops the ball).

Hope it helps.

As ex3me pointed out, parenting would work and would be simple.

I can give you 2 more options but I will assume the following:

  • The camera is attached to an (observer) actor;
  • The ball is a physical object or another actor whose movement is independent from that of the camera actor;

There are several paths you can take from this point on.

  1. Join the two movements:
  • On begin play save the OffsetVector = CameraActorPosition - BallActorPosition
  • Every frame set CameraActorPosition = BallActorPosition + OffsetVector
  • You can modify the OffsetVector to produce different movement or take just the Z component of the BallActorPosition to make the camera move only up and down.
  • You can add smoothing by saving previous position and limiting the size of the NewPosition - OldPosition

This approach might create problems if the Camera actor hits an obstacle.

  1. Look at:
  • Use FindLookAtRotation node and give it the CameraActorPosition and the BallActorPosition
  • Apply the resulting rotation to the CameraActor
  • You can add smoothing by limiting the angle of the rotation.

This way the camera stays stationary but it rotates to follow the object.

IMPORTANT NOTE: Make the CameraActor tick after physics if the Ball is a physical object. Otherwise it will produce jittering.

If you haven’t already, you will want to set up a custom camera actor with a spring arm and a camera for you to use. When you drop the ball, you will need to tell you camera that it now has an object it needs to follow. This can be done several ways but easiest may be to use the ball to tell the camera it is the follow object and start following, or from within the camera get all “drop ball” actors and set them as the follow target and to start following.

The Camera on begin play should get its X, Y, and Z positions and set them to variables

Next you want to be in the custom camera’s event tick. Set the Delta to a variable. Branch if following ball. If true, run a Custom event “Follow Ball.” Here, get the Y and Z location of the ball and FInterp from where the camera currently to that Y and Z position (could be x and z depending on how you built the world) . You can adjust how quickly it follows the ball using the Interp speed.

If you want the player to zoom in and out, you can use use their scroll wheel input to set the length of the camera’s spring arm. Hope that helps

Thanks for the tips guys, im not at home but ill definitely give it a try and let you guys know

Hello, sorry to bring up an old thread, i have it set up pretty uch how yo udo, however im having issues finding a couple nodes.
Both of the set camera position nodes, Ive been pulling my hair out trying to figure it out. Thanks in advance

Not a problem! If you mean the Blue “Set Camera Position” in the event tick and the red “Set Camera Position” that is a custom event. You can create a custom event by right clicking in the blueprint and when the search window pops up I believe its called “Add Custom Event.” Once this event is created, it can be called from this blueprint.

So every “event tick” will run your custom event “Set camera position” if the “Follow Ball?” is True

Thanks , so then id have to set what followball? and the actor is in reference to the blueprint?

Yea, this will let you enable and disable if and what the camera follows. You can get the referenced, followed actor from the scene or more dynamically. The interp of the movement will prevent jitters and the set up is also flexible enough to be expanded upon if you want to do something like follow the average location of two actors instead of the 1 or zoom in and out based on Z height

Sorry one last question (sorry im bad at blueprint) do i call it up in the bblueprint or in the construction graph?

You’ll want to call it in the standard blueprint event graph. Construction graph executes when the object is created and if changed at all in the scene (even if the game isn’t simulating). This isn’t what you need here. Youll only need to set the follow ball when the ball is spawned.

Thanks for being patient , and all the help. I tried doing doing it on my own but was getting frustrated

No problem at all! Blueprints can take some time to figure out but can also be powerful and fun at the same time

So im giving up for now on this, I cant get the nodes to reference certain actors. And whatever I did I made the ball invisible when i start the game lol. The joys of programming

Edit: The camera now follows the ball but the view port doesnt. So I got the ball to reappear lol