• 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
1
Question by Mason Cook · Mar 07, 2011 at 12:35 PM · physicsjointhingejointsnake

How to Recreate the Old Classic Snake with Hinged Joints

Remember Snake? Well I'm currently recreating it, but I've gotten stuck on the basis of my idea. I was thinking I could attach a hinged joint to my main snake object (the head) and make all the Connected bodies snake segments (little segments that increase in number as you eat the apples). I wanted the snake to be strung together with these joints, but I've ran into a few problems.

Currently my SnakeMotor.cs script continually applies force to the snake's forward vector (keeping the snake always moving like the original) and my SnakeController.cs rotates the snake on its up vector (left or right) depending on user input. When I attempt to use the hinged joints with these controllers in mind, I get very unfamiliar results as to what I imagined it would work. The segments seem to pull on the snake head affecting its rotation and I can't tweak the settings for the life of me to find a proper effect.

Also, Keep in mind it's all 3d instead of the Classic Snake, so no tiles are involved; pure Unity physics.

So... Does Anyone have any ideas on how to approach this? I was hoping to make some type of joint (hinged, configurable, etc) work because I think it would apply a nice chain snake effect but I'm open for ideas.

Thanks, Let me know if I need to include any more information. -Mason Cook-

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by dissidently · Mar 07, 2011 at 03:12 PM

You're biggest problem here is likely the MASS of the connected parts as you stitch them to the head. This is known as Forward and Inverse Kinematics if you want to look it up online.

In short, each new object you attach as "tail" has Mass, and is acting like an anchor to the head part of your Snake.

The easiest way to overcome this would be making dummy objects with zero size and zero mass as the joint holders for your new tail pieces. These need to be rigid bodies to work with the physics, and they'll have TINY impacts, but probably nothing that you'll see once their size is reduced to nothing and mass to zero. (even tho the manual recommends not setting mass to zero, I've tested in on some of the stuff I'm doing, and it works the way I want)

Then you'll need to attach "tail section" objects to these dummy objects, and ensure that these visible tail sections do not have rigidbodies on them.

Hope that works for you.

Comment
Add comment · 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 Mason Cook · Mar 07, 2011 at 10:21 PM 0
Share

This fixes the problems I had with the rigid bodies fighting eachother. Unfortunately, I can't make a good snake effect with hinged joints I suppose, it just doesn't follow the snake game logic properly >.< Thank you for your help though..

avatar image rami · Apr 08, 2011 at 07:25 PM 0
Share

Did you managed to solve the problem, i am also in the same situation as you (I am new to this tool, need to write the java script). If the "rigid bodies fighting each other" try to check the constraints of all the axis, hope it will work......

avatar image
1

Answer by Bunny83 · Mar 07, 2011 at 06:40 PM

You try to use physics on a movement that's not based on physics. If the snake turns, the body(-parts) follow the exact path of the head. But in the "real" world if you form a rectangle with a rope and you pull on one end the rope will not stay on the path you've set up, at least not without some sheaves at the corners to keep the rope on track.

The old snake game doesn't even move the body parts. The head moves on and a new bodypart is created at the last head's position. The last part of the snakes tail is removed to simulate the movement.

What you want is a fix movement along fix waypoints (that are set at direction changes). I don't know what you want to use as snake body because the bodyparts have to bend around the corners.(skinned mesh?).

The real challange when creating a snake-clone in 3D is to create this "movement engine" to handle the movement correctly (not too sharp curves or it will look strange).

As I said: to use physics is not the right choice here.

It would be possible to use physics but you would have to create invisible colliders (cylinders) that act as sheaves at the corners. But that would restrict the movement and if the chain is really long the spring behaviour of the joints will cause problems.

Comment
Add comment · Show 1 · 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 Mason Cook · Mar 07, 2011 at 10:26 PM 0
Share

Okay, I see... I should have thought of that before I made the entire rest of the game ha... So How would I go about doing the way points? I've never used waypoints before, but I'm familiar with idea..

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Is there a 2d joint for a torsion (rotation) spring? 0 Answers

How to use Hinge Joints correctly inside a parent? 1 Answer

Why are my hinge joints inaccurate? 1 Answer

How to add friction to Unity HingeJoint? 1 Answer

Hinge joints not reaching target position 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