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 BlacKatFever · Jan 20, 2012 at 03:34 AM · slerpobject movement

Slerps and / or other pendulum-like movements

Hey all,

Recently been working on adjusting my spider object in my game, and I've managed to come up with something (with the help of the kind folks at Unity Answers) that produces the desired result. Imagewise, I have a spider that is sitting on a branch (we'll call point A) who swings in an arc towards another branch (point B). When he reaches point B, he makes the return trip back towards point A. The arc is reminiscent of a pendulum.

The problem is that I've been using Slerp and while I'm happy with how the spider moves - I need away to adjust the depth of the arc. Here is my current code.

 using UnityEngine;
 using System.Collections;
 
 public class swingSpider : MonoBehaviour {

 public Transform start;
 public Transform end;
 
 public bool startToFinish;
 public bool finishToStart;
 
 public float slerpStartTime;
 public float speed;
 public float distance;
 
 GameObject spider;
 //public GameObject A;
 //public GameObject B;
 
 Vector3 spiderPos;
 Vector3 startPos;
 Vector3 endPos;
 
 // Use this for initialization
 void Start () 
 {
     startPos = start.transform.position;
     Debug.Log(startPos);
     endPos = end.transform.position;
     Debug.Log(endPos);
     
     startToFinish = true;
     Debug.Log("sTF = true");
     finishToStart = false;
     Debug.Log("fTS = false");
     
     speed = 0.1f;
     slerpStartTime = Time.time;
     transform.position = start.position;
     Debug.Log("startPos = "+startPos);
     //transform.position = end.position;
 }
 
 // Update is called once per frame
 void Update () 
 {
     
     if(startToFinish == true)
     {
         Vector3 center = (start.position + end.position) * 0.5f;
         center -= new Vector3(0,-0.1f,0);
         Vector3 startRelCenter = start.position - center;
         Vector3 endRelCenter = end.position - center;
         
         distance = Vector3.Distance(transform.position, end.transform.position);
         if(distance >= 0.1)
         {
             transform.position = Vector3.Slerp(startRelCenter, endRelCenter, (Time.time - slerpStartTime) * speed);
             transform.position += center;
         }
         if(distance <= 0.1)
         {
             ResetA();
         }
     
     }
     
     if (finishToStart == true)
     {
         Vector3 center = (start.position + end.position) * 0.5f;
         center -= new Vector3(0,-0.1f,0);
         Vector3 startRelCenter = end.position - center;
         Vector3 endRelCenter = start.position - center;
         
         distance = Vector3.Distance(transform.position, start.transform.position);
         if(distance > 0.1)
         {
             transform.position = Vector3.Slerp(startRelCenter, endRelCenter, (Time.time - slerpStartTime) * speed);
             transform.position += center;
         }
         if(distance <= 0.1)
         {
             ResetB();
         }
     }
 }
 
 void ResetA()
 {
     if(startToFinish == true)
     {
         startToFinish = false;
         slerpStartTime = Time.time;
         transform.position = end.position;
         distance = 0; 
         finishToStart = true;        
     } 
 }
 
 void ResetB()
 {
     if(finishToStart == true)
     {
         finishToStart = false;
         slerpStartTime = Time.time;
         transform.position = start.position;
         distance = 0;
         startToFinish = true;
     }
 }

}

I've found that I can adjust the y-coordinate of the Vector3 center to some degree, but not enough to fit my needs. I don't need the arc to be completely spherical, it can cylindrical as well.

Any suggestions how I can use the slerp function to produce the desired results? Or any other suggestions on how I can go about doing this?

I know Eric5h5 suggested looking into co-routines, but I wasn't able to find (let alone, write) anything useful.

Thanks again for your time!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Moving player in an arc, from startPoint to endPoint 2 Answers

Having an action that occurs after a Quaternion slerp reaches goal 2 Answers

Vector3.Slerp leads to wrong axis rotation 1 Answer

Euler Angles Rotation Problems 1 Answer

Why does resetTimer act counter-intuitively? 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