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 Alter · Jan 23, 2013 at 03:48 PM · c#spline

Switching Splines on the go

Hi guys, still fairly new to programming (C#) and unity and was wondering if I could get some help with splines please. I've managed to get splines working so far where the 'player' will follow the select route.

However I would like to find out how to make the 'player' switch splines when needed, for example while running they can choose a different path and not to just appear on it- more like a jumping motion.

I've tried following other posts but I simply can't get the hang of it at all. If it makes things easier I'm trying to create a rail shooter/runner.

Any help on the subject is greatly appreciated and thank you in advance.

Comment
Add comment · Show 2
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 Graham-Dunnett ♦♦ · Jan 23, 2013 at 04:28 PM 0
Share

Post the code that you have and that does not work how you want, and the community can help you.

avatar image Alter · Jan 23, 2013 at 05:24 PM 0
Share

Basically I'm using an invisible gameObjects to follow me the opposite spline. Hope this gives you guys an idea.

 using UnityEngine;
 using System.Collections;
 
 public class $$anonymous$$oveTo : $$anonymous$$onoBehaviour {
     
 //    private Transform myTransform;
     public GameObject ObjectA;
     public GameObject ObjectB;
     
     public float smooth = 5.0F;
 
     // Update is called once per frame
     void Update () 
     {
 
        if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A))
           transform.position = Vector3.Lerp(transform.position, ObjectB, Time.deltaTime * smooth);
 
 
        if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.D))
           transform.position = Vector3.Lerp(transform.position, ObjectA, Time.deltaTime * smooth);
 
     }
 }

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Graham-Dunnett · Jan 23, 2013 at 08:13 PM

Okay, so you currently use two GOs and can get the player or whatever the script is attached to to move between them. You're using Lerps, which is not quite the same thing as a spline. But no matter. So, instead of having ObjectA and ObjectB, have an array of GameObjects. You can then in the inspector populate this array with all the invisible game objects that define where the player can get to. Then, in your code, use ObjectA and ObjectB. These would be used as the start and end points for the player. Your challenge is then to work out how to set these two values.

To keep things simple, assume that you have only 3 invisible game objects, call them go1, go2 and go3 in the array. To start with, ObjectA = go1, and ObjectB = go2. Your player can move between them. If the player gets to go2, then set ObjectA = go2, and ObjectB = go3. The player then moves between these.

If your player can only move between a linear sequence, say go1->go2->go3->...->goN then these transitions are easy, ObjectA = ObjectB and ObjectB = whatever it was pointing at plus one. If the ordering is more complex, so the player can progress through a graph network then your transitions are harder to work out. The principle is the same, just you'll need to compute the new values for ObjectA and ObjectB. That might depend on ObjectB, and perhaps what button or key the user has pressed. If you look at the diagram at the top of the wikipedia link, assume that the player starts at 6. They move towards 4. When they get there, if they press the space bar, they do a jump, and move towards 5. If they are not pressing space, then they move towards 3. And so on.

I guess, for completeness, I should have added that the game objects in a graph would be called nodes, and the transitions between nodes are called edges. Your problem is really deciding how to represent the edges, and use those to determine how the player transitions from one edge to the next. You can think of each node as storing data about which edges can be taken depending on which key is pressed.

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

12 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

The name `DebugUtils' does not exist in the current context 1 Answer

Bullet moving backwards with Hermite Spline Controller 0 Answers

How do i Have GameObjects along a spline(Like Nodes)?? 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