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 arvzg · Apr 25, 2014 at 12:16 PM · collisionphysicsrigidbodytransform

Modifying height directly on a Rigidbody Object without gravity

I am making a UFO spaceship type object controller, and one of the controls is if I press the Space key, it raises the height of the ship, and pressing Control lowers the height.

The spaceship currently has a Rigidbody component component with "Use Gravity" disabled, and I am manipulating its Transform.position variable directly inside of code that looks basically like this:

 throttle = Input.GetAxis("Vertical");
 height += throttle * verticalSpeed; //height is a Property which maps to transform.position.y

And it is working quite nicely in general, but I've read that I should not be modifying Transforms on objects with a Rigidbody component, so I am wondering what the proper way would be to do this?

I need the object to have a Rigidbody because I want it to have collisions. Is there another way to achieve physical collisions without a rigidbody? Or is this a perfectly ok way to do this?

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 EvilTak · Apr 25, 2014 at 02:24 PM 1
Share

Ins$$anonymous$$d of using transform to change the position, you can use rigidbody.position to change it. It is similar to transform.position, but with transform.position, the rigid body will give incorrect collisions as it appears to teleport ins$$anonymous$$d of move. You can use rigidbody.$$anonymous$$ovePosition() also.

avatar image arvzg · Apr 25, 2014 at 03:11 PM 0
Share

I was staring at the script reference for Rigidbody and somehow completely missed both $$anonymous$$ovePosition and rigidbody.position. So obvious now that I know, thanks!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by PumpkinHead · Apr 25, 2014 at 02:41 PM

Don't know if this is right but Float up;

 Throttle = Input.GetAxis("Vertical");
 Height + up += th...........

Don't know if that's what you are looking for but fort Il give it a go as a noob to unity and coding

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 EvilTak · Apr 25, 2014 at 03:13 PM 0
Share

I'm sorry PumpkinHead, that code is wrong and will result in an error. If you are a noob and don't know what you're doing, please do not post answers.

avatar image PumpkinHead · Apr 26, 2014 at 09:42 AM 0
Share

ok sorry evil Tak happy you sorted it

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

22 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

Related Questions

Detect collision/trigger between two body without rigidbody? 3 Answers

How to test for a collision with a Terrain 1 Answer

How to properly move a rigidbody/collider? 2 Answers

Is there a solution to when colliders bypass? 2 Answers

Physics - increase gravity speed without making balls fall through planes 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