- Home /
Simulating Marble Blast Gold: A script to make a character as a marble roll forward, mouse turns screen?
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
I think if you just want a complete script, your best bet might be to hire someone to write it for you, or try the 'Collaboration' forum and see if you can get a programmer involved in the project. Someone might be generous and post a complete script here, but that's not really what Unity Answers is geared towards. Of course if you have a specific question about how to write the script, you can always ask here or on the forums, and people will likely be more than happy to help.
Answer by JDonavan 1 · Nov 12, 2010 at 03:53 AM
You might start with the roll a ball example Unity Technologies provides... http://unity3d.com/support/resources/example-projects/iphone-examples.html
Thank you for your reply. It says iPhone, but does it work cross-platform? I'll try it out now.
For what you're looking for I imagine it's about as simple as changing which axis you're checking against.
Err... It isn't relevant at all. Sorry. I tryed to modify the script but it has nothing to do with that, only to do with rolling, no force, since it is using the tilt sensor. D:
Answer by supersm64fan · Jul 15, 2015 at 10:51 AM
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;
}
}