Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Dris · Feb 07, 2015 at 11:16 AM · animator controllercamera movementinfinite runnerjetpacksprite animation

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:

alt textalt text

grounded.jpg (34.8 kB)
fly.jpg (33.3 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Mmmpies · Feb 07, 2015 at 02:00 PM 0
Share

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?

avatar image Dris · Feb 07, 2015 at 04:00 PM 0
Share

@$$anonymous$$mmpies, I think i missed checking the grounded status. How do I fix that?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges