# Rigidbody only moving in one direction

So I’m not a coder so this is hell for me, but I am trying to get my head around this so bear with me please.

I got this code

using UnityEngine;
using System.Collections;

public class PlayerScript : MonoBehaviour {

public static float distanceTraveled;
private Touch curTouch;
public float speed;
public float maxSpeed;
public float maxSpeedConstant;

//Virtual buttons left and right half of the screen
private Rect leftHalf = new Rect(0F,0F,Screen.width/2,Screen.height);
private Rect rightHalf = new Rect(Screen.width/2,0F,Screen.width/2,Screen.height);

public void Update() {
distanceTraveled = transform.localPosition.x;
}
public void FixedUpdate() {
Movement ();
}

public void Movement(){

if(rigidbody.velocity.magnitude > maxSpeed)
{
rigidbody.velocity = rigidbody.velocity.normalized * maxSpeed;
}

//Accelerometer Control up/down
Vector3 dirAcc = Vector3.zero;

dirAcc.y = Input.acceleration.y*10;

if(Input.touchCount != 0){
if (leftHalf.Contains (curTouch.position)){
maxSpeed = maxSpeed*2;
}else{
if (rightHalf.Contains(curTouch.position)){
maxSpeed = maxSpeed*2;
}
}
}else{
if(Input.touchCount == 0){
maxSpeed = maxSpeedConstant;
}
}
}
}

What I’m trying to achieve is that the play is able to control the up/down movement of the character via accelerometer and right/left movement by touching the right/left side of the screen.

With the above code the touch area does not matter the character will always move backwards and accelerometer input is entirely ignored. What bothers me is that the above code (accelerometer part only) worked with transform.Translate instead of rigidbody.AddForce.
But from what I’ve read on the internet I’m going to need rigidbodies if I want collisions.

So any help or advice regarding code structure/syntax or solution towards my problem is appreciated.

I feex.
Touch curTouch;
to define the touch position I had to use a Vector2,use Input.GetTouch(0) for the if statement and now I set curTouch everytime a touch occurs.

Here is what the essential part looks like now :

public void Movement(){

//Accelerometer Control up/down
Vector3 dirAcc = Vector3.zero;

dirAcc.y = Input.acceleration.y*.5F;

transform.Translate(0F,0F,dirAcc.y);

if(Input.touchCount != 0){
Vector2 curTouch = Input.GetTouch(0).position;
if (leftHalf.Contains (curTouch)){
//transform.Translate(-Vector3.right*speed*Time.deltaTime);
transform.Translate (-moveVec*2*Time.deltaTime);
}else{
if (rightHalf.Contains(curTouch)){
//transform.Translate(Vector3.right*speed*Time.deltaTime);
transform.Translate (moveVec*2*Time.deltaTime);
}
}
}else{
if(Input.touchCount == 0){
//transform.Translate(Vector3.right*speed*Time.deltaTime);
transform.Translate (moveVec*Time.deltaTime);
}
}
}

If you want collisions, you do need a rigidbody but you do not have to make the movement based on physics. Use Translate only and add a rigidbody to the gameobject. Simple. That means that you can easily make your character move, and you will still have collisions.