Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Project Roll-a-Ball "Moving the Player"

Discussion in 'Scripting' started by DeeJayVee, Jan 2, 2015.

  1. DeeJayVee

    DeeJayVee

    Joined:
    Jan 2, 2015
    Posts:
    121
    Hey how are ya, I'm following the unity provided tutorial on making the Roll-a-Ball game, and I'm up to the part "Moving the Player" where you use a c# code. I've gone over this a few times, and from what I can tell, the code is the exact same.

    I started a new project and followed everything exactly (Or so I hope).

    When I apply this code to my Player object, instead of moving around like it does in the video, my "Player" moves above the plane, and stops, I can't move it and it doesn't move after that.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PlayerController : MonoBehaviour
    5. {
    6.  
    7.     void FixedUpate()
    8.     {
    9.         float moveHorizontal = Input.GetAxis("Horizontal");
    10.         float moveVertical = Input.GetAxis("Vertical");
    11.  
    12.         Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    13.  
    14.         rigidbody.AddForce(movement);
    15.     }
    16.  
    17. }
    18.  
    Edit: I realized that if I took off "Convex" from the plane that the ball would not raise and instead would stay on the plane. I still don't have a moving ball, this is confusing me now. it now drops from Y - 0.5 to 0.48..


    The tutorial which is located here; http://unity3d.com/learn/tutorials/projects/roll-a-ball/moving-the-player

    Says that it was 'checked' with version 4.0 and I have version 4.6.1 would that make a difference? I assume not, but I'm just learning so I don't really know
     
    Last edited: Jan 2, 2015
  2. REV-FX

    REV-FX

    Joined:
    Oct 24, 2013
    Posts:
    28
    I guess the applied force is just to lower to have any visual effect on your game object. The max value of Input.GetAxis calls is 1 only so you might want to add a multiplier to it.
     
  3. DeeJayVee

    DeeJayVee

    Joined:
    Jan 2, 2015
    Posts:
    121
    Thanks for your reply,
    Do you mean like this;

    Code (CSharp):
    1. float moveHorizontal = Input.GetAxis("Horizontal") * 10;
    2.         float moveVertical = Input.GetAxis("Vertical") * 10;
    3.  
    Or like this;

    Code (CSharp):
    1. Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical) * 10;
    If so, that hasn't made a change

    if not, please explain

    EDIT: Also, when trying to move the 'Player' no axis changes, x/y/z stay in the exact same position, so It's not moving the 'Player' at all
     
    Last edited: Jan 2, 2015
  4. DeeJayVee

    DeeJayVee

    Joined:
    Jan 2, 2015
    Posts:
    121
    My non scripting - tech retarded girlfriend has just figured out my problem, other then having upDate i had upate. Thanks for your help.
     
  5. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    An easy way to solve that problem is to print at the top of the function "line reached" (or whatever) to tell you a function is indeed being called. A very common error to make is misspelling a built in function so it doesn't run or making your own function but not actually calling it anywhere.
     
  6. DeeJayVee

    DeeJayVee

    Joined:
    Jan 2, 2015
    Posts:
    121
    Awesome, I'm about to start learning their next tutorial, the Survival Shooter, this will come in handy, thank you