How to make smooth camera follow zigzag player in 2d mode

Updated on April 7, 2018 in [A] 2D
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
24 on April 2, 2018

Hi I am creating a zig zag game and i have a little problem  how can we How to make smooth camera follow  zigzag  player in 2d mode i tried every thing . please help 

I want to camera to follow like this 

https://www.youtube.com/watch?v=PyXYBkvZY3k

  • Liked by
Reply
0 on April 2, 2018

Since it appears that the caream moves with the ball just parent the camera to it and have it look at it. That way as the ball moves the camera will. Or if you are a bit more code savy you can make CameraFollowBehaviour that takes in the player’s position and keeps lerping towards it.

  • Liked by
Reply
Cancel
2 on April 2, 2018

not working 

on April 2, 2018

Could you be a bit more descriptive of the problem?

on April 2, 2018

What you mean its not working? Can you explain the steps you took to achieve this not working you speak of.

 

Show more replies
  • Liked by
Reply
Cancel
5 on April 2, 2018

Thanks for all the great help problem solved Thank you soo much I got it now 🙂

on April 2, 2018

Then there is something else happening.

Even if the effect isn’t what you want just yet, a parented object should follow it’s parent unless it is being moved by something else.

 

Could we see a picture of the ball and camera in the hierarchy and could you post the lerp script you made?

on April 2, 2018

i tried script from brackey post how to make smooth camera effect well that was for 3d 

i tried that on 2d but lerping not solving the issue

picture

https://ibb.co/iFU1En

on April 2, 2018

Unity will automatically convert 3d vectors and math to 2d vectors and math. From the picture, if the ball is moving, the camera should be following it exactly, unless it’s being moved or kept in place by something else.

 

What components are on the ball, and the camera?

on April 2, 2018

on ball Rigidbody 2d and Movement Script 

on Camera Default Components only

on April 2, 2018

Then the camera should follow the ball no problem.

Can we see the movement script and the lerp script you were using?

Show more replies
  • Liked by
Reply
Cancel
2 on April 2, 2018

movement script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Movement : MonoBehaviour {
public float zigzag = 1f;
public float speed = 3.0f;
Rigidbody2D rb;
public float velocity;
public bool zigZagX = false;
// Use this for initialization
void Start() {
rb = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update() {
rb.velocity = new Vector2(rb.velocity.x, -speed); // at start set Y velocity
SwitchDirection(); // call input system for movemnt.
velocity = rb.velocity.x;
}
void SwitchDirection()
{
if (Input.GetMouseButtonDown(0) && zigZagX == false) // Our ZIgZagX bool will tell us in which direction we should move.
{

rb.velocity = new Vector2(speed * zigzag, rb.velocity.y);
zigZagX = true;
}
else if (Input.GetMouseButtonDown(0) && zigZagX == true)
{
rb.velocity = new Vector2(-speed * zigzag, rb.velocity.y);
zigZagX = false;
}

}
}

on April 2, 2018

Apart from the velocity float never being used this script seems fine.

Is the camera set to static by any chance?

 

Because w/o any extra components on it, or any scripts telling it to move, it should be following the ball.

on April 3, 2018

float velocity is for detecting rigidbody velocity in inspector  

Show more replies
  • Liked by
Reply
Cancel
0 on April 2, 2018

Camera lerp one i deleted that script because that was not working

  • Liked by
Reply
Cancel
0 on April 3, 2018
  • Liked by
Reply
Cancel
3 on April 5, 2018

@Mouledoux

how can we make path system

 

How can we make path system in unity. If object collide with a point on path it should start following that path and we can flip sprite if we reach end and vice versa like ping pong movement. Path should be visual in scene.

[url=https://postimg.org/image/btb2xly4l/][/url]

sorry i am posting new topic here because the recaptcha is not working for me .

on April 5, 2018

Yeah I can help you make this, but I need a few things from you before I get started.

1. I need you to define for me what a Player is, what a Path is, and what a Destination is.

2. What does the player “do” and how does the user tell the player to do it.

3. Besides the path, can the player interact with anything else? (If they can, define that too)

on April 6, 2018

I am adding picture that what path is and add 1 more with more detail.

on April 6, 2018

here is little more detail of path

if you like to add more feature i will tell you later if you like

Show more replies
  • Liked by
Reply
Cancel
0 on April 6, 2018

more Images 

  • Liked by
Reply
Cancel
0 on April 6, 2018

Ok, a few things.

  1. I don’t use pre-made assets with custom behaviors. So if you want to use that path making plugin in the picture, I can’t help you.
  2. You need to define THIS player more clearly. What can THIS player do? Will they ever not be following the path? What do they do if there is no path?
  3. You said the player can pick up coins and stuff on the path, does that mean non-player object just sit on the path? can they move backward on the path? does the path control the direction, or does the object on it control the direction?
  • Liked by
Reply
Cancel
0 on April 6, 2018

1: I am giving just example of path how it look visually. 

2.  player can be anything you like . Player can do its normal movement if its not touching the first point of path the main point on which the collider is. If it collides with that player. Player should follow that path.  and If there is no path then player can do its normal movement.  Path we are creating should know which object or game item going to use me.

3. i mean when designing a game we set gameplay element on the map/scene. if they are within the path then they will remain at rest no movement for them because we are not creating path for them to follow. Path control the direction. if you see up example a path it shows the starting and end destination. if a movement is ping pong like path will move the object back and forth. if not ping pong movement its mean simple movement from 1 point to another, Then controll is back to player script. 🙂

  • Liked by
Reply
Cancel