playMaker

Author Topic: Translate a camera in a clamp relative to player variable.  (Read 2059 times)

Vanyfraise

  • Playmaker Newbie
  • *
  • Posts: 19
Translate a camera in a clamp relative to player variable.
« on: January 24, 2018, 09:14:13 AM »
Hi guys,
I'm trying to dev "this" exact feature :
I want to translate the camera on the x axis depending on the player position and blocked at -x & +x.

Like that :
https://youtu.be/ZMYThjHA1Xw


I tried a lot of things, but i'm at a dead end. Any idea ?


Deek

  • Full Member
  • ***
  • Posts: 133
Re: Translate a camera in a clamp relative to player variable.
« Reply #1 on: January 24, 2018, 03:55:06 PM »
I couldn't view your referenced video (either removed or geo-restricted) to get a grasp of what your goal is, but my best quess is that you want your camera to follow the player only on the x-axis.

For that I present you two options:
1. Get only the x-axis in the world position of your player on fixed update, give it an offset if you don't want your camera to center the player and set the x-axis in world position of your camera, like this:
Then you can set the height (y-axis) of your camera individually because it doesn't get touched by these actions. The operation in the middle adds an offset of 0.3 in world space, meaning the camera (in my example) is a third further to the right on the x-axis, so that I always see ahead of where he's going. If your player isn't just going into one direction, you can dynamically change the offset to the direction hes facing and how far he should look there. This method also allows your player to jump or fall, without the camera following the player.

2. Follow the player smoothly with the camera with the action "Camera 2d Smooth Follow" from the Ecosystem, and calculate the 'Y Offset' value against your player's y-position; which is a bit more complex and inaccurate, but this action allows for the camera to have a smoother, more wobbly effect, especially when changing directions.
There's also the Corgi Engine asset specifically build for 2D games which comes with several functionalities that help moving the camera according to the player's position and even adapting it to several objects-of-interest on the screen, and maybe other assets that allow to manipulate the camera more easily, but I think you can come pretty far with PlayMaker alone.

In general, when it comes to moving any camera around, it almost always leads to guess-work, which offset is ideal and where to put the camera at what time; that's why this is an area where I suggest you to experiment and play around, to see which setting feels best for the vision you have.

Vanyfraise

  • Playmaker Newbie
  • *
  • Posts: 19
Re: Translate a camera in a clamp relative to player variable.
« Reply #2 on: January 25, 2018, 09:02:38 AM »
Thank you for your reply. It really helps !

The video was set as private, it's availlable now.


In order to adapt to my project, i'm trying this :


This activate or desactivate that FSM :


But the feedback isn't what i expected.

Deek

  • Full Member
  • ***
  • Posts: 133
Re: Translate a camera in a clamp relative to player variable.
« Reply #3 on: January 25, 2018, 03:00:04 PM »
Oh ok, so you want it to go vertically and only clamp the sides. You could still use my first suggestion with slight modifications:
- In your STRAFE LEFT state you seem to be missing to get the x-position of your player on update, without that your camera just stays in one place
- In my first example I was using a float operator action to add a horizontal offset of 0.3 which moves the camera to the right, but in your case where your camera is mainly centered on the player it makes more sense to set the float operator to divide between 0.5 and 0.9 to achieve something like the camera in the video, where it doesn't go all the way to the players x-position but to a degree in its direction (the more you divide it towards 0, the less your camera will move to the players position, creating an indirect "clamping" of your cameras movement)

If you want to actually clamp the camera, you would need to use the action 'Float Clamp', specify the min/max values and restrict the 'CameraFollowPlayerPos' variable with that; but the other suggestion with the float operation should be better, since it automatically creates an offset between the camera and the player like in the video.

Also in my first example I was using the "... Advanced"-variations of built-in actions from the Ecosystem that add the option to run the action functionality on fixed update, which makes any movement rely on physics rather than time-based calculations. So if you encounter any jittery/stuttery movement I'd suggest trying those (but then you'd also need to run all those actions on fixed update for it to work).
Whenever possible, it's usually better to run actions in fixed update when it comes to RigidBody stuff, like movement or change in position.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Translate a camera in a clamp relative to player variable.
« Reply #4 on: January 26, 2018, 01:50:27 AM »
Hi,

 There is a sample on the Ecosystem doing something similar, you need to simply invert the logic if you want the camera to move, but given your video example, this is not the case, it's the player that is moving, and the background is having a parallax effect, the camera doesn't move actually ( at least you can create the very same effect without moving the camera).

Check out "MovementConstraint"

it will also show you how to tilt the spacecraft as you move left and right if you want.


https://twitter.com/JeanAtPlayMaker/status/809662480129605632

Check out the link above or this video: https://video.twimg.com/tweet_video/Czx4v55XUAAXOma.mp4




 Bye,

 Jean