I am a newbie and I have been watching all sorts of 2D tutorials. I am interested in making a platformer among other types of games. The problem I keep running into is that all of the tutorials have outdated code and I hit a wall. I have taken quite a few C# courses too for newbies but the problem is that I do not have enough skills to adequately troubleshoot the code errors. And many of the tutorials are made w. Unity 5 but it still has dated references.
So here is my question is:
How do I make a controller for a 2D character Controller?
The best video I came across was the Unity sponsored 2D Character Controllers but that has old code too. So I get far into making a good controller but I get all sorts of errors. Please help.
Option 2: I do not know the workflow yet but is it possible to download a controller form the asset store? If so, which is a good 2D controller?
how complicated do you want the controller? will you be using physics & rigidbody2d on the character?
Edit: it might help if you post the code you did that is the one you want to use (use the code tags so it is inserted correctly) & then paste all the errors that you have with it as the console messages will identify the lines it is having issues with.
This guy, he’s basically Jesus to Unity newcomers. Very good tutorial on how to make a solid competent raycast based controller. Not just a walk through of how to do it, actually gives you a pretty good understanding on how it all works so that you may apply the techniques used elsewhere.
First off, thank you for the prompt reply, TedTheBug Very much appreciated. To answer your questions specifically:
How complicated do I want the controller to be?Dead Simple. Being a newbie, I just want it working at first. I can complicate things later
Here is a look at the code:
using UnityEngine;
using System.Collections;
public class CharacterControllerScript : MonoBehaviour
{
public float maxSpeed = 10f;
bool facingRight = true;
Animator anim;
// Use this for initialization
void Start ()
{
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void FixedUpdate ()
{
// How much the character is moving
float move = Input.GetAxis ("Horizontal");
anim.SetFloat ("Speed", Mathf.Abs (move));
// Moves the character
GetComponent<Rigidbody2D>().velocity = new Vector2 (move * maxSpeed, Rigidbody2D.velocity.y);
// Checks the character direciton
if (move > 0 && !facingRight)
Flip ();
else if (move < 0 && facingRight)
Flip ();
}
void Flip()
{
// Flips the characters direction
facingRight = !facingRight;
Vector3 theScale = transform.localScale;
theScale.x *= -1;
transform.localScale = theScale;
And I get three errors. They are:
Assets/Scripts/CharacterControllerScript.cs(29,98): error CS0120: An object reference is required to access non-static member `UnityEngine.Rigidbody2D.velocity’
Assets/Scripts/CharacterControllerScript.cs(29,109): error CS1502: The best overloaded method match for `UnityEngine.Vector2.Vector2(float, float)’ has some invalid arguments
Assets/Scripts/CharacterControllerScript.cs(29,109): error CS1503: Argument #2' cannot convert object’ expression to type `float’
Thanks a bunch for this link, Prototypetheta. I am going to start looking at them now. At first glance, they look very good and high quality. A great resource.
I am having trouble finding tutorials that teach “why” they are doing things a certain way. Quite often they tell the viewer to add some code- but it doesn’t explain why they made those decisions. So when I run into a problem or outdated code, I do not have the ability to troubleshoot the situation myself.