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 Asy1umrat · Oct 24, 2012 at 06:42 PM · animation2dcollisioncontroltop down

Need help fixing 2D Top-Down controls and collisions

So, I am working on a 2D top-down game using the 2D Toolkit in Unity. Thus far everything has been working fine, but you can see in this video that I'm having some issues with controls/collisions. The build in the video for controls is bellow, though 1) it is a much older working build, and 2) I have made several attempts at a state-based system. Unfortunantly, I have come to realize that I was not actually doing it state based, or at least in the correct manor. While I would appreciate pointers on the bellow script (C#), any outlines on doing an actual state-based directional controller would be even more appreciated:

 using UnityEngine;
 using System.Collections;
 
 public class Animation_Controler : MonoBehaviour 
 {
     tk2dAnimatedSprite anim;
     float speed = 0.25f;
     int lastButtonPress = 0;
 
     
     // Use this for initialization
     void Start () 
     {
         anim = GetComponent<tk2dAnimatedSprite>();
     }
 
     // Update is called once per frame
     void Update () 
     {            
         //movement conditions
         else 
         {
             //Moving Animations
             //Move Up
             if (Input.GetKey(KeyCode.UpArrow))
                {
                    transform.Translate(0,0,speed * Time.deltaTime,Space.World);
                 if (Input.GetKeyDown(KeyCode.UpArrow))
                 {
                     anim.Play("Walk_Up");
                 }
                 lastButtonPress = 0;
                    return;
                }
             //Move Left
             else if (Input.GetKey(KeyCode.LeftArrow))
             {
                 transform.Translate(-speed * Time.deltaTime,0,0,Space.World);
                 if (Input.GetKeyDown(KeyCode.LeftArrow))
                 {
                     anim.Play("Walk_Left");
                 }
                 lastButtonPress = 1;
                 return;
             }
             //Move Down
             else if (Input.GetKey(KeyCode.DownArrow))
             {
                 transform.Translate(0,0,-speed * Time.deltaTime,Space.World);
                 if (Input.GetKeyDown(KeyCode.DownArrow))
                 {
                     anim.Play("Walk_Forward");
                 }
                 lastButtonPress = 2;
                 return;
             }
             //Move Right
             else if (Input.GetKey(KeyCode.RightArrow))
             {
                 transform.Translate(speed * Time.deltaTime,0,0,Space.World);
                 if (Input.GetKeyDown(KeyCode.RightArrow))
                 {
                     anim.Play("Walk_Right");
                 }
                 lastButtonPress = 3;
                 return;
             }
         
         
         
             //Idle Animations
             else if (lastButtonPress == 0)
             {
                 anim.Play("Up_Idle");
             }
     
             else if (lastButtonPress == 1)
             {
                 anim.Play("Left_Idle");
             }
         
             else if (lastButtonPress == 2)
             {
                 anim.Play("Forward_Idle");
             }
     
             else if (lastButtonPress == 3)
             {
                 anim.Play("Right_Idle");
             }
         }
     }        
 }


Finally, you can see the shaking collisions in the video. I do not know what is causing this, if it is inherent to unity, or if it actually is an issue in the 2D Toolkit. If this is something anyone knows how to fix/or what the cause is, I would appreciate an explanation, but its not my primary concern at this point in time.

Comment
Add comment
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

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make camera position relative to a specific target. 1 Answer

How can I code an enemy attack? (Top Down Melee Attack) 1 Answer

Strange 2D sprite behavior 0 Answers

Character Arm Joints. 1 Answer

Collision on specific animation 1 Answer


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