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 /
  • Help Room /
avatar image
0
Question by McRobea · Mar 07, 2017 at 12:23 PM · vrlerpsmooth

Lerp to Gaze Location Smoothing Motion Issues (Cardboard)

Hey guys.

Im trying to create a script that allows my camera (player) to move between waypoints within a VR scene.

I have a script for a basic 'stare button' and would like the player to move to the location of the button once it has been looked at. Thus far the script it working to the extent that it 'teleports' the player to the new location, could anyone help me out with smoothing this so it happens over a few seconds?

 using System;
 using System.Reflection;
 using UnityEngine;
 using System.Collections;
 using UnityEngine.EventSystems;
 using UnityEngine.Events;
 using UnityEngine.UI;
 
 public class StareButton2 : MonoBehaviour, IEventSystemHandler, IPointerExitHandler, IPointerEnterHandler, ISelectHandler
 {
     Transform startMarker;
     public Transform endMarker;
     public float speed = 1.0F;
     private float startTime;
     private float journeyLength;
    // Stare Variables
      
         [SerializeField]
     private ButtonClickedEvent _OnClick = new ButtonClickedEvent();
     public float fillSpeed = 2f;
     Text _buttonLabel;
     public Image radialFill;
     bool _selected;
     bool _staring;
 
     void Awake()
     {
         _buttonLabel = this.gameObject.GetComponentInChildren<Text>();
         startTime = Time.time;
         journeyLength = Vector3.Distance(startMarker.position, endMarker.position);
         // startMarker = Camera.main.transform;
     }
 
     void Start()
     {
         Reset();
     }
 
     void Update()
     {
         if (_staring)
             radialFill.fillAmount += (Time.deltaTime * fillSpeed);
         else
             radialFill.fillAmount -= (Time.deltaTime * fillSpeed);
 
         if (radialFill.fillAmount >= 1f)
         {
             radialFill.fillAmount = 1f;
 
             if (!_selected)
             { //prevent multiple triggers
                 _selected = true;
                 _OnClick.Invoke();
                 Debug.Log("CLICK!");
             }
         }
         else if (radialFill.fillAmount <= 0f)
         {
             _selected = false;
             radialFill.fillAmount = 0f;
         }
     }
 
     public void StaringAt(bool on)
     {
 
         _staring = on;
     }
 
     public void Reset()
     {
         _staring = false;
         _selected = false;
         radialFill.fillAmount = 0;
     }
 
     public void OnPointerEnter(PointerEventData eventData)
     {
         StaringAt(true);
     }
 
     public void OnPointerExit(PointerEventData eventData)
     {
 
         StaringAt(false);
     }
 
     public void OnSelect(BaseEventData eventData)
     {
         _OnClick.Invoke();
         radialFill.fillAmount = 1f;
         _selected = true;
         Debug.Log("SELECT?!?!?!!");
 
         float distCovered = (Time.time - startTime) * speed;
         float fracJourney = distCovered / journeyLength;
         transform.position = Vector3.Lerp(startMarker.position, endMarker.position, fracJourney);
     }
 
 
     [Serializable]
     public class ButtonClickedEvent : UnityEvent { }
 }

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

113 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

Related Questions

Why isn't my object lerping ? C# 2 Answers

Smooth movement for a 3rd person camera 2 Answers

Determine a radius on terrain and lerp the border to smooth the height flattening 0 Answers

Rotate on Transform.localeulerAngels smoothly 0 Answers

How to smoothly rotate gameobject 20 degrees on key press? 0 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