1
\$\begingroup\$

I have a script attached to a car game object that allows the player to tap the screen and then accelerate, the game object has a RB2D and collider set to it , 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? As I need this to work to complete my game , as the player can move side to side with the accelerometer but I also want them to move forward when they touch the screen. Also , my game is 2D. Plus , since then , when the car ( my object) collides with anything else in the scene , it ignores it ( the obstacles just have Box Colliders on them). I had to freeze rotation so it could stop spinning out when it hit soemthing , now it just won't recognize collision at all. What's going on? The code I think is causing the error starts at line 32. I have obstacles the player has to dodge and they all have box colliders and an appropiate script attached to them as well ( so when they collide with my player , it destroys it)

I've figured it out , Collision works when I first start the game , but when the player dies and I press "Replay" , it goes crazy. Here's the script that controls the enemy cars spawning , what the hell do I do to fix this?

 Code (CSharp):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnemyCar : MonoBehaviour {
public float speed ;
public float acceleration = 0.5f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
    speed += Time.deltaTime * acceleration;
    transform.Translate(new Vector3(0, 1, 0) * speed * Time.deltaTime);
 
}
void OnCollisionEnter2D(Collision2D col)
{
    if (col.gameObject.tag == "Coin")
    {
        Destroy(col.gameObject);
    }
}
}
 

I've done everything in the book trying to solve this , re-install unity , add different colliders etc. What's weirder is that it is FLAWLESS in Unity Remote and the Editor , these issues only arise when I test out the apk.

Here's how my game usually looks when the collisions work. enter image description here

Now when it collides with a car ( on android) , it just ignores it and is slightly pushed back.

Help me!

Here is my script attached to enemy cars ( the cars that should destroy the player on Collision)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyCar : MonoBehaviour {
    public float speed ;
    public float acceleration = 0.5f;
	// Use this for initialization
	void Start () {
 
    }

    // Update is called once per frame
    void Update () {
        speed += Time.deltaTime * acceleration;

        transform.Translate(new Vector3(0, 1, 0) * speed * Time.deltaTime);
		
	}
    void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "Coin")
        {
            Destroy(col.gameObject);
        }
    }
}

Also here is the inspector view of my Player Car enter image description here

enter image description here

Here is the inspector view of an enemy car ( they all have the same things) enter image description here

\$\endgroup\$
-1
\$\begingroup\$

currentPlatformAndroid is misspelled right at the top of the file, inside the #IF.

\$\endgroup\$
  • \$\begingroup\$ Just changed it , still causes the error sadly. \$\endgroup\$ – tomowale Apr 23 '17 at 18:50
  • \$\begingroup\$ I updated the code at the top of the post , it's the Replay button \$\endgroup\$ – tomowale Apr 25 '17 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.