Search Unity

Roll A Ball not working - any help is appreciated

Discussion in 'Getting Started' started by vmadev, Dec 16, 2015.

  1. vmadev

    vmadev

    Joined:
    Dec 16, 2015
    Posts:
    5
    The code is here

    using UnityEngine;
    using UnityEngine.UI;
    using System.Collections;

    public class PlayerController : MonoBehaviour {
    public float speed=10;
    //private CharacterController cc;
    private Rigidbody rb;

    void Start ()
    {
    rb=GetComponent<Rigidbody>();
    // cc = GetComponent<CharacterController>();

    }

    void FixedUpdate ()
    {
    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");

    Debug.Log("I am alive and H : " + moveHorizontal);

    Debug.Log("I am alive and V : " + moveVertical);


    Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);


    //speed value is set to 10 in the inspector
    rb.AddForce(movement * speed);

    //cc.Move(movement*speed);

    }
    }

    Scenario 1:
    Rigidbody : Doesnt't work

    Scenario 2:
    When I added CharacterController instead and unchecked Rigidbody it works fine but speed is not shown in the CharacterCountroller in inspector for the Player

    Scenario 3
    With rb uncommented and cc commented out and if CharacterController is still selected along with Rigidbody it still works.

    Any help is appreciated