Search Unity

Roll-A-Ball Speed will not show under "PlayerController" script

Discussion in 'Editor & General Support' started by unity_BmFFV4qGhePyjA, Sep 23, 2017.

  1. unity_BmFFV4qGhePyjA

    unity_BmFFV4qGhePyjA

    Joined:
    Sep 23, 2017
    Posts:
    5
    My Roll-A-Ball Speed will not show up under my "PlayerController script" the way the tutorial did. I followed directions exactly the way the tutorial showed and it says next to " rb.AddForce (movement = speed);":
    "cannot implicitly convert type 'float' to 'UnityEngine.Vector3'

    PLEASE HELP!!!

    code i have currently below:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerController : MonoBehaviour {

    public float speed;

    private Rigidbody rb;

    void Start ()
    {
    rb = GetComponent<Rigidbody> ();
    }

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

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

    rb.AddForce (movement = speed);
    }
    }
     

    Attached Files:

  2. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    Change 2 lines to this:
    Code (CSharp):
    1. Vector3 movement = new Vector3 (moveHorizontal * speed, 0.0f, moveVertical * speed);
    2. rb.AddForce (movement);
    Also, next time, please post in the scripting section and use the "Insert Code" button.
     
  3. unity_BmFFV4qGhePyjA

    unity_BmFFV4qGhePyjA

    Joined:
    Sep 23, 2017
    Posts:
    5
    Thank you for your fast response!
     
  4. unity_BmFFV4qGhePyjA

    unity_BmFFV4qGhePyjA

    Joined:
    Sep 23, 2017
    Posts:
    5
    After fixing the code my ball just rolls off the board, could you tell me what would fix this issue?
     
  5. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    unity_BmFFV4qGhePyjA likes this.
  6. viesignlanguage

    viesignlanguage

    Joined:
    Sep 25, 2017
    Posts:
    1
    I have the same problem: when I tried to start moving the ball, it falls down along Y axis instead of going around on the ground. Someone told me that I should add rigidbody and collider to both them to add the physics. I don't know how to do since I am new at the Unity. Could you explain what it means?
     
  7. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    If you do the tutorial step-by-step, everything will work fine.

    To add a component, click on an object, and in the Inspector, use the Add Component button to add a collider and/or rigidbody.
     
    unity_BmFFV4qGhePyjA likes this.
  8. hvarma

    hvarma

    Joined:
    Nov 28, 2017
    Posts:
    4
    can anyone send me the corect set of script
     
  9. hvarma

    hvarma

    Joined:
    Nov 28, 2017
    Posts:
    4
    my script dosent work