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
3
Question by dhendrix · Feb 09, 2010 at 06:01 PM · movementphysics

Restricting movement on an axis from physics

I want enemies and objects to not move on the y-axis on account of physics, but I want to still be able to move them at will, such as in their update method. So I may want an enemy to move up and down on the y axis, but if the player bumps into him I don't want the enemy to go flying off into space because of a y axis offset. A configurable joint is amazing, but does not work to my knowledge, as I can't move the object at all.

I was thinking maybe something with Math.clamp, but I'm not sure if that's the best solution.

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 Nicolaj Schweitz · Feb 09, 2010 at 09:56 PM 0
Share

it would be great if you can edit in and example of your clamp theory.

avatar image dhendrix · Feb 09, 2010 at 10:29 PM 0
Share

Well, now that I think about it, that wouldn't work. At certain points I may want the player to "descend" through the level on the y axis, in a on-rails type of way. Clamping movement wouldn't work, as that would limit the amount the player could move.

So basically, I want objects to be able to move freely on the y axis, but not move at ALL on that axis in terms of physics or collisions.

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by jonas-echterhoff · Feb 10, 2010 at 10:29 AM

You could Make a script which clamps the character to a certain position on the y-Axis. Then, when you actually want to move the character on that axis, do that via the script. Like this:

var yPos = 0.0;

function FixedUpdate () {

transform.position.y = yPos;

}

function Move (var newPos: Vector3) {

transform.position = newPos;
yPos = newPos.y;

}

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 dhendrix · Feb 10, 2010 at 07:28 PM 0
Share

That's a simple but effective solution, thanks.

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

No one has followed this question yet.

Related Questions

How to program gravity for planets? 3 Answers

Got unwanted motion blur on fast moving object (Only iOS) 0 Answers

How to archive anti-gravity controlls for a racer? 0 Answers

RigidBody immediately stops after AddForce 1 Answer

How can I make a physics object jump a given height on collision regardless of current velocity? 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