Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 xfixtrion4 · Aug 10, 2019 at 07:07 AM · vrcontrollerbike

Smooth turn (bike controller + yocto)

Hi everyone !

I have an issue in my vr simulator. I use a yoctoPuce to get impulse from my bike (real). When i go forward it works pretty well but the rotation is jerky. If anyone have a solution this will be wondeful ! This is my Script:

 using System;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
 
 
 public class BikeControler : MonoBehaviour
 {
     public bool isReplay;
     public int minAngle;
     public int maxAngle;
     public float magnitude;
     public bool alreadyTurn;
     public float coef;
     private Data data;
 
     #region bike component
     public GameObject bikeFrame;
     public GameObject frontWheel;
     public GameObject backWheel;
     public GameObject player;
     public GameObject bike;
     public float speed;
     public float turnSpeed;
     public GameObject wheel;
     public GameObject point;
     private float coefRotation = 1.2f / Mathf.Cos(21.257f);
     public Rigidbody rigid;
     public ReplayManager replayManager;
     public GameObject cadretest;
     #endregion
 
     #region Yocto component
     string errmsg = "";
     string target;
     YAnButton input1;
     YAnButton input2;
     YAnButton input3;
     YAnButton input4;
     YAnButton input5;
     private long nbOfPulse;
     private long lastNbOfPulse;
     private int sens;
     private float speedy;
     #endregion
 
     private void Start()
     {
         data = GameObject.FindGameObjectWithTag("Data").GetComponent<Data>();
 
         //initialize my yoctoPuce 
         if (YAPI.RegisterHub("usb", ref errmsg) != YAPI.SUCCESS)
         {
             Debug.Log("RegisterHub error: " + errmsg);
             Environment.Exit(0);
         }
         input1 = YAnButton.FirstAnButton();
         if (input1 == null)
         {
             Debug.Log("No module connected (check USB cable) ");
             Environment.Exit(0);
         }
 
         target = input1.get_module().get_serialNumber();
 
         input1 = YAnButton.FindAnButton(target + ".anButton1");
         input2 = YAnButton.FindAnButton(target + ".anButton2");
         input3 = YAnButton.FindAnButton(target + ".anButton3");
         input4 = YAnButton.FindAnButton(target + ".anButton4");
         input5 = YAnButton.FindAnButton(target + ".anButton5");
         nbOfPulse = input5.get_pulseCounter();
         lastNbOfPulse = input5.get_pulseCounter();
 
     }
 
     void Update()
     {
 
         if (!isReplay)
         {
             //Get pulse of the yocto from the bike
             nbOfPulse = input5.get_pulseCounter();
 
             //Difference between the last pulse counter and now
             long pulseDif = nbOfPulse - lastNbOfPulse;
             lastNbOfPulse = nbOfPulse;
 
             // Rotation value from the yoctopuce of the bike
             float frameRotation = input2.get_calibratedValue();
             float angle;
 
             // Slowdown if the player stop pedaling
             if (pulseDif == 0)
             {
                 //Speed change with weather
                 if (speedy > 0)
                     if (data.weatherData == 2)
                         speedy = speedy - 0.05f;
                     else if (data.weatherData == 3)
                         speedy = speedy - 0.01f;
                     else
                         speedy = speedy - 0.2f;
             }
             else // Speed from impulse
             {
                 speedy = pulseDif;
             }
 
             // The rotation of the bike frame
             bikeFrame.transform.localEulerAngles = new Vector3(-21.257f, 0, (500 - frameRotation) / 10);
 
             //Here is my issue-> rotation
             if (frameRotation < minAngle || frameRotation > maxAngle)
             {
                 if (frameRotation > 500)
                 {
                     angle = (360 - bikeFrame.transform.localEulerAngles.z);
                     sens = -1;
                 }
                 else
                 {
                     angle = -bikeFrame.transform.localEulerAngles.z;
                     sens = 1;
                 }
 
                 //here 
                 angle = Mathf.Deg2Rad * angle;
 
                 float centerCircle = coefRotation * (1 / angle);
 
                 point.transform.localPosition = new Vector3(centerCircle, 0, 0);
 
                 bike.transform.RotateAround(point.transform.position, Vector3.up, sens * (speedy) * turnSpeed);
 
                 alreadyTurn = true;
             }// Forward move 
             else
             {
                 if (rigid.velocity.magnitude < magnitude)
                 {
                     if (alreadyTurn)
                     {
                         rigid.AddForce(transform.forward * (speedy) * turnSpeed * coef);
                         alreadyTurn = false;
                     }
                     else
                         rigid.AddForce(speed * (speedy) * 10 * cadretest.transform.forward, ForceMode.Acceleration);
                 }
             }
         }
     }
 }




Comment
Add comment
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

0 Replies

· Add your reply
  • Sort: 

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

140 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

SteamVR 2.3 - Vive controllers aren't tracking after scene load 1 Answer

Gear VR controller buttons not working in Unity 2018.2 LW VR template 0 Answers

OVR Controller ghost flyer 0 Answers

how to save the values of hmd and controller position rotation in a list 0 Answers

How to map input for new Samsung Gear VR controller? 3 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