Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing speed between ControlPoints
#1
Question 
Hi,

I'm looking to change the speed of an object attached to a spline after it travels pass each control point.
(E.g A race car slowing down for corners and speeding up after the corner)

How would I best achieve something like this?

Thanks in advance.
Reply
#2
Hi,
In your controller, you have a OnControlPointReached event. Use that ans set your new speed in the event handler.
Let me know if it does work
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
(07-22-2020, 04:58 PM)_Aka_ Wrote: Hi,
In your controller, you have a OnControlPointReached event. Use that ans set your new speed in the event handler.
Let me know if it does work

Hi I am trying to use this method but I don't see an option to change speed.   Can anyone advise please?
Also, I tried the Transform.LookAt function and it didn't work.  Maybe I'm using this whole section wrong?

thanks.

   
Reply
#4
Hi,
The list of members displayed are the members of the different scripts attached to the object you selected, for example CP0004. This object does not have a Speed member, so it is normal that it does not display. What you need to do is to set the code that checks what control point is reached and set the speed accordingly in a method, and then use that method as an event handler. You see what I mean?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
(10-02-2020, 12:15 PM)_Aka_ Wrote: Hi,
The list of members displayed are the members of the different scripts attached to the object you selected, for example CP0004. This object does not have a Speed member, so it is normal that it does not display. What you need to do is to set the code that checks what control point is reached and set the speed accordingly in a method, and then use that method as an event handler. You see what I mean?


In theory, I understand the overview of what you mean,  but please forgive that I only started teaching myself this stuff for about 3 months.  So how to do this feels very advanced to me.  I tried to find tutorials but I haven't had luck.  Should I create a new script from scratch OR is it just a matter of selecting the appropriate script from this list and adding something like:     public float Speed... etc ?
And then maybe it will show up in the list for me to change?

Thanks and sorry if this is a very newbie ask.
Reply
#6
Here is an example:

Code:
        public void OnCPReached(CurvySplineMoveEventArgs e)
        {
            if (e.Spline.GetControlPointIndex(e.ControlPoint) == 2)
                e.Sender.Speed = 10;

        }

Add this method to a script (whatever it is), and then select an instance of that script as the object for your On Control Point Reached event, then select the method above.

You can see an example of usage of that event in TrainCarManager.cs, used in the scene 12 to handle the train junction.

If this explanation is not enough, please read this part of Unity's manual: https://docs.unity3d.com/Manual/UnityEvents.html
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Changing Volume Mesh UV ATHellboy 15 4,148 03-19-2020, 05:35 AM
Last Post: ATHellboy
  Generating multiple object on changing transform jawadkhan.9026 12 6,432 09-06-2019, 09:39 PM
Last Post: _Aka_
  Connections during speed change 3583Bytes 8 5,148 04-05-2019, 01:12 PM
Last Post: _Aka_
  Pitch and Speed sirak 1 2,000 11-23-2018, 02:48 PM
Last Post: _Aka_

Forum Jump: