this allows my character to flip when it travels in the opposite direction and correctly cycle through the animations.
It works perfectly on my laptop but I’m making this game for android and when I run this on my Kindle, obviously the left and right arrow keys wont work on there.
I basically want to know how I can implement tilt controls to this code so I works on my kindle.
I’m new to c#, I got this code from a live training session by the unity developers.
I have this snippet of code which allows tilt controls to work but when I use this the animation the flip and walk cycle don’t work.
transform.Translate(Input.acceleration.x * Time.deltaTime,0,
-Input.acceleration.z * Time.deltaTime);
You shouldn’t move a rigidbody(2D) using transform.Translate().
I suggest you save whatever axis you need of the accelerometer to float move in Update() and apply it in fixed update using rigidbody2D.AddForce() or by directly manipulating the velocity of the rigidbody2D.
I’d guess that Flip() and the animation don’t work because they are relying on the move variable which you are not assigning anything to except key input from A D or LeftArrow RightArrow. This is easily fixed if you save the accelerometer data into the move var as stated above.
I changed float move= Input.GetAxis (“Horizontal”); to float move= Input.acceleration.x; and it worked just how I wanted.
Is my method of doing this inefficient as it is now?
My main goal was to just get it working but obviously if its and easy fix (remember i’m new to c#) than I might as well make it the best I can.
Also, where are the commands to use the left and right arrow (or A and D) in this code? I got this script from the unity live training and was surprised when the keys made the player move as I couldn’t see anywhere where the keys had been assigned.