Search Unity

Question Rythmn Game Note Typing Issue

Discussion in 'Scripting' started by pikachurian, Apr 13, 2021.

  1. pikachurian

    pikachurian

    Joined:
    Sep 28, 2017
    Posts:
    2
    I'm making a DDR style rhythm game. I have a conductor class that keeps track of the song position, bpm. A track class that keeps track of the notes and spawn them when needed. And a note class that move the note towards the button that you need to press. The timing on this works pretty well. However, I want to note to move off screen, which I am having trouble with because I am using lerp to move the note to its destination. Is there a way to make the note move past its destination at the same speed as the lerp function? Also, the reason why I am using Vector3 is I'm going to parent the notes to the camera and move the camera for some cool effects.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class NoteController : MonoBehaviour
    6. {
    7.     //transform tf;
    8.     // Start is called before the first frame update
    9.     public Conductor conductor;
    10.     public GameObject buttonObj;
    11.  
    12.     public Vector3 spawnPos;
    13.     private Vector3 hitPos;
    14.  
    15.     public int beatsShownInAdvance;
    16.     public float beatOfThisNote;
    17.  
    18.  
    19.     void Start()
    20.     {
    21.         hitPos = buttonObj.transform.position;
    22. }
    23.  
    24.     // Update is called once per frame
    25.     void Update()
    26.     {
    27.         if (transform.position.y < hitPos.y)
    28.         {
    29.             transform.position = Vector3.Lerp(
    30.                 spawnPos,
    31.                 hitPos,
    32.                 (beatsShownInAdvance - (beatOfThisNote - conductor.songPositionInBeats)) / beatsShownInAdvance
    33.             );
    34.         }
    35.     }
    36. }
    37.  
     
    Last edited: Apr 13, 2021
  2. pikachurian

    pikachurian

    Joined:
    Sep 28, 2017
    Posts:
    2
    I meant timing not typing.