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 Padawan94 · Mar 30, 2012 at 01:24 PM · androidgamecarnewbie

Problem with jcar script for android mobile

Hello everybody :D I have again some problem's with some scripting :( So my problem is what i use is (ctrl-j) jcar script . But i can't make it so that i want to don't use the accelerometer for acclerating and for reverse . I want instead (accelerometer) to press a certain button (like gas,brake pedal etc..) But i want to have steering with accelerometer so steering don't need editing :)

 using UnityEngine;
 using System.Collections;
 
 public class JControlledCar : JCar {
     
     // automatic, if true car shifts automatically up/down
     public bool automatic = true;
 
     public float shiftDownRPM = 1500.0f; // rpm script will shift gear down
     public float shiftUpRPM = 2700.0f; // rpm script will shift gear up
 
     void Update() {
         if (Input.GetKeyDown("page up")) {
             ShiftUp();
         }
         if (Input.GetKeyDown("page down")) {
             ShiftDown();
         }
         if (Input.GetKeyDown("g")) {
             automatic = !automatic;
         }
         if (Input.GetKeyDown("t")) {
             switch (wheelDrive) {
                 case JWheelType.Front : wheelDrive = JWheelType.All; break;
                 case JWheelType.Back : wheelDrive = JWheelType.Front; break;
                 case JWheelType.All : wheelDrive = JWheelType.Back; break;
             }
             foreach (WheelData w in wheels) {
                 WheelCollider col = w.col;
                 col.motorTorque = 0f;
                 col.brakeTorque = 0f;
             }
         }
     }
 
     
     // handle the physics of the engine
     void FixedUpdate () {
         
         float steer = 0; // steering -1.0 .. 1.0
         float accel = 0; // accelerating -1.0 .. 1.0
         bool brake = false; // braking (true is brake)
         
 //        if ((checkForActive == null) || checkForActive.active) {
 //            // we only look at input when the object we monitor is
 //            // active (or we aren't monitoring an object).
 //            steer = Input.GetAxis("Horizontal");
 //            accel = Input.GetAxis("Vertical");
 //            brake = Input.GetButton("Jump");
 //        }
         if ((checkForActive == null) || checkForActive.active) {
             // we only look at input when the object we monitor is
             // active (or we aren't monitoring an object).
 
             // don't know if I guessed the right axi (what's plural for axis?) here
             // now you have to hold the iphone more or less flat and move from there
             // just experiment with it, for really good control you maybe have to look
             // for something more advanced like averaging the samples to get less
             // jitter and stuff.
             steer = -Input.acceleration.y;
             accel = Mathf.Clamp(4f * (-Input.acceleration.z -0.5f), -1f, 1f);
 // Debug.Log("v = " + iPhoneInput.acceleration + " accel = " + accel);
             // for brake I only check if there is a touch started or going on
             for (int i = 0; i < Input.touchCount; i++) {
                 Touch touch = Input.GetTouch(i);
                 if ((touch.phase != TouchPhase.Ended) && (touch.phase != TouchPhase.Ended)) {
                     brake = true;
                 }
             }
         }
         
         // handle automatic shifting
         if (automatic && (CurrentGear == 1) && (accel < 0.0f)) {
             ShiftDown(); // reverse
         }
         else if (automatic && (CurrentGear == 0) && (accel > 0.0f)) {
             ShiftUp(); // go from reverse to first gear
         }
         else if (automatic && (MotorRPM > shiftUpRPM) && (accel > 0.0f)) {
             ShiftUp(); // shift up
         }
         else if (automatic && (MotorRPM < shiftDownRPM) && (CurrentGear > 1)) {
             ShiftDown(); // shift down
         }
         if (automatic && (CurrentGear == 0)) {
             accel = - accel; // in automatic mode we need to hold arrow down for reverse
         }
         if (brake) {
             accel = -1f;
         }
         
         HandleMotor(steer, accel);
     }
 }

I hope that it's everything is clear .

I really hope that some one can help me :)

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
0

Answer by darkcaptain · May 16, 2014 at 07:56 AM

Hi all, My english little bad, sorry. I have same problem. any body help me.please. because I dont know how can I make for android

Comment
Add comment · 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

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

Multiple Cars not working 1 Answer

Problem with acclerometer 0 Answers

Porting Unity Game to Android 1 Answer

How to control a car using joystick 1 Answer

another android dpi question... 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