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 Garbo42069 · Apr 26 at 12:26 PM · splinetweening

Surge - tween sequenced object sometimes teleports

I'm using pixelmaker's Surge script for a game in which balls spawn on the left side of the screen and move to the right, bouncing on a paddle that the player moves. If the player misses the ball, it falls below the paddle and the player loses health.

This is my first personal project and I'm very happy with how much I've learned and how many bugs I've managed to fix so far, but this one has got me completely stumped:
Sometimes the ball will teleport briefly, either to the beginning of its previous spline, or to the beginning of its next spline before it has moved. So if the paddle is in position 1, the ball will bounce over to position 2, then teleport to position 1 for a fraction of a second and detect the collision with the paddle that has not moved, then bounce over to position 3.

I've already started to think about how I could completely rewrite this script to possibly fix this, but if anybody has any ideas, I would much rather fix what I already have:
using System.Collections; using System.Collections.Generic; using UnityEngine; using Pixelplacement;

 public class BallMovement : MonoBehaviour
 {
     private GameManager gameManager;
 
     private GameObject player;
 
     public Transform ball;
     private Spline startSpline;
     private Spline highSpline;
     private Spline medSpline;
     private Spline lowSpline;
     private Spline fallSpline;
     private Spline endSpline;
     public AnimationCurve bounceCurve;
     public AnimationCurve startBounceCurve;
     public AnimationCurve endBounceCurve;
 
     // Animation durations (playback speed)
     public float firstDuration = 2.5f;
     public float highDuration = 3f;
     public float medDuration = 2.5f;
     public float lowDuration = 2f;
     public float fallDuration = 0.4f; 
 
 
     // Start is called before the first frame update
     void Start()
     {
         gameManager = GameObject.Find("Game Manager").GetComponent<GameManager>();
 
         player = GameObject.Find("Player");
 
         // Get the splines (paths) for all bounce types
         ball = transform.GetChild(0);
         startSpline = transform.GetChild(1).GetChild(0).GetComponent<Spline>();
         highSpline = transform.GetChild(1).GetChild(1).GetComponent<Spline>();
         medSpline = transform.GetChild(1).GetChild(2).GetComponent<Spline>();
         lowSpline = transform.GetChild(1).GetChild(3).GetComponent<Spline>();
         fallSpline = transform.GetChild(1).GetChild(4).GetComponent<Spline>();
         endSpline = transform.GetChild(1).GetChild(5).GetComponent<Spline>();
 
         startSpline.enabled = true;
 
 
         // Start first bounce
         StartCoroutine(FirstBounce());
 
     }
 
     private void OnTriggerEnter(Collider other)
     {
 
         // Only if colliding with player, not other balls
         if (other.CompareTag("Player"))
         {
             // Stop ball from continuing to fall
             StopAllCoroutines();
             // Unused splines are disabled to prevent teleportation (this didn't fix it)
             startSpline.enabled = false;
             medSpline.enabled = false;
             lowSpline.enabled = false;
             highSpline.enabled = false;
             fallSpline.enabled = false;
             endSpline.enabled = false;
 
             // Move splines right to next position
             int moveRight = 8;
 
             startSpline.transform.Translate(new Vector3(moveRight, 0, 0));
             lowSpline.transform.Translate(new Vector3(moveRight, 0, 0));
             medSpline.transform.Translate(new Vector3(moveRight, 0, 0));
             highSpline.transform.Translate(new Vector3(moveRight, 0, 0));
             fallSpline.transform.Translate(new Vector3(moveRight, 0, 0));
 
 
             if (ball.transform.position.x > 10)
             {
                 // Final bounce
                 StartCoroutine(LastBounce());
             }
             else
             {
 
                 // Randomly select next bounce type
                 int bounceSelect = Random.Range(0, 3);
 
                 switch (bounceSelect)
                 {
                     case 0:
                         StartCoroutine(LowBounce());
                         break;
                     case 1:
                         StartCoroutine(MedBounce());
                         break;
                     case 2:
                         StartCoroutine(HighBounce());
                         break;
                 }
             }
         }
 
 
     // Bounce animations
     // Unused splines are disabled to fix bug that lead to ball teleporting for a fraction of a second, leaving weird trails
     // and bouncing when they should be missed.
     // but turns out that didn't fix it idk
     IEnumerator FirstBounce()
     {
         Tween.Spline(startSpline, ball, 0.5f, 1, false, firstDuration, 0, startBounceCurve, Tween.LoopType.None);
         Tween.Spline(fallSpline, ball, 0, 1, false, fallDuration, firstDuration, Tween.EaseLinear, Tween.LoopType.None);
         yield return null;
     }
 
     IEnumerator LastBounce()
     {
         endSpline.enabled = true;
         Tween.Spline(startSpline, ball, 0, 0.6f, false, firstDuration, 0, endBounceCurve, Tween.LoopType.None);
         yield return null;
     }
 
     IEnumerator HighBounce()
     {
         highSpline.enabled = true;
         Tween.Spline(highSpline, ball, 0, 1, false, highDuration, 0, bounceCurve, Tween.LoopType.None);
         Tween.Spline(fallSpline, ball, 0, 1, false, fallDuration, highDuration, Tween.EaseLinear, Tween.LoopType.None);
         timeToPaddleHit = highDuration;
         yield return null;
     }
 
     IEnumerator MedBounce()
     {
         medSpline.enabled = true;
         Tween.Spline(medSpline, ball, 0, 1, false, medDuration, 0, bounceCurve, Tween.LoopType.None);
         Tween.Spline(fallSpline, ball, 0, 1, false, fallDuration, medDuration, Tween.EaseLinear, Tween.LoopType.None);
         timeToPaddleHit = medDuration;
         yield return null;
     }
 
     IEnumerator LowBounce()
     {
         lowSpline.enabled = true;
         Tween.Spline(lowSpline, ball, 0, 1, false, lowDuration, 0, bounceCurve, Tween.LoopType.None);
         Tween.Spline(fallSpline, ball, 0, 1, false, fallDuration, lowDuration, Tween.EaseLinear, Tween.LoopType.None);
         timeToPaddleHit = lowDuration;
         yield return null;
     }
 }
 
Comment
Add comment · Show 1
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 Garbo42069 · Apr 27 at 12:44 PM 0
Share

So I re-wrote the script so that future splines spawn in advance instead of on top of each other and moving over after bounces, and I'm still getting the same bug. I have no idea what to do about this.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Garbo42069 · Apr 27 at 08:58 PM

I figured it out -- the end of the tween's animation curve went slightly past 1 in value and time, which apparently broke 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

135 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

Related Questions

leantween ltspline control points setup 0 Answers

Help needed: repairing the Spline Controller Script 1 Answer

Mesh from Vertices (Polygon from Spline) 3 Answers

Help resetting a spline for repeat use 0 Answers

Orientation along spline path / Mesh extrusion along path, problem with smooth orientation 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