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 Trodekas · Jul 04, 2014 at 01:34 PM · transformpositionvector3moveslerp

Vector3.Slerp not working

Hello, I'm trying to write a script which creates a platform and over short period of time moves the platform into position above. But I can get it working properly: the platform instantiates only on start position and doesn't move at all. Thanks for the help.

using UnityEngine; using System.Collections;

public class GroundCreator : MonoBehaviour {

 public GameObject[] ground;
 public Transform startpoint;
 public Transform endpoint;

 public bool detector;

 public float time = 1f;

 void Start()
 {
     detector = false;
 }
 
 void OnTriggerEnter2D (Collider2D other)
 {
     if(other.tag == "Player")
     {
         detector = true;
     }
 }

 void Update()
 {
     if(detector == true)
     {
         int i = Random.Range(0, ground.Length);
         GameObject groundInstance = Instantiate(ground[i], startpoint.position, startpoint.rotation) as GameObject;
         groundInstance.transform.position =  Vector3.Slerp(startpoint.position, endpoint.position, time * Time.deltaTime);
         Destroy(gameObject);
     }
 }

}

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by fschneider · Jul 04, 2014 at 01:54 PM

Don't use Time.DeltaTime as parameter to Slerp. If you want to animate the position for a given time, create one variable for defining the seconds you want to animate, and a second variable keeping track of the fraction of that you already animated. Then use a third variable to map the second variable to the interval [0..1] and pass that as a parameter to Slerp.

Comment
Add comment · Show 1 · 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
avatar image robertbu · Jul 04, 2014 at 02:36 PM 1
Share

The use of deltaTime will work if the first parameter represents the current position, not the starting position. It produces and eased movement to the goal. So if 'groundInstance.transform.position was used for the first parameter, the object would move. If you don't want eased movement, you can still use deltaTime. Change the use of Slerp() to $$anonymous$$oveTowards() and also have the first parameter represent the current position.

avatar image
0

Answer by meat5000 · Jul 04, 2014 at 02:41 PM

Lerp and Slerp are attended functions, i.e they require constant attention and must be called every frame to work properly.

  groundInstance.transform.position = Vector3.Slerp(startpoint.position, endpoint.position, time * Time.deltaTime);
 Destroy(gameObject);

You perform one step of Slerp and then destroy the object which handles it. Place your Slerp in a script on the Instantiated gameObject and use GetComponent to trigger the Slerp, so destroying your creator object won't prevent the Slerp being performed.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How to move Instantiated object to pre-defined position(Solved) 1 Answer

C# move y position of object not working 2 Answers

Setting target position in Vector3.MoveTowards 2 Answers

Creating a bouncing game without using physics - Vector3 math problem, 2 Answers

Trouble converting transform.position to C# 1 Answer


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