Hi, I am trying to implement script for movement; i cannot understand what doing to use arrow key. The script is this:
using UnityEngine;
public class playerMovement : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
Rigidbody2D rb;
Animator anim;
float moving= 2;
void Start()
{
rb=GetComponent();
anim=GetComponent();
}
// Update is called once per frame
void Update()
{
rb.AddForce(transform.right*moving*Input.GetAxis("Horizontal"),ForceMode2D.Force);
if(rb.linearVelocity.magnitude>0.01f)
{
anim.SetBool("walking", true);
}
else{
anim.SetBool("walking", false);
}
}
}
Start with any one of the ten billion youtube tutorials out there for every possible form of movement known to mankind in the entire video game universe.
If you cannot get something working from a tutorial, nothing in this little text box will matter.
Two steps to tutorials and / or example code:
- do them perfectly, to the letter (zero typos, including punctuation and capitalization)
- stop and understand each step to understand what is going on.
If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.
Imphenzia: How Did I Learn To Make Games:
The problem is that when I get stuck following up a tutorial I go to look for another tutorial…
Ah, then you’re not doing Step #2. Step #2 is how you get “unstucked.”
Two steps to tutorials and / or example code:
- do them perfectly, to the letter (zero typos, including punctuation and capitalization)
- stop and understand each step to understand what is going on.
If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.
Here’s more writing about Step #2:
Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.
Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.
I completely agrre to you, but honestly I am blocked trying to perform the 2 steps…but nothing…