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 Nander · Jun 08, 2015 at 11:07 AM · inputcarsimulation

How to export the input history of a gama to a txt/excel file

Hi there,

I have a developed a car simulator for a university project, and i want to record the history of the players inputs. When the driver/player is playing, i want to be able to record the moments when he or she presses the brake/acelerator and for how long. Kinda like race telemetry, that would be cool. Do you guys have any ideas or suggestions? i dont have really a clue on how to do this.

Regards

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by mikelortega · Jun 08, 2015 at 03:49 PM

You can use System.IO.StreamWriter to write to a txt file.

For instance, you can start tweaking this code, it prints a line every time a key is pressed.

 public class LogFile : MonoBehaviour
 {
     System.IO.StreamWriter m_LogFile;
 
     void Start()
     {
         m_LogFile = new System.IO.StreamWriter(@"Log.txt");
     }
 
     void Update()
     {
         if (Input.anyKeyDown)
         {
             m_LogFile.WriteLine("Key Down in frame " + Time.frameCount);
             m_LogFile.Flush();
         }
     }
 }

Comment
Add comment · Show 7 · 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 Nander · Jun 08, 2015 at 04:26 PM 0
Share

Wow this looks simple! So i just add this script as component of the car prefab and im all set? What if i was to use a logitech steering wheel, could this measure the travel with which the user is pressing the acelerator/brakes?

thanks a lot mikelo!

avatar image mikelortega · Jun 08, 2015 at 04:39 PM 0
Share

It is not difficult to change the code to use it with a Joystick or Steering Wheel. Check Input.

Input.GetAxis("Horizontal") should give you the steering wheel position.

avatar image Nander · Jun 08, 2015 at 05:34 PM 0
Share

Wow is the code this simple? So i just have to add this code as a component of the car? Another thing, if i am adding a logitech steering wheel this would work too right? Would it also measure the intensity with which im braking/acelerating?

Thanks a lot mikelo!!!

avatar image mikelortega Nander · Jun 08, 2015 at 06:10 PM 0
Share

If the pedals are progressive you can measure the intensity. Check the Input $$anonymous$$anager to know which inputs you have to log. You have more info here.

avatar image Nander · Jun 09, 2015 at 05:42 AM 0
Share

Wow really? this looks very easy...So i just have to add this script as a component of the car prefab? Another thing, for a logitech steering wheel, is there a why to know how hard the user/player is pressing the acelerator or brakes?

Thanks a lot mikelo!

avatar image mikelortega · Jun 09, 2015 at 07:15 AM 0
Share

Yes, it is easy. Add the script to your car prefab. I recommend you to play around with the code, get your hands dirty and then ask a more specific question.

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Applying proper drag and center of mass for a vehicle 1 Answer

Help with car 2-player Input 0 Answers

Reading from Serial port with Vive (SteamVR) resulting in huge lag. 1 Answer

Input Manager can't detect a already pressed button 1 Answer

AI in a Driving Simulation 1 Answer


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