Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Axxorxd · Dec 18, 2013 at 02:36 PM · restart game

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);
     
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Axxorxd · Dec 18, 2013 at 02:41 PM 0
Share

Could you explain how that would be done? I'm still not good at this, I've never done it before.

avatar image fafase · Dec 19, 2013 at 08:09 AM 0
Share

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.

avatar image
0

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);
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Axxorxd · Dec 18, 2013 at 02:54 PM 0
Share

Thanks, that worked.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges