Hello! I a big noob to Unity and scripting. I would like to make a game such as Marble Blast Gold, where the character is a marble (a ball). The marble should move forward and backwards with the A and S keys, and left and right with the A and D keys (this means roll, not move, I already have a script for movement). The space bar should also make the marble jump a defined amount each time the space bar is hit, where a tap and a long hold should be the same height, and holding space will let you jump multiple times. I know how to use the smooth follow on the camera on the marble, but the mouse needs to turn the point of view, affecting where forward is. Also I need the up and down keys to move the height angle from side/up to top, having a limit of directly on top and around 45 degrees. I would really appreciate it if there could be a traction/slip variable to define. I am sorry that I am asking for a whole script, but I am very bad at scripting. This would help me and others learn more about it, but I am also very open to any suggestions, too. [I am going to add a bounty to this tomorrow, but apparently it has to be 3+ days to do so, so bear with me until then. Answering it today would be helpful and I can mark the answer describing all things mentioned here with the bounty points tomorrow.] Thank you! -Keavon
You might start with the roll a ball example Unity Technologies provides... http://unity3d.com/support/resources/example-projects/iphone-examples.html
This is what I use for movement.
using UnityEngine;
using System.Collections;
public class MarbleControl : MonoBehaviour {
public float movementSpeed = 6.0f;
void Update () {
Vector3 movement = (Input.GetAxis("Horizontal") * -Vector3.left * movementSpeed) + (Input.GetAxis("Vertical") * Vector3.forward *movementSpeed);
movement *= Time.deltaTime;
GetComponent<Rigidbody>().AddForce(movement, ForceMode.Force);
}
void OnTriggerEnter (Collider other ) {
if (other.tag == "Pickup")
{
MarbleGameManager.SP.FoundGem();
Destroy(other.gameObject);
}
else
{
//Other collider.. See other.tag and other.name
}
}
}
Here is a jump script.
using UnityEngine;
using System.Collections;
public class JumpScript : MonoBehaviour
{
public float jumpForce;
private float jumpHeight;
private bool isGrounded ;
private Vector3 jump;
void Update()
{
jumpHeight = Input.GetAxis("Jump");
jump = new Vector3(0.0f, jumpHeight, 0.0f);
if(Input.GetButtonDown("Jump") && isGrounded)
{
GetComponent<Rigidbody>().AddForce(jump * jumpForce, ForceMode.Impulse);
isGrounded = false;
}
}
void OnCollisionEnter()
{
isGrounded = true;
}
}