x


Limited tilt ojbect on pivotpoint

Hi all

I hope someone can help me out. I am struggling with a little game which i cannot get the tilt function working. The game is for android and i want to use the tilt sensor in the phone to tilt an object on it's pivot point.

This is what i have so far...

using UnityEngine;
using System.Collections;

public class TiltAround : MonoBehaviour 
{
    private Quaternion localRotation;
    public float speed = 1.0f;     

    void Start () 
    {       
       localRotation = transform.rotation;
    }

    void Update() 
    {     
       float curSpeed = Time.deltaTime * speed;

       localRotation.y += Input.acceleration.x * curSpeed;
       localRotation.x += Input.acceleration.y * curSpeed;

       transform.rotation = localRotation;
    }
}

But the object is moving anywhere but not staying at one point (the pivot) and tilting the ojbect itself. I hope someone can point me in the right direction..

more ▼

asked Mar 22 '12 at 08:21 PM

Nieniepanini gravatar image

Nieniepanini
31 6 7 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You shouldn't manipulate x, y, z, w components of quaternions. Use the functions like Euler.

more ▼

answered Mar 23 '12 at 06:16 PM

Berenger gravatar image

Berenger
11k 12 19 53

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2458
x84
x67

asked: Mar 22 '12 at 08:21 PM

Seen: 489 times

Last Updated: Mar 23 '12 at 06:16 PM