Hi, me and my friend have been assigned to make a game for school and we decided to make a car game.
I chose to do the scripting and it havent turned out so well.
Instead i got a script from a friend and modifyed it a little.
As you see in the video the car starts to fly almost as soon as it touches a wall from about a 45° angle
(also very laggy colissions).
According to him it has something to do that the car has a rigid body,
but the scipt is not meant to work with rigid bodies. He said that i should use some code that make
the ridgid body get a push forward instead of the car (if i remember right).
I dont know what you need for info so im just gonna put some here.
video: http://www.youtube.com/watch?v=DgZed6AeRmU&feature=youtube_gdata
The car setup:
Car (with rigid body and car script)
–colission mesh (with mesh collider(smooth sphere collisions, convex)
–visual body
–tires
----all tires here(with wheel collider)
All the boxes(houses) have a unedited mesh collider attatched to them.
Code:
private var speed = 0.0;
private var turning = 0.0;
var acceleration = 0.2;
var autobreak = 0.99;
var max_turn = 65.0;
var turning_speed = 2.5;
var turn_friction = 0.96;
private var drift = 0.0;
var drift_amount = 12.5;
var min_drift_speed = 15.0;
var max_speed = 50;
function Update () {
// Debug.DrawRay(transform.position, -up * 5, Color.green);
//if(Physics.Raycast(transform.position, -up, 5)){
//}
var up = transform.TransformDirection(Vector3.up);
/*MOVING FORWARD*/
if (Input.GetButton("Vertical") speed < max_speed) {
if(Physics.Raycast(transform.position, -up, 8)){
speed += acceleration*Input.GetAxis("Vertical");
}}
else {
if(speed != 0) {
speed *= autobreak;
}
}
gameObject.transform.Translate(drift,0,speed * Time.deltaTime);
/*TURNING*/
if (Input.GetButton("Horizontal") turning < max_turn turning > -max_turn) {
turning += turning_speed*Input.GetAxis("Horizontal");
}
else {
if(turning != 0) {
turning*= turn_friction;
}
}
gameObject.transform.Rotate(0,drift*drift_amount+turning*speed/8*Time.deltaTime,0);
/*Drifting*/
if(speed > min_drift_speed) {
drift = -0.1*(speed-min_drift_speed)*turning/500;
}
else {
drift = 0;
}
if(speed > -0.01 speed < 0.01) {
speed = 0;
}
}
Any help would be usefull.