- Home /
camera doesnt move after switching animation
Hello again.
I am in the process of creating a game like jetpack whereby the sprite switch animation but the camera doesn't move along with it. It only works with the fly animation but doesn't with the running. Please do help me in this issue, anyone.
Below are my codes (grounded and camera movement) with snapshots.
Thanks in advance.
Grounded C# Code:
public Transform groundCheckTransform;
private bool grounded;
public LayerMask groundCheckLayerMask;
Animator animator;
void FixedUpdate ()
{
bool jetpackActive = Input.GetButton("Fire1");
if (jetpackActive)
{
rigidbody2D.AddForce(new Vector2(0, jetpackForce));
Vector2 newVelocity = rigidbody2D.velocity;
newVelocity.x = forwardMovementSpeed;
rigidbody2D.velocity = newVelocity;
}
}
void UpdateGroundedStatus()
{
//1
grounded = Physics2D.OverlapCircle(groundCheckTransform.position, 0.1f, groundCheckLayerMask);
//2
animator.SetBool("grounded", grounded);
}
// Use this for initialization
void Start () {
animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
UpdateGroundedStatus();
}
}
Camera movement C#:
public GameObject targetObject;
private float distanceToTarget;
// Use this for initialization
void Start () {
distanceToTarget = transform.position.x - targetObject.transform.position.x;
}
// Update is called once per frame
void Update () {
float targetObjectX = targetObject.transform.position.x;
Vector3 newCameraPosition = transform.position;
newCameraPosition.x = targetObjectX + distanceToTarget;
transform.position = newCameraPosition;
}
}
Snapshot:
How are you moving if on the ground? I can see it check the grounded status and tell the animator to set grounded but can't see where you move the character if on the ground.
Or should it all work via the jetPackActive?
@$$anonymous$$mmpies, I think i missed checking the grounded status. How do I fix that?
Your answer
Follow this Question
Related Questions
How do I check, and change, the current frame/time of a sprite animation in Unity 4.3? 0 Answers
How would you create an animator controller prefab? 1 Answer
Animator and animations issue 1 Answer
How to trigger the same animator state in unity5 with script? 2 Answers
Super Smash Bros Styled Game animators and hitboxes 0 Answers