Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by tomowale · Apr 21, 2017 at 04:33 PM · collisionphysicsphysics2dcollision2dunityremote

Collision not working in APK , but works in Unity Remote?

Hey guys , I have a script attached to a car game object that allows the player to tap the screen and then accelerate , it works fine in Unity Remote , but when I download the APK , as soon as I tap the screen , collisions go completely bezerk and the car just starts ignoring collisions , what's going on? The code I think is causing the error starts at line 48 (From main forums , I didn't get any responses)

 using UnityEngine;
 using System.Collections;
  
 public class carController : MonoBehaviour {
  
     public float carSpeed;
     public float maxPos = 2.2f;
  
     Vector3 position;
     public UIManager ui;
     public AudioManager am;
     public float MaxPosY = 3.69f;
     public GameObject anim;
     bool currntPlatformAndroid = false;
     bool heldDown = true;
     Rigidbody2D rb;
  
     void Awake(){
  
         rb = GetComponent<Rigidbody2D> ();
  
         #if UNITY_ANDROID
                 currntPlatformAndroid = true;
         #else
                 currentPlatformAndroid = false;
         #endif
  
  
         am.carSound.Play ();
  
     }
  
     void Start () {
  
         position = transform.position;
  
         if (currntPlatformAndroid == true) {
             Debug.Log ("Android");
         }
         else {
             Debug.Log ("Windows");
         }
  
  
  
     }
  
     void FixedUpdate() {
         if (Input.touchCount > 0)
         {
             transform.Translate(new Vector3(0, 1, 0) * carSpeed * Time.deltaTime);
  
         }
  
         else {
             transform.Translate(new Vector3(0, -1, 0) * carSpeed * Time.deltaTime);
  
         }
     }
     void Update()
     {
  
  
         if (currntPlatformAndroid == true)
         {
             //android specific code
             //TouchMove ();
             AccelerometerMove();
         }
  
         else {
  
             position.x += Input.GetAxis("Horizontal") * carSpeed * Time.deltaTime;
             position.y = Mathf.Clamp(position.y, -4.25f, 4.25f);
             position.x = Mathf.Clamp(position.x, -2.5f, 2.5f);
  
             transform.position = position;
         }
      
         position = transform.position;
         position.y = Mathf.Clamp(position.y, -4.25f, 4.25f);
         position.x = Mathf.Clamp(position.x, -2.5f, 2.5f);
         transform.position = position;
      
  
     }
  
      
  
  
     void OnCollisionEnter2D(Collision2D col){
  
         if (col.gameObject.tag == "EnemyCar") {
             //Destroy (gameObject);
  
  
             Instantiate(anim, transform.position, transform.rotation);
             am.explosionSound.Play();
             Destroy(anim);
             Destroy(this.gameObject);
             am.carSound.Stop();
             ui.gameOverorNot();
  
  
  
  
  
         }
     }
  
     void AccelerometerMove(){
  
         float x = Input.acceleration.x;
         Debug.Log ("X = " + x);
  
  
         if (x < -0.1f) {
             MoveLeft ();
         } else if (x > 0.1f) {
             MoveRight ();  
         }
         else {
             SetVelocityZero();
         }
  
     }
  
  
     void TouchMove(){
  
         if (Input.touchCount > 0) {
  
             Touch touch = Input.GetTouch (0);
  
             float middle = Screen.width / 2;
  
             if (touch.position.x < middle && touch.phase == TouchPhase.Began) {
                 MoveLeft ();
             }
             else if (touch.position.x > middle && touch.phase == TouchPhase.Began) {
                 MoveRight ();
             }
      
         }
  
         else {
             SetVelocityZero();
         }
  
     }
  
  
     public void MoveLeft(){
         rb.velocity = new Vector2 (-carSpeed, 0);
     }
  
     public void MoveRight(){
      
         rb.velocity = new Vector2 (carSpeed, 0);
     }
  
     public void SetVelocityZero(){
         rb.velocity = Vector2.zero;
     }
  
     /*void AccelerometerMove(){
         float x = Input.acceleration.x;
      
         Debug.Log (" X: " + x);
      
         if (x < -0.1f) {
             MoveLeft ();
         } else if (x > 0.1f) {
             MoveRight ();
         }
         else {
             SetVelocityZero();
         }
      
     }*/
  
  
  
  
  
  
  
 }
  
 

The object that script is attached to has a rigidbody and a box collider , the objects it's colliding with have box colliders.

EDIT: Just tested again and even if I just use the accelerometer and not touch the screen , the gameobject still goes bezerk and starts ignoring collisions.
My game is 2D

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 tomowale · Apr 26, 2017 at 03:16 AM

Anyone? I have figured out that collision only acts up when I press the Replay button for my game on Android , but it works when the game first starts up. Why? and how do I fix. Visit here for more info https://forum.unity3d.com/threads/script-refuses-to-work-in-apk-but-works-in-unity-remote-editor.467380/

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Physics Movement without Physics Reactions 1 Answer

RigidBody becomes awake without a collision 1 Answer

Where collision matrix in unity3d 5+ ? 0 Answers

Rigidbody2D and non-trigger child colliders! 2 Answers

Car will only turn right (& ignored collders) 0 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