Search Unity

Accelerometer input, Is Kinematic and OnCollisionenter

Discussion in 'Physics' started by RHD, Aug 28, 2016.

  1. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    Hi,

    I'm not a coder, I'm from the Art side, so please be patient.

    I'm trying to use the accelerometer on IOS to steer a ship, this only works with the script I'm using if I have "is Kinematic" checked which I have verified from the documents.

    The problem then becomes how to get it to crash when it hits things because OnCollisionEnter doesn't work with "Is Kinematic".

    This is the C# script I have for the Accelerometer:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class AccelerometerInput : MonoBehaviour {
    4.      // Use this for initialization
    5.      void Update () {
    6.          transform.Translate(Vector3.forward * Time.deltaTime);
    7.          transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z);
    8.          }
    9.  
    10. }
    and this is the JS script for the collisions:

    Code (JavaScript):
    1.  #pragma strict
    2. function Start () {
    3.    // Plays the reload animation - stops all other animations
    4.   animation.Play("Fly fast", PlayMode.StopAll);
    5.  
    6.   }
    7.  
    8. function OnCollisionEnter(col : Collision)
    9. {
    10. if(col.gameObject.name == "Bat_Death")
    11. {
    12. animation.wrapMode = WrapMode.Once;
    13. animation.Play("Death", PlayMode.StopAll);
    14. yield WaitForSeconds (.8);
    15. Application.LoadLevel("StartWindow");
    16. //audio.PlayOneShot(AudioClip);
    17. }
    18. }

    Weirdly it seemed to work for a while, but I have no idea why and I do gather it isn't supposed to.

    It certainly isn't now.

    What is the simplest way to steer the ship with the accelerometer on an IOS device and still have the ship hit obstacles?

    Thank you.
     
  2. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    1: Why are you mixing JS and C#? Just do everything in C#.
    2: Why are you using a rigidbody as kinematic? Do you even know what kinematic means? : http://docs.unity3d.com/Manual/class-Rigidbody.html

    Doc says:
    Animation
    For some situations, mainly creating ragdoll effects, it is neccessary to switch control of the object between animations and physics. For this purpose Rigidbodies can be marked isKinematic. While the Rigidbody is marked isKinematic, it will not be affected by collisions, forces, or any other part of the physics system. This means that you will have to control the object by manipulating the Transform component directly. Kinematic Rigidbodies will affect other objects, but they themselves will not be affected by physics. For example, Joints which are attached to Kinematic objects will constrain any other Rigidbodies attached to them and Kinematic Rigidbodies will affect other Rigidbodies through collisions.

    So I have no idea why you're using a kinematic Rigidbody :confused:
     
  3. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    1: Did you miss the bit where I said I'm not a coder?
    I'm using C# but the only script I've found that I could understand and adapt to do what I wanted in that case was in JS.
    2: That's what the Unity tutorial said to do.
    I have read that doc and it just made me even more confused.

    However, after reloading the whole project in a new version it is all working fine.
    I don't understand why or why it stopped working last time.
    I'm just making a lot of backups before I change things.

    I needed a rigidbody to collide with things.

    My accelerometer script kept sending the player all over the place when isKinematic was not ticked.
    Now in the new project it is working fine without is kinematic being ticked.
    I have no idea what is different.
     
  4. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    Well, if you can't write C# scripts you're going to have a very hard time making games in Unity3D... I recommend you invest the time to learn the basics of C#. I'm not a great coder myself, but once you understand the language you can just look in the docs and see what you need to do. There really is no point trying to make games in Unity3D if you don't have a basic knowledge of C# (unless you work in a team with a programmer).
     
  5. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    My paid for versions of Unity date from before they used C# so if that is the case maybe you can organise a refund for me.

    On the courses front, do post some links.
    Thank you.
     
  6. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    I started using Unity Pro in 2009.

    In those days when you asked for help on the forum people actually tried to help you.
    Now they just laugh at your ignorance.

    Not sure it's an improvement.

    I've done several projects in Unity a few years ago but I haven't used it in four or five years.

    I'm not being inspired to upgrade to 5 as it appears there is no support at all anymore.
     
  7. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    Yes, the forums can be really harsh sometimes if you don't know exactly what you're doing.

    I'd definitely upgrade to Unity 5. If anything there are more people ready to help with Unity 5 than 4.

    Did you try: https://unity3d.com/learn/tutorials
     
  8. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    Thank you.
    I have been doing nothing but tutorials from that link for the past two weeks.

    Huge progress has actually been made.
    I have got a very simple game framework going and it works.
    I just have to get a scoring system that crosses levels sorted out and I'm sorted.

    That was until I tried to build it to my iPhone.

    208 Xcode errors for the Unity Editor.
    None of which seem to relate to any of my scripts or Assets, they are things I've never seen before.

    Not really included to throw good money after bad by upgrading to 5 after this never mind having to relearn for the third time the ever changing Unity interface at this point.
     
  9. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    But thanks DroidifyDevs.
     
  10. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    ...and now, for absolutely no reason that I can find as I haven't done anything differently, the Xcode build worked and the game is on my phone.
    No idea what happened to the 208 errors.
    Baffling.

    But a sort of success.
     
  11. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    I don't have OSX (I have an emulator though). Why not try to build for Android first?
     
  12. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    I don't have an Android device.

    Just redone exactly the same process as before and all 208 of Unity's fatal errors are back.
     
  13. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    Ouch, I don't know anything about iOS deveopment. You're on a Mac right? I'm on PC so I don't do iOS (greedy Apple :().

    You can get an Android emulator such as Droid4X or Bluestacks.
     
  14. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    I redid the exact same thing four times and on the fourth the errors were gone again.
    It's this inconsistency with things that throws me.

    Yes I'm on a Mac.
    Thank you for the Android advice, I shall look into Driod4X and Bluestacks.

    In the meantime I'm going to get this wretched IOS game on the App Store if it kills everyone!

    Thank you for your advice.
     
  15. DroidifyDevs

    DroidifyDevs

    Joined:
    Jun 24, 2015
    Posts:
    1,724
    Glad to see things worked out! Looks like Macs aren't as error-free as Apple claims they are :eek:
    Also I forgot that I do have a virtual machine running El Capitan (the latest OSX I think, before Sierra). Don't even know why I have it since I never used it.

    Once you get your app published I highly recommend upgrading to the latest version of Unity. You're missing out on so much!
     
  16. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    Thank you but the truth is I simply can't face starting all over again with a completely new Unity interface and coding system for the fourth time.