Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by tenthplanet0 · Jun 17, 2013 at 02:20 PM · devicetranslationgyro

tilt function for moving the character left and right

hi developers,

I want help regarding the tilt functionality. Please help me as I am stuck in this from last few days. I am trying to move my character left and right (similar to temple run 2). The thing is that I am moving my character totally on spline except in y-axis. I am using the concept of iTween spline. Now I am stuck in translating my character on x-axis. As I am using the concept of iTween spline (putonpath()) i need to move the waypoints towards right and left based on tilt. I am working on the curved path thats why i need the concept of spline. For moving my waypoints left and right I am using the following code.

using UnityEngine; using System.Collections; using System;

public class WayPoint : MonoBehaviour {

 bool gyroBool;
 GameObject distanceChecker;
 
 Gyroscope gyro;
 
 int nameNo=0, transValue = 30, objNameLength, lengthDiff;
 string objName, defName = "waypoint", appendName = null;
 
 void Awake() {
     
     parentScript = transform.parent.GetComponent();
     rootScript = transform.root.GetComponent();
     
     objName = name;
     objNameLength = objName.Length;
     
     if(objNameLength>defName.Length) {
         lengthDiff = objNameLength-defName.Length;
         
         for(int i =  defName.Length; i=0 && xPos<=30) {
     }
     else
     if(xPos>30 && xPos<=180) {
         xPos = 30;
     }
     else
     if(xPos>=330) {
         xPos = xPos - 360;
     }
     else
     if(xPos<330 && xPos>180) {
         xPos = 330;
     }
     else
         return;
     
     float xValue = fraction * xPos;
     
     requiredPosition = distanceChecker.transform.TransformPoint(Vector3.right * xValue);
     transform.position = requiredPosition;
 }

}

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tenthplanet0 · Jun 18, 2013 at 04:48 AM 0
Share

much of my code is getting deleted automatically in between.... sorry..... some problem is going on here for posting the code

avatar image tenthplanet0 · Jun 18, 2013 at 05:34 AM 0
Share

Again I am posting my code

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class WayPoint : $$anonymous$$onoBehaviour {
     
     bool gyroBool;
     GameObject distanceChecker;
     
     Gyroscope gyro;
     
     int nameNo=0, transValue = 30, objNameLength, lengthDiff;
     string objName, defName = "waypoint", appendName = null;
     
     void Awake() {
         
         objName = name;
         objNameLength = objName.Length;
         
         if(objNameLength>defName.Length) {
             lengthDiff = objNameLength-defName.Length;
             
             for(int i = defName.Length; i<objNameLength;i++) {
                 appendName = appendName+""+objName[i];
             }
         }
         
         distanceChecker = new GameObject();
         distanceChecker.name = "distanceChecker"+appendName;
         distanceChecker.transform.parent = transform.parent;
         distanceChecker.transform.position = transform.position;
         distanceChecker.transform.rotation = transform.rotation;
         
         gyroBool = SystemInfo.supportsGyroscope;
         
         if(gyroBool) {
             gyro = Input.gyro;
                gyro.enabled = true;
         }
     
     }
     
     void Update() {
         if(gyroBool) {
             GyroWork();
         }
     }
     
     Vector3 requiredPosition;
     
     int xPos;
     float fraction = 0.1f;
     
     void GyroWork() {
         xPos = (int) gyro.attitude.eulerAngles.y;
         
         if(xPos>=0 && xPos<=30) {
         }
         else
         if(xPos>30 && xPos<=180) {
             xPos = 30;
         }
         else
         if(xPos>=330) {
             xPos = xPos - 360;
         }
         else
         if(xPos<330 && xPos>180) {
             xPos = -30;
         }
         else
             return;
         
         float xValue = fraction * xPos;
         
         requiredPosition = distanceChecker.transform.TransformPoint(Vector3.right * xValue);
         transform.position = requiredPosition;
     }
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by cartonino · Nov 07, 2016 at 07:40 AM

@tenthplanet0 I have some problem... You resolved it?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

15 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

deviceUniqueIdentifier 1 Answer

What device is being used? 1 Answer

Rendering with the CPU in Unity 0 Answers

How to make an actor spawn at a fixed position 1 Answer

How to detect if the device is android mobile or tablet 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges