Skip to content
This repository has been archived by the owner on Nov 5, 2020. It is now read-only.

[Question] - how to make both camera moving and shaking #4

Closed
angel1st opened this issue Dec 1, 2019 · 10 comments
Closed

[Question] - how to make both camera moving and shaking #4

angel1st opened this issue Dec 1, 2019 · 10 comments

Comments

@angel1st
Copy link

angel1st commented Dec 1, 2019

Hi there,
I need to have camera both following my player and shaking. Currently, camera moving script is in camera parent object. So basically, I have the following hierarchy:

  • Root
    • Camera Rig (camera moving script)
      • Camera

I read your document and noted, I should NOT put the CameraShaker into the same object, responsible for the camera moving (in my case Camera Rig), hence I put it into the Camera object itself. Unfortunately, it does not shake the camera.
If I put the script into the Camera Rig, the camera shakes on collision, but it does not follow the player anymore.
Any hint would be greatly appreciated!

@andersonaddo
Copy link
Owner

From what I can tell, it looks like Camera Rig is still trying to move the camera itself and not the camera's parent.
Have you tried keeping the structure you've showed me, but disabling the rigging script? If my suspicions are correct, that should allow for shaking again (but of course, no following).

Make sure that your rigging script is only moving the camera's parent and not the camera itself.

If that doesn't help, feel free to reply!

andersonaddo added a commit that referenced this issue Dec 1, 2019
@angel1st
Copy link
Author

angel1st commented Dec 1, 2019

Hi, @andersonaddo, this is my camera rig's script:

public class CopyPosition : MonoBehaviour {
    [SerializeField] Transform transTarget;

    // Update is called once per frame
    void Update() {
        if (transTarget != null)
            transform.position = new Vector3(transform.position.x, transform.position.y, transTarget.position.z); 
    }
}

where transTarget is Player's object.
So I don't think I am trying to move the camera. However the moving script simply does not work when it is in the same object with CameraShaker one.

I have noted, you related this to #3, so I changed hierarchy structure now to:

  • Root
    • Camera Rig (holding moving script)
      • Empty Object (having the exact camera position and rotation)
        • Camera (holding CameraShaker script and having position & rotation reset to 0)

and yet, the issue remains - the camera follows the player but does not shake at all.

@andersonaddo andersonaddo reopened this Dec 1, 2019
@andersonaddo
Copy link
Owner

Huh that is pretty strange! Something is interfering with something but I'm not sure what...
Is there any way I could have a quick look at your Unity project so I can check it out? Maybe put it in Google Drive for to download, send me link and delete it after I've taken a look?

@angel1st
Copy link
Author

angel1st commented Dec 2, 2019

I was preparing for you a minimum playable example, when I found the configuration in which the things work. Here it is:

  • Root
    • Camera Rig (holding BOTH CameraShaker & CopyPosition scripts)
      • Empty Object (having the exact camera position and rotation)
        • Camera (having position & rotation reset to 0)

Hope this helps.

@angel1st angel1st closed this as completed Dec 2, 2019
@andersonaddo
Copy link
Owner

Honestly, I'm completely surprised that works! It really shouldn't 🤔
I want to probe further, but I suppose as long as it works...🤷🏾‍♂️
Good luck with your project!

@ustincameron
Copy link

I recently upgraded from 2018.3 to 2019.2 and now experiencing the shake as well. Pretty much vibrating the whole scene.

@andersonaddo
Copy link
Owner

Huh that's interesting, I just tested it and it looks like the demo script still works as expected in 2019.3.0b1.
Are you sure you didn't change anything else? As far as I know there were no breaking changes between the two versions that should affect the camera shaking script.

@ustincameron
Copy link

Actually, rearranging it to @angel1st 's configuration has now solved it for me. Thanks

@Macyrate
Copy link

Macyrate commented May 5, 2020

However, the hierarchy of @angel1st doesn't work for me in 2020.1.0a25.

But it hinted me, and I find this would work well:

  • Root
    • Camera Rig (Hold CameraShaker, Having position & rotation reset to 0)
      • Camera Follower (Hold CopyPosition or something, and having the exact camera position and rotation)
        • Main Camera (Just having position & rotation reset to 0)

@andersonaddo
Copy link
Owner

@Macyrate This is actually the arrangement that I expected would work for @angel1st as well.
Glad it worked for you!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants