Need help replacing the ball in Roll-a-Ball tutorial game
Hi all,
I successfully finished the Roll-a-Ball tutorial and am trying to:
Replace the ball with a rectangular mesh object I made in Blender
Make the mesh object move like a boat. (with one end being the front)
I've had success making a prefab cube move the way I want, but am having a really hard time figuring out how to make the mesh object move properly.
I have tried:
adding a Rigidbody
adding the PlayerController script (from the Roll-a-Ball tutorial) to the mesh object
adding a boat movement script from an Aaron Hibbard tutorial (because I want the mesh object to move like a boat)
adding a Capsule Collider
When I press play, my mesh object sort of points forward and slowly sinks through the ground. If I change the Y axis position to 1 (to make sure it's above the plane) it flies towards the camera instead.
I'm attaching my scripts in case they're relevant. Any help with this would be greatly appreciated! Thank you!
PlayerController Script:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float speed;
public Text countText;
public Text winText;
private Rigidbody rb;
private int count;
void Start ()
{
rb = GetComponent<Rigidbody>();
count = 0;
SetCountText ();
winText.text = "";
}
void FixedUpdate ()
{
float moveHorizontal = Input.GetAxis ("Horizontal");
float moveVertical = Input.GetAxis ("Vertical");
Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddForce (movement * speed);
}
void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag ( "Pick Up"))
{
other.gameObject.SetActive (false);
count = count + 1;
SetCountText ();
}
}
void SetCountText ()
{
countText.text = "Cheese Squares: " + count.ToString ();
if (count >= 12)
{
winText.text = "You Win!";
}
}
}
Boat script
using UnityEngine;
using System.Collections;
public class boat : MonoBehaviour {
public float turnSpeed = 1000f;
public float accellerateSpeed = 1000f;
private Rigidbody rb;
// Use this for initialization
void Start ()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update ()
{
float h = Input.GetAxis("Horizontal");
float v = Input.GetAxis("Vertical");
Vector3 movement = new Vector3 (h, v, 0.0f);
rb.AddTorque(0f,h*turnSpeed*Time.deltaTime,0f);
rb.AddForce(transform.forward*v*accellerateSpeed*Time.deltaTime);
}
}