I am trying to make Sidescroller movement script based on Character Controller. I have a big problem and I don’t know how to solve it. Slow falling, not touching the ground etc. If you know what I am trying to make, you sure know what my problem is. First, I had unexpected Z-axis moving which hasn’t been mentioned anywhere in my code. I used online documentation as help, so, as you can assume, I am not fully expirienced Unity user.
Code:
using UnityEngine;
using System.Collections;
public class ccMove : MonoBehaviour {
CharacterController cc;
public float speed = 6f;
public float gForce = 20f;
public float jumpSpeed = 10;
private float xSpeed;
private float ySpeed;
private float movementSpeed;
private Vector3 moveDirection;
private Vector3 rotacija;
// Use this for initialization
void Start () {
cc = GetComponent<CharacterController>();
}
// Update is called once per frame
void FixedUpdate () {
float side = Input.GetAxis("Horizontal");
//if (side = 1) {Vector3 rotacija = new Vector3(0,0,0);} else {
//if (side = -1) {Vector3 rotacija = new Vector3(0,180,0);} }
transform.eulerAngles = rotacija;
moveDirection = new Vector3(side, 0, 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (cc.isGrounded Input.GetButtonDown("Jump")) {
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gForce *Time.deltaTime * 2f;
cc.Move(moveDirection * Time.deltaTime);
transform.position = new Vector3(transform.position.x, transform.position.y, 0);
}
}
I was looking back at an old tutorials FPS movement script, but I guess I still don’t know how exactly this script is supposed to work, I mean cc.Move…does it check xyz Vector3 or direction *speed?
Else…I don’t know how to make character face the direction I want and move in it. Collisions aren’t responding too…
If someone has an idea how to make it, please remake this kode or post your own.
I hope this thread will be useful to someone. 
Well I don’t know much too but, one thing that caught my eye is when I saw the “Vector3” part. Instead of Vector3, it should be Vector2, which shows 2D movement/direction.
I still get errors on line 38 but, beside that everything is right in the script and also has the no z-axis like you wanted.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ccMove : MonoBehaviour
{
CharacterController cc;
public float speed = 6f;
public float gForce = 20f;
public float jumpSpeed = 10;
private float xSpeed;
private float ySpeed;
private float movementSpeed;
private Vector2 moveDirection;
private Vector2 rotacija;
void Start()
{
cc = GetComponent<CharacterController>();
}
void FixedUpdate()
{
float side = Input.GetAxis("Horizontal");
//if (side = 1) {Vector3 rotacija = new Vector3(0,0,0);} else {
//if (side = -1) {Vector3 rotacija = new Vector3(0,180,0);} }
transform.eulerAngles = rotacija;
moveDirection = new Vector2(side, 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (cc.isGrounded Input.GetButtonDown("Jump"))
{
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gForce * Time.deltaTime * 2f;
cc.Move(moveDirection * Time.deltaTime);
transform.position = new Vector2(transform.position.x, transform.position.y);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ccMove : MonoBehaviour
{
CharacterController cc;
public float speed = 6f;
public float gForce = 20f;
public float jumpSpeed = 10;
private float xSpeed;
private float ySpeed;
private float movementSpeed;
private Vector2 moveDirection;
private Vector2 rotacija;
void Start()
{
cc = GetComponent<CharacterController>();
}
void FixedUpdate()
{
float side = Input.GetAxis("Horizontal");
//if (side = 1) {Vector3 rotacija = new Vector3(0,0,0);} else {
//if (side = -1) {Vector3 rotacija = new Vector3(0,180,0);} }
transform.eulerAngles = rotacija;
moveDirection = new Vector2(side, 0);
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (cc.isGrounded && Input.GetButtonDown("Jump"))
{
moveDirection.y = jumpSpeed;
}
moveDirection.y -= gForce * Time.deltaTime * 2f;
cc.Move(moveDirection * Time.deltaTime);
transform.position = new Vector2(transform.position.x, transform.position.y);
}
}
[/QUOTE]
You forgot to add the && in the middle of the if statement, you should try it now.