Search Unity

Help!!!!!!! Need to walk sideways

Discussion in 'Scripting' started by kjartanith, Jul 25, 2011.

  1. kjartanith

    kjartanith

    Joined:
    Jul 22, 2011
    Posts:
    25
    I am making my fun game and can walk forward and turn with the mouse, but i can´t use a d to walk sideways. :confused:

    Here is the script:


    //Moving around
    var speed = 3.0;
    //Shooting
    var bullitPrefab : Transform;
    //Dying
    static var dead = false;

    //function OnControllerHit(hit: ControllerColliderHit)
    function OnTriggerEnter(hit : Collider)
    {
    if(hit.gameObject.tag == "fallout")
    {
    dead = true;
    //substract life here
    HealthControl.LIVES -= 1;
    }

    if(hit.gameObject.tag == "enemyprojectile")
    {
    gothit = true;
    HealthControl.HITS += 1;
    Destroy(hit.gameObject);
    }
    }

    function Update ()
    {
    var controller : CharacterController = GetComponent(CharacterController);

    // Move forward / backward
    var forward = transform.TransformDirection(Vector3.forward);
    var curSpeed = speed * Input.GetAxis ("Vertical");
    controller.SimpleMove(forward * curSpeed);

    if(Input.GetButtonDown("Fire1"))
    {
    var bullit = Instantiate(bullitPrefab,
    transform.Find("spawnpoint").transform.position,
    Quaternion.identity);
    bullit.tag ="wormProjectile";
    bullit.rigidbody.AddForce(transform.forward * 2000);
    }

    }

    function LateUpdate()
    {
    if(dead)
    {
    transform.position = Vector3(0, 1, 0);
    gameObject.Find("Main Camera").transform.position = Vector3(0, 4, -10);
    dead = false;
    }
    }

    @script RequireComponent(CharacterController)


    Please help!!! :(
     
  2. Airmand

    Airmand

    Joined:
    Jan 27, 2011
    Posts:
    139
    transform.TransformDirection(Vector3.right;
    transform.TransformDirection(Vector3.left);
     
  3. zine92

    zine92

    Joined:
    Nov 13, 2010
    Posts:
    1,347