Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

want to make animated character walk down

Discussion in 'Getting Started' started by Melodee, Mar 18, 2016.

  1. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    ok i will give this one more shot.
    i got so far that i can make my character walk left and right with a script.
    now i wanna make it walk down while walking.
    i got this animation:

    upload_2016-3-18_18-59-55.png

    and i have no clue how to continue. there are a way too much options and idk where to put my script or if i should add more things or whatever. because when i watched the tutorial it showed this alot more things in the animator than here:

    upload_2016-3-18_19-5-21.png

    i really don't understand what to do after this. no one wants to explain me personally and idk why, but ye. i hope someone wants to explain to me how to continue. what i want is making the character move down, and at the same time playing this animation.
     
  2. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,498
    The reason you're not getting the help you're looking for is because this isn't really the place for "Tell me everything I need to do". It's more for discussions on topics, or when it comes to helping, answering specific questions along the lines of "THIS is what I'm doing, following THIS guide, THIS is what I expect it to do, and THIS is what is actually happening."

    You've already expressed elsewhere that you're not interested in learning, so that makes people not interested in helping. Why would we waste our time (which we volunteer, by the way) explaining something to someone who doesn't want to learn? It would be like handing a Faberge Egg to someone who admits they'll smash it on the ground immediately upon receipt.

    We've directed you to the tutorials. They may seem a bit overwhelming initially, but I promise you they cover the things you need to know to do what you want to do. It makes no sense for us to repeat that information, as it's already been made available to you. I'm also not sure how we can explain it in a way that's as in depth as what you need that would be any clearer than the tutorial content.

    If you don't want to make games or learn how to do certain parts of it, I'm not sure what your intentions with Unity are. You can certainly put together a graphics portfolio using other tools to animate. If the idea is that you want to show your art off in an actual gameplay type setting, you'll either have to suck it up and start hitting the books, or hire someone to do the development portion for you.

    We're not a mean or unhelpful bunch. We just expect you to put in at least as much effort as what you're asking from us to help.
     
  3. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56

    OK. i have one specific question. it is: how to write a goddamn script without errors. secondly. idk why you tell me "i'm not interested in learning" im just not interested in writing every goddamn script myself BECAUSE I DON'T WANNA READ A WHOLE BOOK, OR DO A WHOLE PROGRAMMING UNIVERISTY JUST TO MAKE MY CHARACTER WALKING DOWNWARDS. you said it yourself: it's the basic stuff. i just don't have alot of time, and im using all the time i have in understanding this bs myself because i can't ask a simple question when my head just explodes from all the tiny mistakes i made, and it's not that i cba to fix them, but it's that i have no clue how. i google everywhere to get a solution, without learning how to program. it's not like i ask you all: make my game. it's that i LITERALLY, doesn't matter how much you want to turn everything around, ask for help. it's just that i get headaches from going through 10 tutorials and understanding nothing because 90% is something i am not focussed on and so, makes me REALLY confused.

    ok that's it. wanna help me again?
     
  4. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    oh and just to add, i don't force you to help but since you seem to know it better than me o-o why not? and also, i put effort in it. this is just ENTIRELY new for me, so ofcourse i have no clue what to do.
     
  5. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    ok so whoever wants to help me, i got this script:

    upload_2016-3-18_20-54-20.png

    and like you see it got a few errors i can't fix, because: it's supposed to work. maybe there's some mistake in it? i don't get it.
     
  6. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,796
    That's easy: go to college for four years and get a CS degree, or do serious self-study for 5-10, and if you have a knack for it, you will then be able to write a script (goddamn or not) without errors.

    Seriously, that's the only possible answer to this "specific" question — it's obviously not specific enough to have any more useful answer. Writing script without errors is a skill. Suppose I were to jump into an aritists forum, post pictures of my crude, ill-proportioned stick figures, and say stuff like "idk why ne1 won't tell me how to just make a goddamn Monet-style painting that doesn't suck! I don't wanna spend time learning! Just tell me what to do!!" What would the artists tell me? How could they help me?

    If they're kind, they would tell me that I need to either study hard for a long time to build my skill, or focus on things I do want to learn and find an artist friend to do the artwork for me. (If they're not kind, they'd probably suggest I go do something anatomically improbable.)

    Because you said so yourself:
    You see?

    Then, as we've suggested before, quit trying. Find a friend (or hire a coder) who can do the scripting for you, or stick to what can be done without scripting. (In fact, things like making your character move around on screen in a prescribed manner can be done entirely without scripting, via Unity animation, if that's all you want to do.)

    As an in-between solution, you could also consider trying something like PlayMaker, which at least avoids the problem of syntax errors (which is where you are frequently getting tripped up now). But it is not going to do everything for you either. You will still need to read some docs, watch some tutorials, and learn how to think like a programmer, which takes some time and effort. If you are unwilling or unable to put in some time and effort, then you should save yourself some grief and find a collaborator.

    Finally, please don't go shouting or swearing at us. We are trying to give you the help you need, even if you don't yet realize that you need it. If we weren't trying to help, we wouldn't be responding at all. It pains me to see somebody struggling with code as much as it would probably pain you to see my crude line drawings. But what you lack is a skill, not a specific piece of information, and we can't impart that easily, especially if (as you have said yourself) you are not interested in learning it.
     
    Schneider21 likes this.
  7. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    okay. i'm sorry for swearing. i want to learn it, but it's REALLY hard, and i need alot of help. so here is my specific question:

    i'm watching my 67th tutorial now to make my character animated while walking downwards, and i'm using this script, but it has an error:

    upload_2016-3-18_22-52-55.png

    upload_2016-3-18_22-53-12.png

    i did everything in the tutorials, but i'm still having troubles with the script.
    i understand abit what the errors are saying, but this one i dont understand.
    also, if i wasn't interested in learning it, and want everything to be handed to me, i wouldn't try the whole day to get this working.
     
  8. Deleted User

    Deleted User

    Guest

    You need basic programming education, high-school level will do.

    if variable = 1
    variable+1;

    if(variable = 1)
    {
    variable +1;
    variable/2;
    }

    The parenthesis and brackets serve a specific purpose in every case and must always be arranged in a valid way. In this case they are necessary because I want to do more than one thing if.

    I might also need them if I want to check two things, if(variable = 0 && variable2 = 0){}

    It's a real game engine, programming is required to use it. In programming regards this board is mostly for questions about how Unity's functions work, or how to combine them to get some desired effect.
     
  9. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,796
    OK, fair enough, we all get frustrated and say things we don't mean sometimes.

    The screen shots are really helpful. It's easy to work with code pasted in with code tags, but at least with the screen shots we can also see the error.

    Anyway, the underlined line of code doesn't make any sense to me either — I don't know what you're trying to do there. And you've got either some extra curly braces around the transform.position line, or something missing (like maybe another "if") that would give the curly braces a reason to be there.

    I'm not sure exactly what you're trying to do here, but I will guess that you're trying to (1) set the trigger called "Hi" when the down-arrow key is pressed, and (2) move the sprite down as long as the down-arrow key is held. So the Update method should look something like this.

    Code (CSharp):
    1. void Update() {
    2.     // Set the "Hi" trigger when down-arrow is pressed
    3.     if (Input.GetKeyDown(KeyCode.DownArrow)) {
    4.         animator.SetTrigger("Hi");
    5.     }
    6.  
    7.     // Move the sprite down while down-arrow is held
    8.     if (Input.GetKey(KeyCode.DownArrow)) {
    9.         transform.position += Vector3.back * Time.deltaTime;
    10.     }
    11. }
    See, two steps; just tackle them separately, one at a time. Don't mix them together. (You could even put them in two different scripts, though that might be going overboard.)

    If either part gives you grief, cut that part out, and focus on just the other part. Take it slow and steady. And if you're still stuck, ask again for help. :)
     
    Schneider21 likes this.
  10. Deleted User

    Deleted User

    Guest

    I would recommend definitely not starting with animations, animator component, or Mecanim in any context. I would start with rigidbodies (if you have a good cpu/gpu), triggers, collisions, and addforce/transform; but you're specifically wanting to do one thing. I would say Unity may not be the best tool for this.
     
  11. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,796
    It's true that Animator makes simple animation a lot more complex than it ought to be. @Melodee, you might consider using the SimpleAnimator script from my 2D Animation Methods article. You should be able to just copy & paste the code (from Part 1, "Simple Approach") into a script called SimpleAnimator.cs, and then use it as described in the article — no need for an Animator or Animation Controller at all.
     
  12. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    hey. thankyou all for trying to help me! i clicked on the link and tried seperating the scripts (because it contains jumping, running, etc too and i only want it to walk right, left, forward and backwards) but idk. i didn't succeed. i'm gonna try again for a while, but if anyone wants to help me, i'd be very happy.
     
  13. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    okay i haven't got it walking when the right arrow is pressed (i will start with right arrow cuz i am still unable to make it walk down) my script is alright now i think, but there's an error in the options.
    my script is:

    upload_2016-3-19_14-21-39.png

    right now the animation loads immediately.
     

    Attached Files:

  14. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,796
    Again you're trying to do too much at once. The script I pointed out doesn't contain jumping, running, etc. I was (and am) suggesting you take only the first script, Listing 1, SimpleAnimator.cs. Here it is again.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.Events;
    3. using System.Collections.Generic;
    4. using System.Linq;
    5.  
    6. public class SimpleAnimator : MonoBehaviour {
    7.     #region Public Properties
    8.     [System.Serializable]
    9.     public class Anim {
    10.         public string name;
    11.         public Sprite[] frames;
    12.         public float framesPerSec = 5;
    13.         public bool loop = true;
    14.  
    15.         public float duration {
    16.             get {
    17.                 return frames.Length * framesPerSec;
    18.             }
    19.             set {
    20.                 framesPerSec = value / frames.Length;
    21.             }
    22.         }
    23.     }
    24.     public List<Anim> animations = new List<Anim>();
    25.  
    26.     [HideInInspector]
    27.     public int currentFrame;
    28.    
    29.     [HideInInspector]
    30.     public bool done {
    31.         get { return currentFrame >= current.frames.Length; }
    32.     }
    33.    
    34.     [HideInInspector]
    35.     public bool playing {
    36.         get { return _playing; }
    37.     }
    38.  
    39.     #endregion
    40.     //--------------------------------------------------------------------------------
    41.     #region Private Properties
    42.     SpriteRenderer spriteRenderer;
    43.     Anim current;
    44.     bool _playing;
    45.     float secsPerFrame;
    46.     float nextFrameTime;
    47.    
    48.     #endregion
    49.     //--------------------------------------------------------------------------------
    50.     #region Editor Support
    51.     [ContextMenu ("Sort All Frames by Name")]
    52.     void DoSort() {
    53.         foreach (Anim anim in animations) {
    54.             System.Array.Sort(anim.frames, (a,b) => a.name.CompareTo(b.name));
    55.         }
    56.         Debug.Log(gameObject.name + " animation frames have been sorted alphabetically.");
    57.     }
    58.     #endregion
    59.     //--------------------------------------------------------------------------------
    60.     #region MonoBehaviour Events
    61.     void Start() {
    62.         spriteRenderer = GetComponentInChildren<SpriteRenderer>();
    63.         if (spriteRenderer == null) {
    64.             Debug.Log(gameObject.name + ": Couldn't find SpriteRenderer");
    65.         }
    66.  
    67.         if (animations.Count > 0) PlayByIndex(0);
    68.     }
    69.    
    70.     void Update() {
    71.         if (!_playing || Time.time < nextFrameTime || spriteRenderer == null) return;
    72.         currentFrame++;
    73.         if (currentFrame >= current.frames.Length) {
    74.             if (!current.loop) {
    75.                 _playing = false;
    76.                 return;
    77.             }
    78.             currentFrame = 0;
    79.         }
    80.         spriteRenderer.sprite = current.frames[currentFrame];
    81.         nextFrameTime += secsPerFrame;
    82.     }
    83.    
    84.     #endregion
    85.     //--------------------------------------------------------------------------------
    86.     #region Public Methods
    87.     public void Play(string name) {
    88.         int index = animations.FindIndex(a => a.name == name);
    89.         if (index < 0) {
    90.             Debug.LogError(gameObject + ": No such animation: " + name);
    91.         } else {
    92.             PlayByIndex(index);
    93.         }
    94.     }
    95.    
    96.     public void PlayByIndex(int index) {
    97.         if (index < 0) return;
    98.         Anim anim = animations[index];
    99.        
    100.         current = anim;
    101.        
    102.         secsPerFrame = 1f / anim.framesPerSec;
    103.         currentFrame = -1;
    104.         _playing = true;
    105.         nextFrameTime = Time.time;
    106.     }
    107.    
    108.     public void Stop() {
    109.         _playing = false;
    110.     }
    111.    
    112.     public void Resume() {
    113.         _playing = true;
    114.         nextFrameTime = Time.time + secsPerFrame;
    115.     }
    116.    
    117.     #endregion
    118. }

    Paste the above into a new script called SimpleAnimator.cs. Then attach it to a GameObject that also has a SpriteRenderer component. Hit the Play button. Does it run without errors? It shouldn't move or animate, but it should run. If it does not, stop there and figure out what's wrong. Otherwise, hit the Play button again to stop the run (this is important, as any changes you make while the game is running do not stick!), and proceed to the next step.



    Step 2: Make it animate. The way SimpleAnimator works is, you have a number of "Animations" defined on it, each of which is just a series of frames and a frame rate. You can see these in the inspector image above: under Simple Animator, there is an Animations list, which currently has a Size of 0.

    You want to have more than zero, so for starters, change that Size to 1. Then lock the inspector, so you can grab a whole series of frames in the inspector (by clicking the first and shift-clicking the last), and then drag 'em in. Unity is likely to mess up the order, but SimpleAnimator has a convenient menu command to sort them by name.



    Run again. You should see your character animate, as I've shown above. (Notice how I initially forgot to make the animation loop, so I stopped the play, checked Loop, and tested again.) Does this work? If not, stop there and fix it. If you can't figure out how to fix it, ask and I will help.

    If it does animate correctly, hooray! Now you can worry about making scripts to move the sprite around, and select which animation to play. You don't need anything more from my article; nor do you need an Animation Controller anymore. Life is simple; let's keep it that way!

    (Oh, and don't forget to unlock the Inspector, by again clicking the little padlock at the top; otherwise you won't be able to inspect anything else in your project.)

    To play an animation, your other script needs to GetComponent<SimpleAnimator>() instead of GetComponent<Animator>(). (And the property you store the result in must of course be declared as SimpleAnimator instead of Animator.) And then you either call Play to play an animation by name, or PlayByIndex to play an animation by index.

    I think that's about all you need to know. Let me know how far you get, and where you get stuck.
     
    Last edited: Mar 19, 2016
    MikeTeavee and Schneider21 like this.
  15. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56

    upload_2016-3-19_15-22-41.png

    i have those two errors. what do they mean? i see it's both the same thing.
     
  16. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,796
    Oh nuts — it means that Gamasutra butchered my source code! I should have copied it from the actual project rather than from the article, I guess.

    I've edited my post above with the correct source code (copied from the actual source file this time). So, please just copy/paste it into your script, replacing the previous incorrect code. You should see that on line 24, we are now specifying List<Anim> rather than just List (the "<Anim>" part had been stripped away before).

    I'm very sorry for the confusion.
     
  17. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    is okay XDD well i can't run my game. i removed all the scripts from the character. idk whats wrong now.

    upload_2016-3-19_16-43-56.png
     
  18. maquis

    maquis

    Joined:
    Feb 7, 2016
    Posts:
    61
    Why did you remove all the scripts?

    A few suggestions:

    I dont think you need to take this giant class on programming. You would be majorly benefitted by taking a bit of time to learn the basics. If statements, calling functions, basic syntax. Once you learn those complete basic items, fixing those errors is really just reading the error, reading the line that it refers to, and figuring out why it is saying it is wrong. In non-computer terms, the computer is saying "you are asking me to do something, but I cant figure out what you want, because your sentences dont make sense."
     
  19. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    i removed all scripts to check if it works. idk why it doesn't, because it doesn't show any errors in here:

    upload_2016-3-19_17-15-17.png

    so the computer should make a bit more sense to me too what exactly doesn't make sense.
    i'm trying to make clear to the computer what i mean, but idk, the computer is foreign so, i need some help of you guys translating to him what i mean XDD

    ANYWAY. maybe mr. computer doesn't understand this, since i already added another script for this
    upload_2016-3-19_17-21-52.png :

    not sure if i should delete it.

    and about your suggestion. i'm trying to learn it while doing it. like, i get some functions and errors now, but some errors are just hard to understand. like when the error doesn't connect to wha i wrote, like how am i supposed to understand it? XDD
     

    Attached Files:

    Last edited: Mar 19, 2016
  20. maquis

    maquis

    Joined:
    Feb 7, 2016
    Posts:
    61
    Sox in the images here, it says it cant do anything because a script has compile errors. That means that your instructions arent "grammatically correct". If you look at the console again it will list the errors for you.

    Compile errors come with a line number. Usually, the error is either on that line or the line before. The error can also be because something else has to be done before you can do what you are saying on that line.

    Once you learn the basics of the computer's language, making the script not throw errors becomes the "easy" part of getting things done. The computer tells you exactly where the error is, and takes a pretty good guess at what they think is wrong with it. As opposed to when it does exactly what you told it to do, regardless of whether thats actually what you wanted. :)
     
    Schneider21 likes this.
  21. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    alright. i think it has to do with the options indeed, because the scripts are fine (i hope, and i think they are since they don't show errors). but idk what options, so i'll try removing all options i have.
     
  22. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    aaaaaaaaaand it didnt work.
     
  23. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,796
    You do have compiler errors, but the Console is not in your project. You need to find it (under the Window menu), and then I suggest you dock it somewhere where it's always visible. Or, just make sure you include it in any screen shots! The console is absolutely critical to understanding what's going wrong. Don't worry so much about the errors list in Visual Studio; I don't understand how/when that decides to show you errors, but it's errors in the Unity Console tab that actually matter.

    Also, I notice in your screen shot that you still have the Animator and Animation tabs in your layout. You don't need those anymore; just right-click each of those tabs and select "Close Tab".

    Also, delete the "Animator" component from your chickletwalking object. You don't need that anymore either. In fact maybe you should just start over: make a new scene, use "Create Empty" in your Hierarchy to create a new empty object, add a SpriteRenderer, and add a SimpleAnimator. That's all your object should have on it (except for Transform of course, which all game objects have). It should look exactly like my screen shot above.

    Please try that, and if it still doesn't work, include a picture of your Console so we can see what errors you have.
     
  24. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    okay it worked. except for that i have a white screen again, and my character doesn't show. i forgot how i solved that last time.


    upload_2016-3-19_18-32-42.png
    upload_2016-3-19_18-34-44.png
     
  25. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    i tried changing options in the camera, but it doesn't work. total whiteness.
    there is an error showing at the bottom tho:

    upload_2016-3-19_18-58-36.png
     
  26. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    OK. sorry for all the spam under this thread.
    i got it. it works now. i made another new project.
    here it is:
    upload_2016-3-19_19-10-10.png

    so, can you tell me what the next step is? @JoeStrout
     
  27. Deleted User

    Deleted User

    Guest

    Why are you using Visual Studio? Do you have intellisense set up in Visual Studio to give you the Unity API references? If so, that's great; but you should probably just use MonoDevelop at this stage if you don't.

    The errors are meaningful, if you don't understand them you're out of your depth and should go back to something simpler. I haven't used a 2D camera yet, but the screen position is out of view frustrum.

    Immediately I assume the rectangle must be the 2D "screen" and the "view frustrum" must mean the FOV of the camera. Last night I was looking into using unity's Projector class to create fake low-spec blob shadows and found I had never learned what "frustrum" formally meant. So I google it, and it's the volume of a shape between two intersecting planes- the camera has one representing what it can see.

    So I mean really here you're just not even reading the errors and posting over and over while the camera isn't pointed at your subject matter.
     
  28. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,796
    Good job! This is real progress.

    OK, now the next step I guess is to add a "WalkDown" animation. In the inspector, under Simple Animator, change the Size property of Animations from 1 to 2. You'll get another element of that array. By default, the new one just copies the old one, so twist open the new one, change the name from Idle to WalkDown, and then change the number of frames (i.e. the Size of the Frames array) to 0 to clear it out.

    Then you can lock the inspector, select your walk frames, and drag them into that Frames array, just like you did for Idle.

    Now make a script that gets the SimpleAnimator component, and calls Play("WalkDown") on it. It should look something like this:

    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class AnimDemo : MonoBehaviour {
    4.     SimpleAnimator anim;
    5.    
    6.     void Start() {
    7.         anim = GetComponent<SimpleAnimator>();
    8.         if (anim == null) Debug.LogError("No SimpleAnimator found!");
    9.        
    10.         anim.Play("WalkDown");
    11.     }
    12.    
    13. }
    Add this script to your game object, and you should now see the WalkDown animation instead of the Idle animation when you run.

    Let me know if you can't get this to work, or even if there is any part of it you don't understand. Understanding will be really important if you ever want to be able to do this yourself. :)
     
  29. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,412
    Ah, I like these threads. It's like reality TV.

    Anyway, I didn't read all of it, but it looks like @JoeStrout is doing a great job helping out the newbie. I think a lot of the misunderstanding is that n00bs have no idea where to start, where veterans remember all the learning they went through to get to the point to do it nearly subconsciously. What the veteran is providing is, yeah, a couple of fish to feast on, but you never know when the n00b is watching the veteran as they fish, and learning from it, and in this case, the n00b is given the benefit of the doubt, hopefully providing the nudge in the right direction towards learning how to do it him/herself. Right @Melodee? You'll be pro at this after this thread is done, right? ;)
     
  30. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    well i get the part where it says "Get Component<Simple Animator>" since added that component, and the script is for making it work i guess? that's why it says "anim.Play("WalkDown")" since you want to play the walkdown.
    but i don't get the "(anim == null) Debug.LogError(No SimpleAnimtor found!")" it might have to do something with fixing an error that pops up? idk.

    upload_2016-3-19_22-2-1.png

    it says at the bottom the script is for mac AND for windows, so i don't get that either XDD
    also i wasn't sure. when i open my game my character starts walking right immediately.
    should i put the idle on another animation? because i wasn't sure what idle was for. it was for standing still right?
    also my character isn't able to walk up or downwards. i tried looking at it with my dad and i think i found the problem but we have no clue how to fix it.

    upload_2016-3-19_22-5-8.png

    i think this script is for 3D movement instead of 2D, since there are 3 points (lenght, width, height)

    SO YEAH JUST WANTED TO SHOW I AM LEARNING.
    (and ofcourse also would love to hear the solution XDD)
     
  31. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    YE IM SORRY. i know i know, i just started and i have read the errors but have no clue what i did wrong and how to even "point it at my subject matter" like you say.
    ye, i can understand you think i should go back to something simpler. but when i spend 2 years coming at the point i can do what i want, i probably spend 2 whole years doing only this and not spending time on other things. and since i spend 3 days 24/7 trying to figure this out, i know that's not really a good idea XDD so i focus on the things i wanna do, instead of things i don't wanna do in this unity engine.
     
  32. aer0ace

    aer0ace

    Joined:
    May 11, 2012
    Posts:
    1,412
    This is the problem. You're trying to run before you learn how to crawl. If you are faced with such adversity and complication, it's time to step back and learn what you're missing. Have you gone through all of the relevant training here?
     
  33. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,796
    Right. And we're doing this in the Start method, so it will play the walkdown right away, as soon as the game starts. (I know you want it to be under keyboard control — we'll get to that later!)

    You left out the most important part: if. This says that if anim is null ("null" means "nothing, nada, zilch, zip, no such thing"), even after we called GetComponent, then we want to log an error so that the user (that's you) knows they screwed up. And the error we log tells them exactly what is wrong (no SimpleAnimator component was found), so hopefully they will know how to fix it. Without this check, we would instead get a nil reference exception later, when we try to do something with anim, and you would probably not know what to do about it.

    It says your script has inconsistent line endings. That's just a warning, nothing really to worry about.

    After attaching this script, or before? If after, then it seems that your "WalkDown" script has the wrong frames in it (the frames for walking right instead of for walking down). If before, then your "Idle" animation (which is played automatically because it's the first animation in the list) has the wrong frames in it (the frames for walking right instead of idling).

    Remember, there is no magic here — the computer does exactly what you tell it to do. We're telling it to play the first animation (without the script) or the "WalkDown" animation (with it). You defined what that means, by the sprite images you dragged into the Frames array for each animation in the inspector.

    So, go look at those frames. If they're wrong, fix 'em!

    Right. I was only assuming you have an idle animation. (And remember, an "animation" can be just 1 frame if that's all you have.)

    I wouldn't expect it to be able to do anything except play the "WalkDown" frames, while staying in one place. We haven't told it to do anything else yet, right?

    Oh, I see you're getting ahead of me. :) OK, this ChickletMove2 script actually looks pretty reasonable for moving it around, except that in a 2D world, you want to use Vector3.down and Vector3.up instead of Vector3.forward and Vector3.backward. Forward and backward move in Z; you don't want to move your sprites in Z, but only in X and Y.

    And wait, your dad? Are you a yoot? Not that it really matters, but it may help us to recalibrate our expectations.
     
    Last edited: Mar 20, 2016
    Schneider21 likes this.
  34. Schneider21

    Schneider21

    Joined:
    Feb 6, 2014
    Posts:
    3,498
    @JoeStrout you have the patience of a saint! Bravo for hanging in there and helping out!
     
    aer0ace likes this.
  35. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    ye i am 17 XDD idk if i already said that but here.

    OK. i looked at the frames, now the idle is just the chicklet standing still, and the walkdown is the chicklet walking down.
    i added all the scripts, changed the movement script (ITS ABLE TO WALK UP AND DOWN NOW!! <3 )
    BUT. i don't see the walkdown animation instead of the idle animation when i run.
    it looks like this now:
    upload_2016-3-20_11-46-39.png
    upload_2016-3-20_11-47-21.png
     
    JoeStrout likes this.
  36. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    as weird as it sounds hearing from the person he has to have patience with, i agree with you.
     
    Schneider21 likes this.
  37. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,796
    OK, cool. You're almost there. It sounds like you have your various frames sorted out in the SimpleAnimator; you have a script that demonstrates how to play an animation; and you have another script that moves the object around. Now we just need to put those two scripts together.

    Here's how I would do it.
    Code (CSharp):
    1. using UnityEngine;
    2. public class AnimDemo : MonoBehaviour {
    3.     public float speed = 1.0f;
    4.     SimpleAnimator anim;
    5.     string current;
    6.  
    7.     void Start() {
    8.         anim = GetComponent<SimpleAnimator>();
    9.         if (anim == null) Debug.LogError("No SimpleAnimator found!");
    10.     }
    11.  
    12.     void Update() {
    13.         string play = "Idle";
    14.        
    15.         if (Input.GetKey(KeyCode.RightArrow)) {
    16.             transform.position += Vector3.right * speed * Time.deltaTime;
    17.             play = "WalkRight";
    18.         }
    19.         if (Input.GetKey(KeyCode.LeftArrow)) {
    20.             transform.position += Vector3.left * speed * Time.deltaTime;
    21.             play = "WalkLeft";
    22.         }
    23.         if (Input.GetKey(KeyCode.UpArrow)) {
    24.             transform.position += Vector3.up * speed * Time.deltaTime;
    25.             play = "WalkUp";
    26.         }
    27.         if (Input.GetKey(KeyCode.DownArrow)) {
    28.             transform.position += Vector3.down * speed * Time.deltaTime;
    29.             play = "WalkDown";
    30.         }
    31.        
    32.         if (play != current) {
    33.             anim.Play(play);
    34.             current = play;
    35.         }
    36.     }
    37. }
    This is a combination of the two scripts you had. I added a string property called current that keeps track of what animation is currently playing, and compare it to a local variable called play that we set at the same time we move the transform. So, only if these are not the same (the '!=' operator means "not equal"), we play the new animation and remember it (in current) for next time.

    Of course this will require you to define animations for WalkLeft, WalkRight, and WalkUp, in addition to the WalkDown and Idle you already have.
     
  38. Melodee

    Melodee

    Joined:
    Mar 16, 2016
    Posts:
    56
    I GOT IT!!! THANKYOU SO MUCH. it walks fine now! idk how to thank you XDD
    and for making the idle different at every position i probably need to use alot of different scripts? i'll try XDD

    ANYWAY. THANKYOU!
     
    JoeStrout likes this.
unityunity