Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Roll-a-ball js where is the ball?

Discussion in 'Community Learning & Teaching' started by amandamontanapearce, Aug 11, 2016.

  1. amandamontanapearce

    amandamontanapearce

    Joined:
    Aug 11, 2016
    Posts:
    3
    Hi I've been going through the tutorial (though I am writing my code in js), and I think everything is working, but when I was setting up movement I rolled the ball off the plane and now it seems lost, whenever I hit play. Ideally I would like the ball to start back on the plane each time I hit play. I'm very new to Unity and don't quit understand how everything works ... but I think my ball is just falling. When I hit play and inspect the player(ball) the y position is something crazy like -2000 and growing. This has made it very hard to figure out what is working and what is not. I've considered the idea of trying to use player.transform.translate in start but to no avail. I'm not even sure if that is my issue since when I hit play the game appears to start from where it left off. Is there anyway to play the game as I'm developing it from the beginning where the ball was originally placed?
    Code (JavaScript):
    1. import UnityEngine;
    2. import System.Collections;
    3. import System;
    4.  
    5. class PlayerController extends MonoBehaviour {
    6.     var speed = 800.0;
    7.     var player : GameObject;
    8.  
    9.     function Start () {
    10.     player.transform.Translate(1,1,1);
    11.     }
    12.  
    13.     function FixedUpdate() {
    14.     var moveHorizontal : float = Input.GetAxis("Horizontal");
    15.     var moveVertical : float = Input.GetAxis("Vertical");
    16.  
    17.     var movement = Vector3(moveHorizontal, 0.0f, moveVertical);
    18.  
    19.     GetComponent.<Rigidbody>().AddForce(movement * speed * Time.deltaTime);
    20.     }
    21. }
     
  2. Deleted User

    Deleted User

    Guest

  3. amandamontanapearce

    amandamontanapearce

    Joined:
    Aug 11, 2016
    Posts:
    3
    Thank you Anne!