Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 ToeBeanGames · Sep 08, 2017 at 10:48 PM · path2.5dspline

Restrict 2D object to path/spline

So I'm working on a 2.5D game that has loops. My entire issue here is no matter what, my character's Z position is always 0. I've tried using triggers that set the character's Z position with no luck. alt text The red path is the one my character is currently taking, locked on the Z axis, and the blue path is the one I would like my character to take.

So my main question is, what is a good spline asset and how can I make my character follow it?

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by IsaiahKelly · Sep 09, 2017 at 03:50 AM

Something is locking your character's Z position, but it's impossible for anyone here to tell you why. At least not without more information. However, you will probably need to debug and figure this out yourself, since if you knew exactly what was causing it you probably wouldn't need any of us to help you anyway. :)

All I can really suggest is to try to isolate the issue as much as possible. This will help you narrow down the possible causes. Maybe an animator controller or root motion is locking the position?

A very bad "hack" until you figure out what's causing it or if you're just lazy would be to just forcibly reset the Z position in late or fixed update to whatever you want like this:

     // whatever you want the Z position to be.
     public float zOffset = 10f;
 
     // cache the transform to improve performance.
     private Transform m_Transform;
 
     private void Awake()
     {
         m_Transform = GetComponent<Transform>();
     }
 
     void FixedUpdate()
     {
         m_Transform.position = new Vector3(m_Transform.position.x, m_Transform.position.y, zOffset);
     }
Comment
Add comment · Show 6 · 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 ToeBeanGames · Sep 09, 2017 at 06:11 AM 0
Share

It's not using root motion, but I could check the movement scripts to see if that's the issue.

avatar image ToeBeanGames ToeBeanGames · Sep 09, 2017 at 06:25 AM 0
Share

I can't find anywhere in scripts where the Z axis is locked; I've tried moving the character along Z in play mode which actually works until I jump. If it helps, the engine I'm working with is called Sonic Realms and it's built only for 2D which is probably why I can't seem to modify the Z axis during runtime.

avatar image IsaiahKelly ToeBeanGames · Sep 09, 2017 at 06:53 AM 0
Share

Then the jump method is definitely resetting the Z position and probably some other function is doing so at startup. You need to remember that every bit of code that touches the transform position will probably also be resetting the z axis/position. So this might be hard to change or track down.

However, I've added a simple hack to the answer above that might help you for now.

Show more comments
avatar image IsaiahKelly ToeBeanGames · Sep 09, 2017 at 06:35 AM 0
Share

If you're using physics to move you should also check and see if you have the rigidbody's Z axis frozen under constraints. If you're using 2D physics than you would need to either switch to the 3D physics system or just stop setting the position through physics.

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

70 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

Related Questions

How to go about constraining a player to a path? 0 Answers

object follow a spline path 1 Answer

Follow curved path with dynamic speed 2 Answers

Add force along a path 1 Answer

PutOnPath iTween spline but not restrict in the up direction (jump) 3 Answers


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