For those who use Unity 5, the code shown in this video for the "PlayerMovement" won't be compatible with that version. Use this code instead: using UnityEngine; using System.Collections; public class PlayerMovement : MonoBehaviour { public float moveSpeed; private float maxSpeed = 5f; private Vector3 input; public GameObject other; // Use this for initialization void Start () { } // Update is called once per frame void Update () { Rigidbody rigidbody = other.GetComponent(); input = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical")); if (rigidbody.velocity.magnitude < maxSpeed) { rigidbody.AddForce(input * moveSpeed); } } }
Kyle Barnhart I typed this up, it doesn't work the same as the guy in the video though (It doesn't have that slippery feel.) using UnityEngine; using System.Collections; public class Player : MonoBehaviour { public float moveSpeed = 10f; void Update () { if (Input.GetKey (KeyCode.UpArrow)) { transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime); } if (Input.GetKey (KeyCode.DownArrow)) { transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime); } if (Input.GetKey (KeyCode.LeftArrow)) { transform.Translate(Vector3.left * moveSpeed * Time.deltaTime); } if (Input.GetKey (KeyCode.RightArrow)) { transform.Translate(-Vector3.left * moveSpeed * Time.deltaTime); } } }
Kyle Barnhart I don't have Unity in front of me but looking at the code I see there is a declaration of a public variable other which is a type GameObject: public GameObject other; The error you are getting is probably an 'UnassignedReferenceException: The variable other of Movement has not been assigned.' which means you need to drag and drop your Player object onto the Movement script's other field in the inspector to complete the reference. However, you shouldn't even need to reference 'other' just call Rigidbody rigidbody = GetComponent() and it should work (untested). Let me know how you get on.
Going on 3 years now. Wow! Nice to see people are still finding it useful even with the API changes. Recently started a new series creating a Simple RPG in Unity 5. A bit more complex, with more advanced programming concepts being used, but the end result is going to be pretty cool! Check out the introduction: th-cam.com/video/Pp6UNmt8l1I/w-d-xo.html
So far, this is the best Unity tutorial I've seen! I learned a lot, especially about materials. You take the time to explain things. I can type 80 WPM and would always have to keep pausing videos to keep up when typing in the code while watching the instructor paste in code. I was able to watch your video in one window, and type code in Monodevelop in another window without pausing. Well done!!!
Best.Tut.Ever. He actually explains things! With Brackeys and other programming tutorials they just tell you to write stuff down! This is a series you can actually learn from! I highly recommend this to anyone trying to make a game. Keep up the good work AwfulMedia =) !!!
i have completely finished this episode in unity 5 and here is my coding to anybody who needs it - using UnityEngine; using System.Collections; public class playermovement : MonoBehaviour { public float moveSpeed; private float maxSpeed = 5f; private Vector3 input; // Use this for initialization void Start () { } void Update () { input = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxis ("Vertical")); if (GetComponent().velocity.magnitude < maxSpeed) { GetComponent ().AddForce (input * moveSpeed); }
I have been trying to find tutorials on unity, and this guy is the best so far!!!! Every one else goes way to fast and they don't explain things. I have learned to much already! So thank you
I encountered so many problems using Unity 5 so I uninstalled it and reinstalled Unity 4 and everything is going smooth so far. You go in to depth a lot and this really helps, I'm pretty sure you've taught me more in this one video than I've learnt towards this subject in the past 2 years that I've been at college. Thanks a lot!
Aaron McGuigan I started with Unity 4 and I can't remember why (it was earlier this year so I think U5 was out) but I'm pretty glad I did. Looks like I dodged a bullet by doing so, a lot of people having problems following tutorials because of the differences.
This is the code that worked for me! using UnityEngine; using System.Collections; public class PlayerMovement : MonoBehaviour { public float moveSpeed; public float maxSpeed; private Rigidbody rb; void Start () { rb = GetComponent (); } void FixedUpdate () { float moveHorizontal = Input.GetAxisRaw ("Horizontal"); float moveVeritcal = Input.GetAxisRaw ("Vertical"); Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVeritcal); if (rb.velocity.magnitude < maxSpeed) { rb.AddForce (movement * moveSpeed); } } }
I just started working with unity, i have no programing knowlage what so ever and your vidoes and explenations are so awesome. They really helped me alot.
+Marco koopman (Eviltoastey) omg u are a lifesaver, i was following the video to the letter and getting errors i hadn't a clue why, and den your comment's first line set me straight :P though i was wondering why i was missing a menu option he had....anyway i'm also brand new to scripting so i'd have no chance of writing that myself, thank you again :P
I'd like to apologize for not giving feedback yet, I am enjoying your tutorials thoroughly. They are such a useful tool to learn Unity on! Thank you so much sir!
I think I found a workaround for the "z-axis" drift that is occurring during movement. It has to do with the amount of "surface contact" between the floor's box collider and the player's box collider. Because the box collider for the player is the same size as the box, the entire bottom surface of the box (or it's collider) is in constant contact with the floor (or it's collider). This causes the physics engine to generate, what seems to be, random friction points along the two surfaces. In turn this causes the drifting. I've noticed that the drifting isn't always in a constant direction. When the player crosses boundary lines of the floor when the floor is expanded to a larger size, it takes on a new "random" friction direction. Ok, so where's the workaround? I started playing with the player collider shape. When I made it a sphere collider (it defaults to the same size and center of the player) the drifting was virtually eliminated. But that posed another problem. When entering the maze the player's vertical edges would enter the maze walls until the sphere collided with the maze walls. This looked funny and it took more penetration into the goal before it registered the trigger (actually this was a nicer effect). In order to correct the interaction with everything else except the floor, I added another collider (a box collider). I set it's height to about half the height of the player box and left it's center alone. This provided the desired collision with the floor and the maze. However, I did have to up the drag on the rigidbody of the player to about 5 since it was only contacting the floor at one tangential point (theoretically). I hope this workaround is useful to you.
The first good and explanatory tutorial found so far. The good thing about your explanation, is you share thoughts, why you did it and why you didnt. Keep up the good work, and Ill watch your tutorials from now on. Rock on!
If your x Axis is affecting the z Axis (and vice versa), try using a sphere or capsule collider instead of a box collider. I think the corner of the box collider tends to stick to the floor, which causes the rigidbody to move in the direction the corner is facing.
Around the 10:00 mark when he uses the directional light, I cannot replicate that in Unity. I have the newest version, has anything changed in how light works in the engine?
+lleon79 I struggled with this too for a better part of an hour. I think I may have found the answer: go to Window > Lighting and under Scene tab make sure Skybox is set to None. Suddenly I was able to manipulate the light on the floor. I hope this helps.
the gravity bug is due to the collision innacurracies of the basic vertex (thin plate) collision. basically it gets pushed away from the ground, with some innaccuracies. thank you very much for the nice and clear control scheme and clear tutorial, much appreciated :)
Is c# a good language for developing simple games? I'm currently studying c# in school after learning Java last semester and find it a lot easier! What language do you recommend I expand my knowledge on?
Also, it is your Z axis that's supposed to move as Y makes it go up and down. X is horizontal movement and is perfectly assigned. To move "vertically" the depth of the object is changed (Z).
Error: Assets/Scripts/PlayerMovement.cs(18,27): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)' script: using UnityEngine; using System.Collections; public class PlayerMovement : MonoBehaviour { public float moveSpeed; private Vector3 input; // Use this for initialization void Start () { } // Update is called once per frame void Update () { input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); Rigidbody.AddForce (input * moveSpeed); } }
***** If you are using Unity 5, you will have to add it manually. Do like so: public GameObject other; Rigidbody rigidbody = other.getComponent(); rigidbody.AddForce(1, 1, 1); After that, remember to add the "Player" GameObject in the "Player Movement" script on the inspector. Else it won't work
Put it at the beginning of your Update() method. Here's my whole code :) : using UnityEngine; using System.Collections; public class PlayerMovement : MonoBehaviour { public float moveSpeed; private float maxSpeed = 5f; private Vector3 input; public GameObject other; // Use this for initialization void Start () { } // Update is called once per frame void Update () { Rigidbody rigidbody = other.GetComponent(); input = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical")); if (rigidbody.velocity.magnitude < maxSpeed) { rigidbody.AddForce(input * moveSpeed); } } }
your welcome using System.Collections; using System.Collections.Generic; using UnityEngine; public class Movment : MonoBehaviour { public float moveSpeed; private Vector3 input; private float maxSpeed = 5f; // Start is called before the first frame update void Start() { } void Update() { input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); GetComponent().AddForce(input * moveSpeed); }
There is no problem with Z if it's still the case... Look at your coordinate system gizmo. Y pointing up, that is what you "locked" in your equation. So your movement is in XZ plane, thats why X and Z coordinates are changing... Hope explained good. Very good tutorial for beginners. Thanks a lot!
Thank you so much. I got a book on C# and I am not finished yet but it focuses on mainly software which is fine for me as it (so far) has taught me the basics of C# so this was WAY more helpful and easy for me to follow then what it was a while back. Great job with this video bro! I am going to watch all of this series for sure.
This tutorial is exactly what I was looking for. I'm coming into Unity as a C# programmer and there were a lot of things I wasn't sure about such as how to make references to other components in a GameObject (26:30) so it is good to see you have a similar sort of background. Still a lot of difference between the 2 that haven't quite 'clicked' yet but I think your series is going to be very helpful. Thanks for sharing.
i got an error for "getAxis". Severity Code Description Project File Line Suppression State Error CS1061 'Vector3' does not contain a definition for 'GetAxis' and no extension method 'GetAxis' accepting a first argument of type 'Vector3' could be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\NanuckDogg\Documents\tutorial\Assets\scripts\PlayeMovement.cs 16 Activecould someone help me pls?
I really love the game idea and I was wondering if I could make a full game out of it and distribute it if that is okay? I would like to implement some other features and services in the game.
Don't see why not, its your own game! You just had some help making it. Do what ever you want with it, if you want say you had help from the maker of this tutorial.
Hey Austin, I'm completely new to this, I know a few people who program, but I've never delved into it myself until recently. I stumbled upon this and I just wanted to say that this is awesome stuff. For me, one of the best ways for me is to just jump right in, and you help with that and teach along the way. Some of the stuff gets a little lost in the abyss at times, but definitely keep up the repetition, it allows the programming diction to stick in people's heads better (my head at the very least). Good job again!
I download your tutorials to watch them later. They have been a great help. I come from a Python/Blender background; and learned some C++ in college, so this clicks so much. It is presented in an understandable and relevant way. It's difficult to get more than a dirty look out of me for a response, but I'd like to thank you for these videos.
I must say, your previous tutorials were very good. This one is a bit fast, I think. I could see how an inexperienced programmer would get lost and have to pause a bunch in these. My suggestion, for those less familiar with Unity... watch a bunch of the videos in succession and THEN go back and follow along. You will have less trouble keeping up, and everything will feel familiar. Otherwise, good job Austin. Keep it up. I'm a web developer looking to get into C# and Unity, and these tutorials have been just what the doctor ordered and the pace is just fine for me.. I'd recommend slowing down what you're doing a little bit for the less experienced.
you make game making look easy :D im only 15 and im going to learn as much as i can from you, im going to make a small game maybe for IOS for my first game or something idk yet, and hopefully people will like it and il start off my game dev career :3
Hey Kingkizz, honestly, it does not really matter that much. Grades and diplomas don't matter that much in the games industry, except for people who want to work at EA or alike, but if you look on their sites, in generally says (example): "Masterclass game design or equal working experience" as a requirement. The best thing you can do is just start learning and join projects as a programmer or so. Then again, you should know that Game Development is a lot of different things, not just programming ;) Hope this helped! V_R
I really enjoyed this series! Austin, you were very clear and concise and I appreciated your thoroughness in regards to explaining every little detailed step along the way to help us beginners. One thing I would love to know is how to get an enemy AI to seemingly move randomly through a maze. Not sure if this would be done with a waypoint system where the enemy could randomly choose which nodes to walk to, if it would be some sort of raycasting wall collision detection, or a navmesh function? I would love to learn how to do this without the use of plugins. If anyone knows, I am all ears. Thanks!
Great tutorial , easy to understand and really helpful for newbies like me who are just getting started with the Unity game engine.Looking forward to more of unity tuts from this channel. Keep on uploading these amazing tutorials.
this tutorial seems good - but it is simply filled with irrelevant stuff... minutes of color choosing... come on. make it grayscale and get to the point :/
I love these tutorials, because you're one of the few people who actually tell EVERY little detail! I am trying to use your tutorials to create a prototype which can be used for Dungeons and Dragons Roll20 as a Combat Simulator type of thingy, where you can actually see the combat and stuff =D
I have some suggestions , keep the unity layout default, hierarchy at the left, assets at the left bottom, inspector at the right, scene and game in the middle up, that will be better for beginners
rigidbody.AddForce() is deprecated! Use this instead: Declare a public Rigidbody rbName; Then in the Start () method add rbName= GetComponent(); And use it in the Update() method as rbName.AddForce(transform.forward * speedModifier); ----------------------------------------------------------------------------------------- ----------------FULL CODE------------------------------------------------------ ---------------------------------------------------------------------------------------- public float speedModifier = 10; public Rigidbody rb; private Vector3 userInput; void Start () { rb = GetComponent(); } void Update () { userInput = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); rb.AddForce(userInput * speedModifier); }
I know I'm late, but can you explain why you do > ? UPDATE: like, I know it's just a variable to make it easier to write later on, but why do you do this: rb.AddForce(...........)
rb is basically your object, and AddForce() is a method. So you add a force to your object, and as we know, F=m*a, so you give the object an acceleration, which results in velocity.
something else, in the video he writes this: if (rigidbody.velocity.magnitude < MaxSpeed) { rb.AddForce (UserInput * SpeedModifier); } the "rigidbody.velocity.magnitude" doesn't work.. UPDATE: I just found it... you have to use rb (the variable declared earlier) so it becomes: rb.velocity.magnitude
This was an excellent beginning tutorial. Ultimately, the entire series was very inspiring and led me to start my own Maze type game. Thanks for the work you did on the video.
for the movement of the cube he made it a little more complicated than it has to be for new users you can just use this its bassically the same thing but without the rigid body and vector 3 but using a float for the speed using System.Collections; using System.Collections.Generic; using UnityEngine; public class playerMovement : MonoBehaviour { public float movespeed; void Start () { movespeed = 7f; } void Update () { transform.Translate (movespeed*Input.GetAxis("Horizontal")*Time.deltaTime,0f,movespeed*Input.GetAxis("Vertical")*Time.deltaTime); } }
Just FYI that little bug when moving X, also moves Y that doesn't happen on the latest Unity 5. Great tutorials by the way!! Love the detailed explanations, and the exploring along the way.
I made some simple textures for everything up ahead the floor, player, enemy and the walls and didnt really expect to understand of this tutorial as much as I did. :D Thanks. ^-^
I finished this part of the tutorial and I think it's great! I use a sphere instead of a cube, though, it makes some more sense, plus it gives the player the feeling it is unstable and it might roll out of control. I plan to add a texture to it so the rolling is more obvious. I also used different lights, meaning your game will look better in the end, but ok, I guess I'll just go along with my choices, ha ha :D Some of the code stuff is deprecated by now, but Unity and Visual Studio seem to know hot to fix things, because for some reason things end up working almost like in the video. Here's hoping I'll get to the end of this little project :D EDIT: this is how the script looks now... using UnityEngine; using System.Collections; public class PlayerMovement : MonoBehaviour { public float moveSpeed; private float maxSpeed; private Vector3 input; // Use this for initialization void Start () { } // Update is called once per frame void Update () { input = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical")); if(GetComponent().velocity.magnitude < maxSpeed); { GetComponent().AddForce(input * moveSpeed); } } }
@@dtayt1I know right? Reading some of these comments, I wonder how many actually pursued something substantial in game dev or unity. I then wonder what will come of my journey...existential thoughts distracting me from learning, yet again. lol
I think you got the weird movement on the Z axis because the value of Y on the player is 0.23 not 0.25 so perhaps is causing slight collision with the ground.
so, bunch of stuff is a lil different in 5 version, i highly suggest coding in Visual Studio using Resharper, cause some lines are changed, and you need for example instead of animation.Play(); ---------- GetComponent().Play; anyway, in those cases, resharper tells you what to change(in most of cases tho) and also, if your not familiar with c#, watch this guys tuts for it, its great...this problem is also with rigbody, you need to call class GetComponent instead of just going to rigbody property...
okay, when your using lots of cubes or whatever. if u wanna line them up perfectly hold down v from there u should be able to drag the cube to another and it snaps into place :)
You can't slow down because you're telling the game to not update your force IF the body is moving too fast. And it does just that. When you put it in motion, it moves above maxSpeed, hence it doesn't update the force, and with no drag, there's nothing to slow the body down, so it just keeps going at the same speed. Hope I helped.
I do think I have fixed the cube moving diagonally. I went into the Player's rigid body settings, disabled gravity, then set the drag to 3. But for this to work, you have to have the cube start right on the ground, not above it.
am having a problem can any one help me am getting an error when am typing this code :"Rigidbody" because it dose not show up for me the next code what i have to "write it "Rigidbody.addForce am talking about minute 3:55
Hey, first of all, thanks for that awesome tutorials. They helped me alot :). And if somebody wants to reduce the "gravity - move - bug" add this under "input = new Vector3...." : if (input.x != 0 || input.z != 0) // if player does not press anything { rigidbody.useGravity = false; // set gravity to false } else if (rigidbody.velocity.magnitude < 0.05) // if the cube doesn't move "fast" anymore { rigidbody.useGravity = true; // set gravity to true } /* Operator != means : does not equal to.. Operator || means : "or" example : if( x == 0 || x != 1) { ... } means : if x is equal to 0 or " || " x is not equal " != " to 1 { do : ..... } */ Edit : Here's my Code, remember to change public class Move : MonoBehaviour to public class "Name of your Script without quotes" : MonoBehaviour pastebin.com/amcewBNi
Nice video! I have a question though...what exactly is the rigidbody.velocity.magnitude thing? I tried looking at the documentation but didn't find any useful/exact info about it.
I thought it's fine that the Z value changes, since X and Z is the left,right,forward,backwards movement of the player. If the Y value was changing wouldn't that be something to worry about?
When I try to attach the script to the player, it tells me the script doesn't exist. I did save it after editing, I tried restarting Unity, and I tried creating another script which also Unity is saying doesn't exist. I copied the script shown at 25:17 exactly, and I am not receiving an error message at the bottom of Unity. Any ideas from anyone?
Vorundor i have the same problem with guineapigjones and i did checked what you sayed... but the error stills comes out :( what sould i do ??? (sorry for my english)
rigidbody alone is no longer referring to the component of the gameObject the script is attached to, but there's other easy ways around this. Public Rigidbody rb; // will allow you to drag and drop a gameobject into the inspector, and rb will now refer to the rigidbody of //that gameobject void FixedUpdate{ rb.AddForce(input); } Or you can refer to a component of the gameObject the script is attached to as such private Rigidbody rb; void Start(){ rb = gameObject.GetComponent(); } void FixedUpdate (){ rb.AddForce(input); } Or if you wanna grab a component of another object, even if the script isn't attached to it, then you can say private Rigidbody rb; void Start(){ rb = GameObject.FindWithTag("Tag").GetComponent(); } void FixedUpdate(){ rb.AddForce(input); } But my favorite method would be with a public variable for code re-usability.
For all of those using Unity 5 for this tutorial the rigidbody needs to be declared with a reference like this rb = GetComponent(); then you can use rb.AddForce(input * moveSpeed);
@GameGrind I think they fixed the issues with the Z and X axis changing when the other axis only was intended to move. I'm running 5.4 and am not having the issue you experienced.
Great Tut, thank you. The case sensitive input Input threw me at first and I couldnt follow how it could work. Then I realised our own declared 'input' was clawing a stuff from the bigknob Unity 'Input' class.
emm need some help,, why the error is like this? "Error CS1061: 'UnityEngine.Vector3' does not contain a definition for 'GetAxis' and no extension method 'GetAxis' accepting a first argument of type 'UnityEngine.Vector3' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Assembly-CSharp)"
Please explain the code at 32:02 to me its hard to understand (i watched the c# series) what idont understand it is we have this code ... rigidbody.AddForce (input*movespeed); it was called once before we made an if statement and it did what it did (1thing) now it was called in an if statement and it did another thing! the same code? why it went quicker? no matter what if statement u have this code shall not change the question is how did u get to the speed a bit quicker without changing the code (32:23) it would be great if you would explain the whole code at 32:02 with more details thank you
Since he didn't specify an integer for speed, he changed it in his inspected setting of player class he also played around with physics and stuff to get the slide affect... And he also said that if his current speed is less than the movement speed, his current speed will boost up
hey man, i have seen many videos involving movement which were good and helped me make it work but the way you done your tutorial helped me understand the code a bit better and it helped me do a simaler thing in a 2d project so thx man and ill defo be watching the other tutorials
So i used "GetComponent().AddForce(input * moveSpeed); " thanks to +Draknar everything was good with my small cube was moving like a champ until I got to 32:02 . If i put what put in what +AwfulMedia puts in the "if()" statement I get two errors. One states that rigidbody has been depreciated and the other says component doesn't contain a definition for velocity. I know its not a huge deal but I'd rather do it just for the practice and the learning in the new Unity 5. Thank you if you can help!
Tutorial starts at 7:18. for those that want to get straight to it!
Thanks!
Thank you! VERY COOL!
For those who use Unity 5, the code shown in this video for the "PlayerMovement" won't be compatible with that version. Use this code instead:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
private float maxSpeed = 5f;
private Vector3 input;
public GameObject other;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
Rigidbody rigidbody = other.GetComponent();
input = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
if (rigidbody.velocity.magnitude < maxSpeed)
{
rigidbody.AddForce(input * moveSpeed);
}
}
}
Jan Zimmer No this didn't work
Kyle Barnhart I typed this up, it doesn't work the same as the guy in the video though (It doesn't have that slippery feel.)
using UnityEngine;
using System.Collections;
public class Player : MonoBehaviour {
public float moveSpeed = 10f;
void Update () {
if (Input.GetKey (KeyCode.UpArrow)) {
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.DownArrow)) {
transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.LeftArrow)) {
transform.Translate(Vector3.left * moveSpeed * Time.deltaTime);
}
if (Input.GetKey (KeyCode.RightArrow)) {
transform.Translate(-Vector3.left * moveSpeed * Time.deltaTime);
}
}
}
Kyle Barnhart I don't have Unity in front of me but looking at the code I see there is a declaration of a public variable other which is a type GameObject: public GameObject other; The error you are getting is probably an 'UnassignedReferenceException: The variable other of Movement has not been assigned.' which means you need to drag and drop your Player object onto the Movement script's other field in the inspector to complete the reference.
However, you shouldn't even need to reference 'other' just call Rigidbody rigidbody = GetComponent() and it should work (untested). Let me know how you get on.
Logan F That worked, except it doesn't have the floating feel.
Kyle Barnhart
Yeah I know, I'm still working on that :)
Going on 3 years now. Wow! Nice to see people are still finding it useful even with the API changes. Recently started a new series creating a Simple RPG in Unity 5. A bit more complex, with more advanced programming concepts being used, but the end result is going to be pretty cool!
Check out the introduction:
th-cam.com/video/Pp6UNmt8l1I/w-d-xo.html
Your tutorials are nice and cool! your teaching style is great and easy to understand.
same my problem if you have fix it plz let me know so i can fix it 2
I love your teaching style :DD
Best tutorial for beginners, slow and understandable
Pin this comment
So far, this is the best Unity tutorial I've seen! I learned a lot, especially about materials. You take the time to explain things. I can type 80 WPM and would always have to keep pausing videos to keep up when typing in the code while watching the instructor paste in code. I was able to watch your video in one window, and type code in Monodevelop in another window without pausing. Well done!!!
Thank you so much for not having an obnoxious voice. Your videos are very helpful.
Best.Tut.Ever. He actually explains things! With Brackeys and other programming tutorials they just tell you to write stuff down! This is a series you can actually learn from! I highly recommend this to anyone trying to make a game. Keep up the good work AwfulMedia =) !!!
i have completely finished this episode in unity 5 and here is my coding to anybody who needs it -
using UnityEngine;
using System.Collections;
public class playermovement : MonoBehaviour {
public float moveSpeed;
private float maxSpeed = 5f;
private Vector3 input;
// Use this for initialization
void Start () {
}
void Update () {
input = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxis ("Vertical"));
if (GetComponent().velocity.magnitude < maxSpeed)
{
GetComponent ().AddForce (input * moveSpeed);
}
}
}
Thanks!
Thank you!
Thank you sooo much!!
what a life saver
I have been trying to find tutorials on unity, and this guy is the best so far!!!! Every one else goes way to fast and they don't explain things. I have learned to much already! So thank you
PLEASE MAKE A VERSION OF THIS TUTORIAL FOR UNITY 5!
yea plz do
I really like how you taught people how to actually make the player move instead of just saying 'use the character controller'. Very helpful D:
I encountered so many problems using Unity 5 so I uninstalled it and reinstalled Unity 4 and everything is going smooth so far. You go in to depth a lot and this really helps, I'm pretty sure you've taught me more in this one video than I've learnt towards this subject in the past 2 years that I've been at college. Thanks a lot!
Aaron McGuigan I started with Unity 4 and I can't remember why (it was earlier this year so I think U5 was out) but I'm pretty glad I did. Looks like I dodged a bullet by doing so, a lot of people having problems following tutorials because of the differences.
I have such fond memories of this tutorial, which I did years ago. You definitely taught me so much and I knew nothing.
This is the code that worked for me!
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
public float maxSpeed;
private Rigidbody rb;
void Start () {
rb = GetComponent ();
}
void FixedUpdate () {
float moveHorizontal = Input.GetAxisRaw ("Horizontal");
float moveVeritcal = Input.GetAxisRaw ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVeritcal);
if (rb.velocity.magnitude < maxSpeed) {
rb.AddForce (movement * moveSpeed);
}
}
}
+Sean Willoughby thanks dude..i was stuck with that rigidbody.Addforce thing... it really helped..
Wow thanks, this actually worked!
U wrot veritcal instead of vertical
What do i need to press ?
I am a C# noob...
I just started working with unity, i have no programing knowlage what so ever and your vidoes and explenations are so awesome. They really helped me alot.
Movement for Unity 5:
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
private Vector3 input;
Rigidbody cubeMovement;
private float maxSpeed = 5f;
// Use this for initialization
void Start () {
cubeMovement = GetComponent();
}
// Update is called once per frame
void Update () {
input = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
if(cubeMovement.velocity.magnitude < maxSpeed)
{
cubeMovement.AddForce(input * moveSpeed);
}
if(Input.GetKey(KeyCode.A))
{
cubeMovement.AddForce(input * moveSpeed);
}
if(Input.GetKey(KeyCode.D))
{
cubeMovement.AddForce(input * moveSpeed);
}
if(Input.GetKey(KeyCode.W))
{
cubeMovement.AddForce(input * moveSpeed);
}
if(Input.GetKey(KeyCode.S))
{
cubeMovement.AddForce(input * moveSpeed);
}
}
}
Note: cubeMovement = GetComponent(); replaces the Rigidbody.AddForce.
Great Tut btw!
***** Thought so too but apparently not :C
+marco koopman (Eviltoastey) it said there were inconsistent line endings. some are mac and some are windows
+James Robbie It wasn't actually necessary for Marco add that many lines of code to make it work.
+Marco koopman (Eviltoastey) Code doesnt work - sends cube tumbling around... whats the beef?
+Marco koopman (Eviltoastey) omg u are a lifesaver, i was following the video to the letter and getting errors i hadn't a clue why, and den your comment's first line set me straight :P though i was wondering why i was missing a menu option he had....anyway i'm also brand new to scripting so i'd have no chance of writing that myself, thank you again :P
I'd like to apologize for not giving feedback yet, I am enjoying your tutorials thoroughly. They are such a useful tool to learn Unity on! Thank you so much sir!
I think I found a workaround for the "z-axis" drift that is occurring during movement. It has to do with the amount of "surface contact" between the floor's box collider and the player's box collider. Because the box collider for the player is the same size as the box, the entire bottom surface of the box (or it's collider) is in constant contact with the floor (or it's collider). This causes the physics engine to generate, what seems to be, random friction points along the two surfaces. In turn this causes the drifting. I've noticed that the drifting isn't always in a constant direction. When the player crosses boundary lines of the floor when the floor is expanded to a larger size, it takes on a new "random" friction direction.
Ok, so where's the workaround? I started playing with the player collider shape. When I made it a sphere collider (it defaults to the same size and center of the player) the drifting was virtually eliminated. But that posed another problem. When entering the maze the player's vertical edges would enter the maze walls until the sphere collided with the maze walls. This looked funny and it took more penetration into the goal before it registered the trigger (actually this was a nicer effect). In order to correct the interaction with everything else except the floor, I added another collider (a box collider). I set it's height to about half the height of the player box and left it's center alone. This provided the desired collision with the floor and the maze. However, I did have to up the drag on the rigidbody of the player to about 5 since it was only contacting the floor at one tangential point (theoretically).
I hope this workaround is useful to you.
Thanks for this.
The first good and explanatory tutorial found so far. The good thing about your explanation, is you share thoughts, why you did it and why you didnt. Keep up the good work, and Ill watch your tutorials from now on. Rock on!
That intro is just amazing
If your x Axis is affecting the z Axis (and vice versa), try using a sphere or capsule collider instead of a box collider.
I think the corner of the box collider tends to stick to the floor, which causes the rigidbody to move in the direction the corner is facing.
Around the 10:00 mark when he uses the directional light, I cannot replicate that in Unity. I have the newest version, has anything changed in how light works in the engine?
+lleon79 I struggled with this too for a better part of an hour. I think I may have found the answer:
go to Window > Lighting and under Scene tab make sure Skybox is set to None.
Suddenly I was able to manipulate the light on the floor. I hope this helps.
+Chase Lirette Thanks so much for the tips
Any beginner must follow these courses first. This course is well explained.
If your cube didn't move after AddForce try to disable its gravity or just increase the moveSpeed.
it works for me thnks a lot :)
For me i change the position of player box for example little bit high from floor box
the gravity bug is due to the collision innacurracies of the basic vertex (thin plate) collision.
basically it gets pushed away from the ground, with some innaccuracies.
thank you very much for the nice and clear control scheme and clear tutorial, much appreciated :)
Is c# a good language for developing simple games? I'm currently studying c# in school after learning Java last semester and find it a lot easier! What language do you recommend I expand my knowledge on?
+Harry Fielding post what?
+Harry Fielding nah wasn't me and thanks :)
Also, it is your Z axis that's supposed to move as Y makes it go up and down. X is horizontal movement and is perfectly assigned. To move "vertically" the depth of the object is changed (Z).
Error:
Assets/Scripts/PlayerMovement.cs(18,27): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3, UnityEngine.ForceMode)'
script:
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
private Vector3 input;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
Rigidbody.AddForce (input * moveSpeed);
}
}
is rigidbody no Rigidbody
***** If you are using Unity 5, you will have to add it manually. Do like so:
public GameObject other;
Rigidbody rigidbody = other.getComponent();
rigidbody.AddForce(1, 1, 1);
After that, remember to add the "Player" GameObject in the "Player Movement" script on the inspector. Else it won't work
Jan Zimmer Well I also use unity 5 and I also have the same problem but which part of the code do I add that code into
(hopefully that made sense)
Put it at the beginning of your Update() method. Here's my whole code :) :
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed;
private float maxSpeed = 5f;
private Vector3 input;
public GameObject other;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
Rigidbody rigidbody = other.GetComponent();
input = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
if (rigidbody.velocity.magnitude < maxSpeed)
{
rigidbody.AddForce(input * moveSpeed);
}
}
}
Jan Zimmer Thank you very much :D
You've just sparked the greatest marble game concept of all time, my friend. This should fuel my interest for Unity and C# now.
now that it has been 6 years, how many games have you made?
your welcome
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movment : MonoBehaviour
{
public float moveSpeed;
private Vector3 input;
private float maxSpeed = 5f;
// Start is called before the first frame update
void Start()
{
}
void Update()
{
input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
GetComponent().AddForce(input * moveSpeed);
}
}
Thank you so much
@@Kmh-pl9ze Your welcome
There is no problem with Z if it's still the case... Look at your coordinate system gizmo. Y pointing up, that is what you "locked" in your equation. So your movement is in XZ plane, thats why X and Z coordinates are changing... Hope explained good. Very good tutorial for beginners. Thanks a lot!
rigidbody.velocity.magnitude problems??
Use this: GetComponent().velocity.magnitude
Thankyou so much, thats work for me,, thankyou
Thank you! :)
halo maarv, I can't continue at part 6 . if you can do it at part 6. please join the script with me okay. thankyou
. sorry for bad English
thx
Where do we put it?
Thank you so much. I got a book on C# and I am not finished yet but it focuses on mainly software which is fine for me as it (so far) has taught me the basics of C# so this was WAY more helpful and easy for me to follow then what it was a while back. Great job with this video bro! I am going to watch all of this series for sure.
everything is fine but I cant move I used GetComponent().AddForce(input * moveSpeed); but still wont move
same
same
try to use unity 5.0.2
Change the Rigid body above to the getcomponent code
can u explain more Mortycon?
This tutorial is exactly what I was looking for. I'm coming into Unity as a C# programmer and there were a lot of things I wasn't sure about such as how to make references to other components in a GameObject (26:30) so it is good to see you have a similar sort of background.
Still a lot of difference between the 2 that haven't quite 'clicked' yet but I think your series is going to be very helpful. Thanks for sharing.
RyanFaeScotland Hey look, it's me 2 months ago! Wow I've came on so much from then hehe.
8 years man, wow.
i got an error for "getAxis". Severity Code Description Project File Line Suppression State
Error CS1061 'Vector3' does not contain a definition for 'GetAxis' and no extension method 'GetAxis' accepting a first argument of type 'Vector3' could be found (are you missing a using directive or an assembly reference?) Assembly-CSharp C:\Users\NanuckDogg\Documents\tutorial\Assets\scripts\PlayeMovement.cs 16 Activecould someone help me pls?
Capital I in input
NOTE: if there is a problem with the rigidbody around 30:07 then try using "GetComponent().AddForce" instead, it worked for me.
I really love the game idea and I was wondering if I could make a full game out of it and distribute it if that is okay? I would like to implement some other features and services in the game.
Don't see why not, its your own game! You just had some help making it. Do what ever you want with it, if you want say you had help from the maker of this tutorial.
YOTOPRULES-youtube Okay thanks anways. And yes I will if I make it.
JTechGaming
tell me when released i want it!!!!!
Captain Shorty sure. I'm gonna add leaderboards, in app purchases, achievements and more!
JTechGaming
tell me when its out
This is probably the best introduction to C# Unity that I've found so far on the net. Thank you!!! Vector3 makes sense now :)
This is really good. Thanks a lot for putting in the effort!
@iyitkil :)
Hey Austin, I'm completely new to this, I know a few people who program, but I've never delved into it myself until recently. I stumbled upon this and I just wanted to say that this is awesome stuff. For me, one of the best ways for me is to just jump right in, and you help with that and teach along the way. Some of the stuff gets a little lost in the abyss at times, but definitely keep up the repetition, it allows the programming diction to stick in people's heads better (my head at the very least). Good job again!
my pc crashed when i told the cube to move
lol
i thought im the only one
is your pc good or is it a potato
Thats nothing. My computer committed suicide.
I download your tutorials to watch them later. They have been a great help. I come from a Python/Blender background; and learned some C++ in college, so this clicks so much. It is presented in an understandable and relevant way. It's difficult to get more than a dirty look out of me for a response, but I'd like to thank you for these videos.
void Update () {
input = new Vector3(Input.GetAxis ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
GetComponent().AddForce(input * maxSpeed);
{
GetComponent().AddForce(input * moveSpeed);
}
}
}
hope this helps!
Thats what I was searching for!
I must say, your previous tutorials were very good. This one is a bit fast, I think. I could see how an inexperienced programmer would get lost and have to pause a bunch in these. My suggestion, for those less familiar with Unity... watch a bunch of the videos in succession and THEN go back and follow along. You will have less trouble keeping up, and everything will feel familiar.
Otherwise, good job Austin. Keep it up. I'm a web developer looking to get into C# and Unity, and these tutorials have been just what the doctor ordered and the pace is just fine for me.. I'd recommend slowing down what you're doing a little bit for the less experienced.
you make game making look easy :D im only 15 and im going to learn as much as i can from you, im going to make a small game maybe for IOS for my first game or something idk yet, and hopefully people will like it and il start off my game dev career :3
have you made your game yet?
Solid guy
The quality of the voice recording really sets this tutorial apart from the rest. Sounds great and is very easy to pay attention to. Thanks!
Hi, I'm 13 years old and I'm thinking what kind of subjects should I take later on if I want to become a developer? I was just wandering :)
Hey Kingkizz, honestly, it does not really matter that much. Grades and diplomas don't matter that much in the games industry, except for people who want to work at EA or alike, but if you look on their sites, in generally says (example): "Masterclass game design or equal working experience" as a requirement. The best thing you can do is just start learning and join projects as a programmer or so. Then again, you should know that Game Development is a lot of different things, not just programming ;)
Hope this helped!
V_R
Ok yeah thanks, I thing starting now at a young age as well will help me with experiance
Now to sell your identity!
DrOvi Jolt Was that meant for me or for Kingkizz...? And what exactly did you mean by it...?
I meant it for Kingkizz, and I was joking. At least that's as far as I know.
I really enjoyed this series! Austin, you were very clear and concise and I appreciated your thoroughness in regards to explaining every little detailed step along the way to help us beginners.
One thing I would love to know is how to get an enemy AI to seemingly move randomly through a maze. Not sure if this would be done with a waypoint system where the enemy could randomly choose which nodes to walk to, if it would be some sort of raycasting wall collision detection, or a navmesh function? I would love to learn how to do this without the use of plugins. If anyone knows, I am all ears. Thanks!
i want that game
Great tutorial , easy to understand and really helpful for newbies like me who are just getting started with the Unity game engine.Looking forward to more of unity tuts from this channel.
Keep on uploading these amazing tutorials.
Part 1 450k views, part 2 70k views. lol.
Wanted to make Call Of Duty but didn't work out.
+StraightUpGaming You can't make COD as it requires almost 200 to 300 people as it very complex and vast
Malik Bilal Did you read my comment, that's what I said.
+Malik Bilal Yes you can.. You don't even need a prebuilt engine for it. Programming is not hard at all.
***** You can't make a COD in your lifetime.
Now going to second step. One of the best lessons on youtube.
this tutorial seems good - but it is simply filled with irrelevant stuff... minutes of color choosing... come on. make it grayscale and get to the point :/
I just met your videos first time now on youtube. What a great videos! I subscribed right away. Thank you!
I love these tutorials, because you're one of the few people who actually tell EVERY little detail!
I am trying to use your tutorials to create a prototype which can be used for Dungeons and Dragons Roll20 as a Combat Simulator type of thingy, where you can actually see the combat and stuff =D
I have some suggestions , keep the unity layout default, hierarchy at the left, assets at the left bottom, inspector at the right, scene and game in the middle up, that will be better for beginners
rigidbody.AddForce() is deprecated!
Use this instead:
Declare a
public Rigidbody rbName;
Then in the Start () method add
rbName= GetComponent();
And use it in the Update() method as
rbName.AddForce(transform.forward * speedModifier);
-----------------------------------------------------------------------------------------
----------------FULL CODE------------------------------------------------------
----------------------------------------------------------------------------------------
public float speedModifier = 10;
public Rigidbody rb;
private Vector3 userInput;
void Start () {
rb = GetComponent();
}
void Update () {
userInput = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
rb.AddForce(userInput * speedModifier);
}
thanks for update this!
thanks
I know I'm late, but can you explain why you do > ?
UPDATE: like, I know it's just a variable to make it easier to write later on, but why do you do this: rb.AddForce(...........)
rb is basically your object, and AddForce() is a method. So you add a force to your object, and as we know, F=m*a, so you give the object an acceleration, which results in velocity.
something else, in the video he writes this:
if (rigidbody.velocity.magnitude < MaxSpeed) {
rb.AddForce (UserInput * SpeedModifier);
}
the "rigidbody.velocity.magnitude" doesn't work..
UPDATE: I just found it... you have to use rb (the variable declared earlier) so it becomes: rb.velocity.magnitude
This was an excellent beginning tutorial. Ultimately, the entire series was very inspiring and led me to start my own Maze type game. Thanks for the work you did on the video.
does it work in 2019
@@CringeMaster64 The software I started works on the most recent version of Unity. It just imported no problem.
Ur great at these tutorials because normally it would be 10 mins of people rushing to show u stuff
for the movement of the cube he made it a little more complicated than it has to be for new users you can just use this its bassically the same thing but without the rigid body and vector 3 but using a float for the speed
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playerMovement : MonoBehaviour {
public float movespeed;
void Start ()
{
movespeed = 7f;
}
void Update ()
{
transform.Translate (movespeed*Input.GetAxis("Horizontal")*Time.deltaTime,0f,movespeed*Input.GetAxis("Vertical")*Time.deltaTime);
}
}
thank you for this
This works as of 4JUL18. Thanks.
Just FYI that little bug when moving X, also moves Y that doesn't happen on the latest Unity 5. Great tutorials by the way!! Love the detailed explanations, and the exploring along the way.
I made some simple textures for everything up ahead the floor, player, enemy and the walls and didnt really expect to understand of this tutorial as much as I did. :D Thanks. ^-^
I finished this part of the tutorial and I think it's great! I use a sphere instead of a cube, though, it makes some more sense, plus it gives the player the feeling it is unstable and it might roll out of control. I plan to add a texture to it so the rolling is more obvious. I also used different lights, meaning your game will look better in the end, but ok, I guess I'll just go along with my choices, ha ha :D
Some of the code stuff is deprecated by now, but Unity and Visual Studio seem to know hot to fix things, because for some reason things end up working almost like in the video.
Here's hoping I'll get to the end of this little project :D
EDIT: this is how the script looks now...
using UnityEngine;
using System.Collections;
public class PlayerMovement : MonoBehaviour {
public float moveSpeed;
private float maxSpeed;
private Vector3 input;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
input = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
if(GetComponent().velocity.magnitude < maxSpeed);
{
GetComponent().AddForce(input * moveSpeed);
}
}
}
idk why its so interesting to see old comments and wonder how much their life has changed lmao
@@dtayt1I know right? Reading some of these comments, I wonder how many actually pursued something substantial in game dev or unity. I then wonder what will come of my journey...existential thoughts distracting me from learning, yet again. lol
I think you got the weird movement on the Z axis because the value of Y on the player is 0.23 not 0.25 so perhaps is causing slight collision with the ground.
Awful? AwfulMedia is the best media ever!
so, bunch of stuff is a lil different in 5 version, i highly suggest coding in Visual Studio using Resharper, cause some lines are changed, and you need for example instead of animation.Play(); ---------- GetComponent().Play; anyway, in those cases, resharper tells you what to change(in most of cases tho) and also, if your not familiar with c#, watch this guys tuts for it, its great...this problem is also with rigbody, you need to call class GetComponent instead of just going to rigbody property...
okay, when your using lots of cubes or whatever. if u wanna line them up perfectly hold down v from there u should be able to drag the cube to another and it snaps into place :)
32:04 my code had a compiler error something to do with the parantheses and the semi colons. Help?
Metal Gear Solid called, they want their VR Training levels back!
Great looking tutorial guys, going to save this and watch after work.
You can't slow down because you're telling the game to not update your force IF the body is moving too fast. And it does just that. When you put it in motion, it moves above maxSpeed, hence it doesn't update the force, and with no drag, there's nothing to slow the body down, so it just keeps going at the same speed.
Hope I helped.
I do think I have fixed the cube moving diagonally. I went into the Player's rigid body settings, disabled gravity, then set the drag to 3. But for this to work, you have to have the cube start right on the ground, not above it.
Thanks a lot, as a complete beginner I find your tutorial mesmerizing, and really useful for creating your first game. Subscribed!
Wait. At 24:06 isn't instanciating a new vector every frame very inefficient??
am having a problem can any one help me am getting an error when am typing this code :"Rigidbody" because it dose not show up for me the next code what i have to "write it "Rigidbody.addForce am talking about minute 3:55
Your voice is *AWESOME!!!*
Best tutorial ever! Reilly helped me get started with Unity
Do all ur tutorials work with the free version?
I learned so many things from this tutorial! Now I am almost finished with my own game called "Dodge the Cubes!"
Did you ever figure out why the box slides up in the z axis when you go right horizontally?
Hey,
first of all, thanks for that awesome tutorials.
They helped me alot :).
And if somebody wants to reduce the "gravity - move - bug" add this under "input = new Vector3...." :
if (input.x != 0 || input.z != 0) // if player does not press anything
{
rigidbody.useGravity = false; // set gravity to false
}
else if (rigidbody.velocity.magnitude < 0.05) // if the cube doesn't move "fast" anymore
{
rigidbody.useGravity = true; // set gravity to true
}
/*
Operator != means : does not equal to..
Operator || means : "or"
example :
if( x == 0 || x != 1)
{
...
}
means :
if x is equal to 0 or " || " x is not equal " != " to 1
{
do : .....
}
*/
Edit :
Here's my Code, remember to change
public class Move : MonoBehaviour
to
public class "Name of your Script without quotes" : MonoBehaviour
pastebin.com/amcewBNi
What computer are you using?
Nice video! I have a question though...what exactly is the rigidbody.velocity.magnitude thing? I tried looking at the documentation but didn't find any useful/exact info about it.
To change the Ambient:
Windows -> Lighting -> Settings. Then go to the Environment Lighting in the Environment Tab. Change the source to 'Color'.
I thought it's fine that the Z value changes, since X and Z is the left,right,forward,backwards movement of the player. If the Y value was changing wouldn't that be something to worry about?
When I try to attach the script to the player, it tells me the script doesn't exist. I did save it after editing, I tried restarting Unity, and I tried creating another script which also Unity is saying doesn't exist. I copied the script shown at 25:17 exactly, and I am not receiving an error message at the bottom of Unity. Any ideas from anyone?
Make sure that in the code the first public class is the same name as the file name.
Vorundor i have the same problem with guineapigjones and i did checked what you sayed... but the error stills comes out :(
what sould i do ???
(sorry for my english)
thankyou Vorundor you fixed my problem and now im abl to continue
The word is slippery and keep up! Im finally learning Unity, thanks to you man. you explain everything in detail and I love it, +1 SUb!
rigidbody alone is no longer referring to the component of the gameObject the script is attached to, but there's other easy ways around this.
Public Rigidbody rb; // will allow you to drag and drop a gameobject into the inspector, and rb will now refer to the rigidbody of
//that gameobject
void FixedUpdate{
rb.AddForce(input);
}
Or you can refer to a component of the gameObject the script is attached to as such
private Rigidbody rb;
void Start(){
rb = gameObject.GetComponent();
}
void FixedUpdate (){
rb.AddForce(input);
}
Or if you wanna grab a component of another object, even if the script isn't attached to it, then you can say
private Rigidbody rb;
void Start(){
rb = GameObject.FindWithTag("Tag").GetComponent();
}
void FixedUpdate(){
rb.AddForce(input);
}
But my favorite method would be with a public variable for code re-usability.
For all of those using Unity 5 for this tutorial the rigidbody needs to be declared with a reference like this
rb = GetComponent();
then you can use
rb.AddForce(input * moveSpeed);
what is the unity 5 version of the if statement at 31:22?
@GameGrind I think they fixed the issues with the Z and X axis changing when the other axis only was intended to move. I'm running 5.4 and am not having the issue you experienced.
also, i think i'm going to play around with the 'freeze rotation' off :P
Amazing video series, explain everything so well! In-depth but not wasteful with time!
Great Tut, thank you. The case sensitive input Input threw me at first and I couldnt follow how it could work. Then I realised our own declared 'input' was clawing a stuff from the bigknob Unity 'Input' class.
The moveSpeed variable doesn't appear in the Player.
I attached it just fine and the script appears in the Player, but there is no moveSpeed variable?
Make sure to set moveSpeed to public instead of private
emm need some help,, why the error is like this?
"Error CS1061: 'UnityEngine.Vector3' does not contain a definition for 'GetAxis' and no extension method 'GetAxis' accepting a first argument of type 'UnityEngine.Vector3' could be found (are you missing a using directive or an assembly reference?) (CS1061) (Assembly-CSharp)"
thanks bro i have download unity a week earlier i m a complete noob..........
But ur vid helped a lot
Please explain the code at 32:02 to me
its hard to understand (i watched the c# series)
what idont understand it is we have this code ... rigidbody.AddForce (input*movespeed);
it was called once before we made an if statement and it did what it did (1thing)
now it was called in an if statement and it did another thing! the same code? why it went quicker? no matter what if statement u have this code shall not change
the question is
how did u get to the speed a bit quicker without changing the code (32:23)
it would be great if you would explain the whole code at 32:02 with more details
thank you
Since he didn't specify an integer for speed, he changed it in his inspected setting of player class he also played around with physics and stuff to get the slide affect... And he also said that if his current speed is less than the movement speed, his current speed will boost up
hey man, i have seen many videos involving movement which were good and helped me make it work but the way you done your tutorial helped me understand the code a bit better and it helped me do a simaler thing in a 2d project so thx man and ill defo be watching the other tutorials
If you freeze the rotations on all axes, the Z position won't change when you move on the X and vice versa.
Thank you,
Because of you I have a direction to create a game.
keep doing what you are doing!!!
So i used "GetComponent().AddForce(input * moveSpeed); " thanks to +Draknar everything was good with my small cube was moving like a champ until I got to 32:02 . If i put what put in what +AwfulMedia puts in the "if()" statement I get two errors. One states that rigidbody has been depreciated and the other says component doesn't contain a definition for velocity. I know its not a huge deal but I'd rather do it just for the practice and the learning in the new Unity 5. Thank you if you can help!
Have you set your maxSpeed in the inspector window? By default it would be 0.
This had gotten good and I know it is back-order but I think it's the first introduction tutorial, yeah I'll subscribe.