- Home /
Car Game For School Project
So I'm making a car game with my friends for a school project, and if you want and or need to respawn I was thinking of doing so that when you press "K" you respawn at wanted location and in the right direction. I've gotten the position right so that it should spawn where I wanted, but I can't get the direction script to work. So my question is, where am i going wrong with the rotation lines and as I'm using "this", will do the things to the car if I attatch the script to it. I'm using the public variables so that I can edit them easily w/o opening mono. I'm no pro so don't judge please :)
public class BilKeyRespawn : MonoBehaviour {
public float x;
public float y;
public float z;
public float a;
public float b;
public float c;
void Update() {
if (Input.GetKeyDown (KeyCode.K))
this.transform.position = new Vector3 (x,y,z);
this.transform.rotate = new Vector3 (a,b,c);
}
}
Answer by fafase · Dec 18, 2013 at 02:37 PM
Best would be to have empty game objects at spawn point. This way you can orientate them as you need and use that rotation.
Could you explain how that would be done? I'm still not good at this, I've never done it before.
It seems you had your pb fixed but there it goes. Car games often have loads of empty game objects and trigger boxes all over the tracks. Those helps to define the order of the racers, if a racer is not using illegal shortcuts, respawning when falling off the track (if possible).
Let'say your track is pretty short and only have 10 waypoints. Those are empty game objects placed on the track with trigger box collider that takes the width of the track. the next waypoint is the target of your player and the distance with it defines your rank compared to other racers.
Racer1 is at wp2 distance 5m
Racer2 is at wp3 distance 6m
Racer3 is at wp4 distance 9m
You are at wp3 distance 7m
The order is Racer3, Racer2, Player and last Racer1
Also, those waypoints can be used for tha AI of the racers, the next waypoint is their target they are driving towards. Then you apply some randomization (Behaviour AI) so that they don't all take the same path at the same speed.
Answer by GameVortex · Dec 18, 2013 at 02:47 PM
This will not compile. You are probably getting some errors in the console.
transform.Rotate is a function and not a variable, so you can not set it to be a Vector3.
transform.rotation is a variable of type Quaternion so you can not set that to a Vector3 either.
You are probably looking for transform.eulerAngles which is the Vector3 rotation of the GameObject:
this.transform.eulerAngles = new Vector3 (a,b,c);
Your answer
Follow this Question
Related Questions
restart a scene 1 Answer
Reset Lives Object 0 Answers
How do I add a replay buttom in my game? 1 Answer
Unity 5: PlayerPrefs/Application data resets Graphics on Android device 0 Answers
Need help getting the screen to fade. 2 Answers