Is the “Character Controller” all I need to turn an object into my main player?
Hi TheRedGuy90,
I would reccomend to delete additional cameras if there any exists, unless you plan to create a system or a mechanic which would allow moving between the views.
As of your question - Yes, “Character Controller” will make the object it handles the main player.
If you need additional information about it, you can read it up here
Sincerely,
Trimadix
my player doesnt move.
are there awkward keys assigned to movement? I’m just using the arrow keys.
Do I need to add a “jump” component if I want my character to jump?
The details of my current project are a cube on a terrain, and I just assigned a Character Controller to the cube.
I didnt think you were talking about the component. Well as of the component, no, it certainly doesnt make your game object your main player and it doesnt involve movement mechanics themselves, it only includes and consists of different mechanics of physics like slope detection, distance between slopes and the object etc.
If you want to play around with movement and youre new I would advice you to go to the top of Unity where you find all the tabs for adding objects and manipulating the game (file, edit, assets etc). Click Assets → Import Package → Character Controllers. Youll see that it will add a new folder and youll find a nicely configurated fps and 3d person models. When youll add them to your map, theyll automatically become your main player with cameras and scripts attached to them.
If you want to move around with using assets and just blunt code, you could go ahead and create a new script.
Ill give you a C# copy of moving around, though it still requires modifications such as jump, walk etc. There could be a lot improved, but I assume youre looking for the basics and its easy to read.
using UnityEngine;
using System.Collections;
public class MovementScript : MonoBehaviour {
public float moveSpeed = 5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
if (Input.GetKey(KeyCode.D))
{
gameObject.transform.Translate(moveSpeed * 0.05f,0,0);
}
if (Input.GetKey(KeyCode.A))
{
gameObject.transform.Translate(-moveSpeed * 0.05f,0,0);
}
if (Input.GetKey(KeyCode.W))
{
gameObject.transform.Translate(0,0,moveSpeed * 0.05f);
}
if (Input.GetKey(KeyCode.S))
{
gameObject.transform.Translate(0,0,-moveSpeed * 0.05f);
}
}
}
I installed the 3rd person controller from the assets.
My cube gets suspended in the air as soon as I hit an arrow key for some reason. It can jump, but just stays about 10 off the ground and cant go anywhere.
You’re opening up a can of worms. I recommend starting with the mecanim tutorial and a humanoid character. Start here: Learn game development w/ Unity | Courses & tutorials in game design, VR, AR, & Real-time 3D | Unity Learn
My character is not humanoid. It is a 2D Sprite in 3D.
What do I add to this to detect collision; adding a Rigidbody has too many adverse effects.
In the new version, I get an error "movespeed does not exist in the current context. I changed the parentheses to brackets, and get the error “only assignment, call etc. can be used as a statement”. What’s changed
What’s happening is you’re trying to write a computer program, without knowing how to program. I recommend to learn C#. Then you’ll know things like: You can’t just change parenthesis to brackets, these things mean different things. And when it says “movespeed” does not exist, it’s different from “moveSpeed” (notice the capital S).
Here’s some links to get you started.
https://channel9.msdn.com/Series/C-Sharp-Fundamentals-Development-for-Absolute-Beginners
https://www.udemy.com/programming-for-complete-beginners-in-csharp/
Well, moveSpeed isn’t recognized either.
And this script worked just fine in the earlier version of Unity before my computer died on me and I had to reinstall.
It would never work changing parenthesis to brackets.
Also, “moveSpeed” is clearly at the top of the script:
public float moveSpeed = 5f;
So check all your usages of it, make sure you don’t have some extra braces in places where they shouldn’t be.
And take one of those courses, so you know how C# works.