- Home /
How to set mobile device position zero
Hi guys, Im just starting my adventure with c# and unity so please forgive me my lack of knowledge and messy code. I was digging through the internet for 2 days , but nothing i found worked for me. What I need is how to get device position on void start, so every time i run game, game detects phone in 0 position.`
public class Controller : MonoBehaviour {
Rigidbody rb;
float dirX;
public float moveSpeed = 10f;
// Start
void Start () {
rb = GetComponent<Rigidbody> ();
}
// Update
void Update () {
dirX = Input.acceleration.x * moveSpeed;
//limit y-axis movement for future ramps etc
transform.position = new Vector3(transform.position.x, Mathf.Clamp (transform.position.y,-99f,20f), transform.position.z);
}
// FixedUpdate
void FixedUpdate()
{
rb.velocity = new Vector3 (0, -4f, dirX);
transform.position = new Vector3(transform.position.x - 0.2f, transform.position.y, transform.position.z);
}
}
I have tried This one how to detect device start position for player acceleration (iPhone) But it didn't work for me neither(im working on android).
I will appreciate any advice and help.
Answer by megastacks_13 · Feb 13, 2020 at 09:32 AM
@VezzUK
Hi, I see you've been practising a lot with c#!! I'm going to ask you if you tried adding a button in the canvas for reseting and detecting when you press it for setting the rotation to 0. It's only a suggestion, could you tell me if it works? Don´t forget to use the UI library.
Hi, thank you. I have not tried it. the whole point is that i need it to zero without user interference. But from the other side i could try to implement that into "start" button on the every level player starts. Thank you for your suggestion, Ill make sure to update here if it will work.
Your answer
Follow this Question
Related Questions
Device acceleration problem 0 Answers
How do I access CoreMotion and the Android equivalent? 0 Answers
Gravity in unity android 1 Answer
Accelerometer works on phone until build exe 3 Answers
Face Direction of Tilting 1 Answer