okay so iam tinkering around with this…
i have a rock on top of a mountain it sits still… when you tap it you control it for 2-3 seconds,
and i want it so when i tip the tablet, the rock falls in the direction i tip the tablet,
i have it working, but the thing is, the tablet is tipped towards me for me to look at the tablet, by default,
i want my script to ignore that…
whatever orientation i have when i first tap the rock is the default, and then further tipping of the tablet is the input controls for the rock.
how do i do that?
i figure id ask here before i start trial and erroring it.
okay so these are my two codes im working with…
one is accelerometer, the other is accelerometer and gyroscope, theyre the same, but im testing which to use, at the moment ive only tried accelerometer…
but anyway, the rock falls towards me since my tablet is angled towards me to view the screen
this is the first time ive tried to implement these things, so maybe you guys have some tips/ideas?
i see theres like Input.compensateSensors and Input.gyro.userAcceleration
i guess ill have to try em out see what i can do
using UnityEngine;
using System.Collections;
public class AddForceAccello : MonoBehaviour
{
public int torqueAmt;
public int forceAmt;
public Rigidbody rb;
public bool canMove = false;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
if(canMove == true)
{
if (SystemInfo.deviceType == DeviceType.Desktop) // --desktop devices--
{
int torqueAmt = 2500;
int forceAmt = 150;
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 moveTorq = new Vector3 (moveVertical,0.0f,-moveHorizontal);
Vector3 moveForce = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddTorque(moveTorq * torqueAmt * Time.deltaTime); //* Time.deltaTime
rb.AddForce(moveForce * forceAmt * Time.deltaTime);
}
else // --mobile devices--
{
Vector3 moveTorq = new Vector3 (Input.acceleration.y, 0.0f, -Input.acceleration.x);
Vector3 moveForce = new Vector3 (Input.acceleration.x, 0.0f, Input.acceleration.y);
rb.AddTorque(moveTorq * torqueAmt); //* Time.deltaTime
rb.AddForce (moveForce * forceAmt);
}
}
}
}
using UnityEngine;
using System.Collections;
public class AddForceGyroAccello : MonoBehaviour
{
public int torqueAmt;
public int forceAmt;
public Rigidbody rb;
public bool canMove = false;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate ()
{
if(canMove == true)
{
if (SystemInfo.deviceType == DeviceType.Desktop) // --desktop devices--
{
float moveHorizontal = Input.GetAxis("Horizontal");
float moveVertical = Input.GetAxis("Vertical");
Vector3 moveTorq = new Vector3 (moveVertical,0.0f,-moveHorizontal);
Vector3 moveForce = new Vector3 (moveHorizontal, 0.0f, moveVertical);
rb.AddTorque(moveTorq * torqueAmt * Time.deltaTime); //* Time.deltaTime
rb.AddForce(moveForce * forceAmt * Time.deltaTime);
}
else // --mobile devices--
{
Vector3 moveTorq = new Vector3 (Input.gyro.rotationRate.y, 0.0f, Input.gyro.rotationRate.z);
Vector3 moveForce = new Vector3 (Input.acceleration.x, 0.0f, Input.acceleration.y);
rb.AddTorque(moveTorq * torqueAmt); //* Time.deltaTime
rb.AddForce (moveForce * forceAmt);
}
}
}
}