Mobile Flashcards

1
Q

Sistema de Tilt no Mobile - gyroscopy

public Rigidbody body;
private float minTilt = 5f;
private float sensitivity = 1f;
private Vector3 totalRotate = Vector3.zero;

A
public void Awake()
{
Input.gyro.enable= true;
}
private void FixedUpdate()
{
body.Addtorque(total rotate*sensitivity);
}
public void Update()
{
ZeroMovement();
}
public void ZeroMovement()
{
Vector3 rotation = Input.gyro.rotationRate*Mathf.Rad2Deg; 
if (Mathf.Abs(rotation.x)< minTilt)
{
rotation.x=0;
}
if (Mathf.Abs(rotation.y)< minTilt)
{
rotation.y=0;
}
if (Mathf.Abs(rotation.z)< minTilt)
{
rotation.z=0;
}
totalRotate += new Vector3(rotation.x,rotation.y,rotation.z)* Time.deltaTime;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Sistema do player virando p onde tilt

public Transform monkeyPivot;
private float monkeyLookSpeed = 10f;

A
public void LateUpdate()
{
if (monkeyPivot != null)
{
MonkeyFacing();
}
}
void MonkeyFacing ();
{
Vector3 velocity = body.velocity;
velocity.y= 0;
Vector3 forward = monkeyPivot.forward;
forward.y= 0;
float step = monkeyLookSpeed *Time.deltaTime;
Vector3 newFacing= Vector3.RotateTowards(forward,velocity,step,0);
monkeyPivot.rotation= Quaternion.LookRotation(newFacing);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

PlayerControl scrip

void FixedUpdate()
{
var horizontalspeed = Input.GetAxis(”Horizontal")*leftrightSpeed;
#if UNITY_STANDALONE||UNITY_WEBPLAYER||UNITY_EDITOR
horizontalspeed=Input.GetAxis("Horizontal")*leftrightSpeed;
if(Input.GetMouseButton(0))
{horizontalspeed =CalculateMovement(Input.mousePosition);
}
#elif UNITY_IOS||UNITY_ANDROID
if(Input.touchCount>0)
{Touch touch =Input.touches[0];
horizontalspeed= CalculateMovement(touch.position);
}
#endif
A
private float CalculateMovement(Vector3 pixelPos)
{
var worldPos = Camera.main.ScreenToViewportPoint(pixelPos);
float xMove= 0;
if(worldPos.x<0.5f)
{
xMove=-1;
}else
{
xMove=1;
}
return xMove *leftrightSpeed;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

PlayerControl script - Accelerometer
Eixo x, a direita positivo, eixo y, cima positivo, z, frente positivo.
public enum MobileHorizMovement
{Accelerometer,ScreenTouch}
public MobileHorizMovement horizMovement = MobileHorizMovement.Acceleremoter;

A
(Update function)
//check if we are running on a mobile device
#elif UNITY_IOS||UNITY_ANDROID
if (horizMovement == MobileHorizMovement.Accelerometer)
{//move player in direction of accelerometer
horizontalspeed = Input.accelerometer.x * leftrightSpeed;
//check if Input has registered more than zero touches
if(Input.touchCount >0)
{if (horizMovement == MobileHorizMovement.ScreenTouch)
{//store the first touch detected
Touch touch =Input.touches[0];
horizontalspeed= CalculateMovement(touch.position);
}
}
#endif
How well did you know this?
1
Not at all
2
3
4
5
Perfectly