- Home /
Snowmobile script (being able to drive it)
Okay, apparently I've been working on a "Snowmobile Simulator", creating maps, creating my snowmobiles for weeks. I actually found this car tutorial on the asset store, I've tried by changing the scripts in order to make it work for my project, I've never managed to get that working. If you look at other games like Modern Warfare 2, whenever you're escaping the cliff hanger, you do make your way to the extraction point with a snowmobile, this actually gave me an idea making my own snowmobile game on Unity. I have my colliders ready up, just need the scripts in order to make it work.
Also, before I end it here, here's a few screenshots of my snowmobile:
I know this sounds complicated, but I would really appreciate it if you guys could make me a script for my snowmobile :)
Thanks!
Answer by RetepTrun · Dec 15, 2013 at 03:40 AM
I would make it a 3 wheeled car that looks like a snowmobile. 2wheels really close together at teh back and 1 for each ski at the front. And add some white particicles to the treds
And to start I would follow a car tutorial. http://www.youtube.com/channel/UC3H-n_qgipIYB5bJKjlKUIg
I've checked their channel, is it the Car AI tutorial or is it the "How to make a Car game"?
How to make a car game. Then the other for bots if you want
This.
I'd like to add that what will make it feel like a snowmobile is careful adjustment of the sideways friction vs. forward friction, having different friction curves for the tread and the skis, and adjusting them based on the ground slope and your turning and momentum. How it loses control in extreme situations is where the interesting stuff happens with any simulated vehicle.
Asking someone to make a script for you to make your snowmobile work is not reasonable. If you're making a snowmobile game, the way it handles like a real snowmobile is the whole meat of the game; and if that's beyond your abilities, take on a simpler game (a 2d puzzle or retro shooter for example) that you know how to do, while you improve your scripting abilities.
I understand you $$anonymous$$ilo, but I'm not just going to be driving my snowmobile for all the time, here's a few other things I might add during the future:
NPCs (bots that follow you or goes anywhere)
Different game mode types
$$anonymous$$aybe multiplayer (I'm very far from that now, might be added)
In fact, I know a few things in scripts. Still far ahead to know all the commands, maybe I'll be creating my own scripts with the new Unity page (Learn) and might be able to get around my project.
Wheelies and flipping over are like the most common thing. You can try making the snowmobile heavier and lower center of mass and adjust engine power in fwd direction. You have to adjust things a hundred times before you find settings you like. Hardly anything in unity is going to work right the first time where you just go model+script_I_may_not_understand=game. Have to customize stuff to make them work together.
You could try the lazy way to keep it simple. 2 box colliders for skis, put some capsule colliders sideways to be the treads, a script with transform.rotate(0,input,0) to spin them around. Voila-powered sled.
Answer by jabez · Dec 15, 2013 at 04:49 AM
Add a rigid body to your snow mobile Set Rigid body drag settings to 1 add this script to your snow mobile http://pastebin.com/gfxNwQEd
using UnityEngine;
using System.Collections;
public class SnowMobileController : MonoBehaviour {
public float force = 20;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
// You may have to change rigidbody.AddForce(Vector3.back*force) to the opposite so vector3.back will end up vector3.forward
if(Input.GetKeyDown("s")){
rigidbody.AddForce(Vector3.back*force);
if(Input.GetKeyDown("w")){
rigidbody.AddForce(Vector3.forward*force);
}
if(Input.GetKeyDown("a")){
rigidbody.AddForce(Vector3.right*force);
}
if(Input.GetKeyDown("d")){
rigidbody.AddForce(Vector3.left*force);
}
}}}
if you want animations will have to add animation.play under the keystroke for animations, ex.
if(Input.GetKeyDown("s")){
rigidbody.AddForce(Vector3.back*force);
animation.Play("snowmobileforward");
Or if you want the wheel of the snowmobile to rotate add
public gameobject Wheel1;
public gameobject Wheel2;
public gameobject Wheel3;
to the declaration of the script &
if(Input.GetKeyDown("s")){
rigidbody.AddForce(Vector3.back*force);
Wheel1.transform.Rotate(Vector3.Forward * Time.deltaTime);
Wheel2.transform.Rotate(Vector3.Forward * Time.deltaTime);
Wheel3.transform.Rotate(Vector3.Forward * Time.deltaTime);
}
Umm... $$anonymous$$y snowmobile isn't moving at all, except when I press the "S" key, it only shakes and won't move.
adjust the force on the script to like 2000 just too see if it works, also check there's no colliders blocking it, you may have to change Vector3.back to like Vector3.up, depends what rotation your model is on. make sure there's a rigid body connected to it tou.
try this i forget too add a {
using UnityEngine; using System.Collections;
public class Snow$$anonymous$$obileController : $$anonymous$$onoBehaviour { public float force = 20;
void Update () {
// You may have to change rigidbody.AddForce(Vector3.back*force) to the opposite so vector3.back will end up vector3.forward
if(Input.Get$$anonymous$$eyDown("s")){
rigidbody.AddForce(Vector3.back*force);
}
if(Input.Get$$anonymous$$eyDown("w")){
rigidbody.AddForce(Vector3.forward*force);
}
if(Input.Get$$anonymous$$eyDown("a")){
rigidbody.AddForce(Vector3.right*force);
}
if(Input.Get$$anonymous$$eyDown("d")){
rigidbody.AddForce(Vector3.left*force);
}
}}