- Home /
Cinemachine Noise Messes Up Isometric Z as Y Tilemap
I'm trying to use the 6D Shake Cinemachine has built in to shake my camera whenever the player shoots a bullet, but the shake changes the offset of every tile of a different height causing ugly holes between tiles.
Before shake: During shake: Any way to fix this, or any other way to shake the camera?
Answer by NaturedOne · Feb 26 at 07:42 AM
I've used this with great success in the past. Maybe it will help you.
using UnityEngine;
using System.Collections;
public class CameraShake : MonoBehaviour {
public static CameraShake instance;
private Vector3 _originalPos;
private float _timeAtCurrentFrame;
private float _timeAtLastFrame;
private float _fakeDelta;
void Awake()
{
instance = this;
}
void Update() {
// Calculate a fake delta time, so we can Shake while game is paused.
_timeAtCurrentFrame = Time.realtimeSinceStartup;
_fakeDelta = _timeAtCurrentFrame - _timeAtLastFrame;
_timeAtLastFrame = _timeAtCurrentFrame;
}
public static void Shake (float duration, float amount) {
instance._originalPos = instance.gameObject.transform.localPosition;
instance.StopAllCoroutines();
instance.StartCoroutine(instance.cShake(duration, amount));
}
public IEnumerator cShake (float duration, float amount) {
float endTime = Time.time + duration;
while (duration > 0) {
transform.localPosition = _originalPos + Random.insideUnitSphere * amount;
duration -= _fakeDelta;
yield return null;
}
transform.localPosition = _originalPos;
}
}
And of course, call it from anywhere by using: (I imagine you can add this to your projectile firing script with ease)
CameraShake.Shake(0.25f, 4f);
Thanks man, but it only seems to work without cinemachine, and I'm planning on keeping it
Your answer
Follow this Question
Related Questions
How to count Tiles in a sourinding Area around an Object? 1 Answer
Forward and back movements with a camera emulating an isometric view 1 Answer
Set the default 6d shake noise profile by script in Cinemachine? 0 Answers
How do you get the tile on which a gameObject is standing on Isometric Tilemap ? 1 Answer