• 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
Question by dsaos · Feb 01, 2012 at 12:07 AM · movementrigidbodyvector3constraints

Constrain character to series of intersecting paths?

For the purposes of my project, it's helpful to think about the world maps in old-school Super Mario games, such as this one. I am trying to make a 3D game wherein the character's movement is constrained to paths not unlike the above image—a series of connected "nodes." These lines run in any 3D direction (so point A would be at [0, 2, 3] whereas point B would be at [4,1,2] for example), and will often intersect so the player can change paths. In terms of the control scheme, think Diablo-style point-and-click, only restrained to specific line-based paths.

It looks like RigidBody can constrain movement along basic axes, but how can I constrain my RigidBody to these custom lines I have that move throughout all three? Bonus points if there's an easy way to dynamically generate those paths from geometry intersections in the level.

Comment

People who like this

0 Show 0
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

Answer by Peter G · Feb 01, 2012 at 12:38 AM

The answer is yes to all of those questions.

If you want a really easy method, I would suggest using iTween. It provides exactly what you want for an affordable price.

If your willing to do some coding, then you can do some really basic node navigation. Each point represents a node. And each node keeps track of the nodes near it. As long as the player is controlling the character, you don't really have to do much pathfinding which is very very good for you.

When the player is at a node, they have the ability to choose the next node that they go to (Either by arrow keys or mouse clicks). Then the player starts moving towards the next destination. Here's what I mean in a quick algorithm.

  foreach(node in set) {
        if distance (player, node) < someSmallDist //Account for a little inaccuracy.
                 currentNode = node;
                 break "foreach" loop;

  }
  if(currentNode != null) {
        targetNode = NewNodeFromInput()
        moveDirection = targetNode - PlayerPosition
        Player.Move(moveDirection.normalized * speed)
 }
 else {
        Player.Move(moveDirection.normalized * speed * Input);
 }

That's pretty simple to be honest. You can do far more elaborate pathfinding routines, its just all a matter of what you are able to do.

There are also plenty of AI routines on the Asset store if you want to look there. Most of them are relatively inexpensive so it might be what you want if you can't program.

Comment

People who like this

0 Show 2 · 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 dsaos · Feb 01, 2012 at 02:53 AM 0
Share

I think I may be bad at explaining things. The control scheme, as I envision it, isn't set up for arrow presses from node to node (it looks like this looks great for that though). Rather, the character fluidly moves along these paths via a click-to-move input, but can't move off them (so if you click on an area not occupied by the path, the character simply gets as close as he validly can). The player shouldn't "snap" to any given node. Think Diablo-style point-and-click, only constrained to paths like in the Mario world maps.

avatar image Peter G · Feb 02, 2012 at 10:40 PM 0
Share

Oh, well then you do need to do real pathfinding. You have the option of writing it yourself or finding a number of implementations on the Asset store

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Should I move an object using Transform.translate, or by changing the velocity of the Rigidbody with a Vector2/3 each frame? 0 Answers

How do I use Vector3 with rigidbody.Addforce 2 Answers

Can't move player with rigidbody.velocity 1 Answer

Change player movement 0 Answers

Npc Movement 0 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