Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by M-Mahad · Jul 15, 2016 at 01:16 AM · animationcharactercontrollerbeginnerprojectilerpg

How do I create the animator and the character controller for this situation?

alt text

How can i create a character control and animator for this sprite sheet that when i press the arrow keys,the player faces in that direction but does not move and when i press the space bar,the bow attack animation is played and a projectile is launched?

This may be a tall order but please help me out here!I don't know how to start working this out!

chararcter-archer-spritesheet.png (20.3 kB)
Comment
Add comment · Show 3
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 jdean300 · Jul 15, 2016 at 01:24 AM 1
Share

There isn't really anything tricky to this - with just a basic understanding of the animation system you should be able to figure this out. I suggest you go through some of the tutorials on the animation system here: http://unity3d.com/learn/tutorials/topics/animation

Those should give you everything you need fairly quickly.

avatar image M-Mahad jdean300 · Jul 15, 2016 at 01:41 AM 0
Share

I have watched the tutorials several times but i always keep forgetting what to do and keep getting confused between the character controller/scripts and the animator.I am pretty frustrated.

avatar image jdean300 M-Mahad · Jul 15, 2016 at 02:17 AM 1
Share

Okay, I've posted an answer that should help get you started. In the future, when you ask a question, please mention whatever you have done to try and solve the problem (such as watching the tutorials). Without mentioning that, it can seem like you're just asking for the answer without having tried it yourself.

Good luck! :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by jdean300 · Jul 15, 2016 at 02:13 AM

Okay I'll try to give you some guidance here. First, you'd setup the Animation controller kind of like this:

alt text

Each of the transitions to the directional states has a condition set so that it only moves when the relevant bool is set and shooting is false. The transition to shoot happens whenever shoot is true.

Then, I'd have two separate scripts. The first script will set/unset movement variables as needed, and the second will read the input. Here they are:

 public class AnimController : MonoBehaviour{
     private string m_LastDirection;
     private Animator m_Anim;
     
     private void Start(){
         m_Anim = GetComponent<Animator>();
     }
     
     public void SetDirection(string dir){
         //Dont do anything if the animation is already set for that direction
         if (dir != m_LastDirection){
             //Set all movement bools to false
             m_Anim.SetBool("left", false);
             m_Anim.SetBool("right", false);
             m_Anim.SetBool("up", false);
             m_Anim.SetBool("down", false);
             
             //Move in the given direction
             m_Anim.SetBool(dir, true);
             
             //Save which direction we were last set to move in
             m_LastDirection = dir;
         }
     }
     
     public void SetShoot(bool val){
         m_Anim.SetBool("shoot", val);
     }
 }
 
 public class Character : MonoBehaviour{
     private AnimController m_AnimController;
     private float m_ShootingTime; //This is the time the shooting animation takes
     private void Start(){
         m_AnimController = GetComponent<AnimController>();
     }
     
     private void Update(){
         if (Input.GetKeyDown(KeyCode.Left)){
             m_AnimController.SetDirection("left");
         }
         if (Input.GetKeyDown(KeyCode.Up)){
             m_AnimController.SetDirection("up");
         }
         if (Input.GetKeyDown(KeyCode.Right)){
             m_AnimController.SetDirection("right");
         }
         if (Input.GetKeyDown(KeyCode.Down)){
             m_AnimController.SetDirection("down");
         }
         if (Input.GetKeyDown(KeyCode.Space)){
             m_AnimController.SetShoot(true);
             StartCoroutine(WaitForShoot())
         }
     }
     
     private IEnumerator WaitForShoot(){
         yield return new WaitForSeconds(m_ShootingTime);
         m_AnimController.SetShoot(false);
     }
 }

Note that this code is not tested, but it should help get you started.


2danimdemo.png (25.5 kB)
Comment
Add comment · Show 1 · Share
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 M-Mahad · Jul 15, 2016 at 10:10 PM 0
Share

Thanks for the reply! Shouldn't the entry state be connected to the any state though?

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

121 People are following this question.

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

Related Questions

hide/show an object with another 0 Answers

Adjust Charactercontroller size for landing animation? 0 Answers

My 3D Character Moves to Other Spot When I Press Play 2 Answers

How to substitute one object with another in animation clip 0 Answers

Control my character with mouse click 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