- Home /
Movement Problems PS4 Controller
I'm building a 2D platforming project and I started to expand the controls from just keyboard to PS4 controller and the only part I can not figure out is getting the axis (analogs sticks/directional buttons) to work with it. I have map my PS4 controller in the Input Manager, but is I am still running into a problem with using the "Horizontal" for my player movement. I believe this is a problem with my scripting, I have tried GetAxis and several other scripting found on the internet and the ones found in unity's 2D projects scripting and it gets me no where which makes me believe it's my scripting that is interfering with being able to use any of the PS4 axis inputs.
Here is my pieced together script that I have been using to move around and now stick on.
using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;
public class PlayerController : MonoBehaviour
{
//Movement
public float speed;
public float jump;
public bool candoublejump;
public GameObject deathParticles;
public GameObject JumpingParticles;
public GameObject BigJumpingParticles;
public int LiveCount;
float moveVelocity;
public Vector2 spawn;
//Grounded Vars
bool grounded = true;
void start()
{
spawn = transform.position;
}
void Update()
{
//Jumping
if (Input.GetKeyDown(KeyCode.Space) || Input.GetKeyDown(KeyCode.Joystick1Button1))
{
if (grounded)
{
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jump);
Instantiate(JumpingParticles, transform.position, Quaternion.identity);
candoublejump = true;
print("jump!!");
}
else
{
if (candoublejump)
{
candoublejump = false;
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jump);
Instantiate(BigJumpingParticles, transform.position, Quaternion.identity);
}
}
}
moveVelocity = 0;
//Left Right Movement
if (Input.GetKey(KeyCode.LeftArrow))
{
moveVelocity = -speed;
}
if (Input.GetKey(KeyCode.RightArrow))
{
moveVelocity = speed;
}
GetComponent<Rigidbody2D>().velocity = new Vector2(moveVelocity, GetComponent<Rigidbody2D>().velocity.y);
}
//Check if Grounded
void OnTriggerEnter2D()
{
grounded = true;
print("Grounded!!!!!");
}
void OnTriggerExit2D()
{
grounded = false;
}