- Home /
Need Help in Restricting Player Movement to Only 2 Axis,
I am creating a 2.5D Side Scrolling type Game. For the most part I am using a 3rd Person Character controller. The Major Problem that I am facing is how I can limit the motion of my Player Character to Just 2 Axis. I want to make a Fully Fledged Game so Climbing Ropes and Jumping Rocks etc everything will be there. I am not quite experienced with Unity. Although I have created few 2D. For the 3D World it’s Just a different Universe. There are Zillions of things out there on internet and I have researched allot and read, understood and done so many things to get my task done. But I am unable to achieve what I am looking for. I want my character controller to Use Mechanim, It is creating issues for me because almost All of the tutorials that I am focusing are Legacy Animation Oriented. Please Help me so I may proceed. I am not asking for spoon feeding and Kindly excuse me if I am doing wrong by posting.
Answer by Mmmpies · Jan 19, 2015 at 04:38 PM
In theory, as I don't program 2.5D games myself, you could just not bother moving the Z axis of the character.
using UnityEngine;
using System.Collections;
private float mySpeed;
private float jumpSpeed;
function Start () {
mySpeed = 4.0f;
jumpSpeed = 6.0f;
}
function Update () {
if ( Input.GetKey(KeyCode.z) ) {
transform.position.x -= mySpeed * Time.deltaTime;
}
if ( Input.GetKey(KeyCode.x) ) {
transform.position.x += mySpeed * Time.deltaTime;
}
if ( InputGetKey(KeyCode.Space) ) {
transform.position.y += jumpSpeed * Time.deltaTime;
}
}
Well that jump's pretty dodgy, you probably want to have a rigidbody and apply an upward force.
As for the mecanim, you probably just need to understand how to send bools to change the animation that's being played.
All of this is untested but hopefully will give you a starting point.
I hope so. but atleast for now. I am not quite successful doing stuff.
Had a quick look for some tutorials and found these:
Your answer
