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 Jacktang · Jul 14, 2014 at 07:00 PM · physicstransformworld spacelocal space

Physics in Local Space rather than World Space

Hey guys, I'm working on an endless runner game. Usually with those the idea is to leave the player stationary, and move the level geometry instead. Now the client has thrown a bit of a curve ball and asked for physics bodies in the level, like a stack of boxes or dangling chains.

The problem is, I move the level using transform.position = Vector3.left * speed on each level "tile" that I spawn. This causes any physics bodies i place in the tile to move around as the level moves.

Is there a way to mark certain physics volumes as relative to their parents transform rather than world space? Or can you think of any other ways to combat this problem? Do I need to change the level structure so that it actually is the player that moves rather than the level?

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
Best Answer

Answer by Owen-Reynolds · Jul 14, 2014 at 07:40 PM

I've gotten surprisingly good results with childing rigidbodies and moving the parents.

I noticed it after trying to make a quick example of "why you should never make a child be a rigidbody." In some cases, I could not make child RBs misbehave. Turns out that moving an empty parent of several RBs works fine. It's just a quick way of manually moving them all (with no change to their speed.)

Since you move everything, an object will never teleport inside another this way, only into the player. And player-hits are probably already handled in a special, non-physcis way (by you.)

[Edit] If the objects are resting when you do this (or stacked,) the moving "floor" needs to be a kinematic rigidbody (credit to OP, I don't know why this works.)

Comment
Add comment · Show 4 · 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 Jacktang · Jul 14, 2014 at 08:29 PM 0
Share

I tried this and unfortunately it creates weird physics behaviours. Would you $$anonymous$$d elaborating on how you've gotten decent results doing this? I tried dragging out a long kinematic box as the ground, then stacking some physics boxes one on top of the other, then parenting everything to a root transform. What happened was the blocks slid over the ground as if I was "pulling the rug out from under them" and eventually toppled over.

avatar image Kiwasi · Jul 14, 2014 at 08:31 PM 0
Share

Never actually tried this approach, but I don't see why it won't work.

The only time I ever get rigidbody parenting problems is if one rigidbody is a parent of another rigidbody

avatar image Jacktang · Jul 15, 2014 at 04:53 AM 0
Share

This actually did work. The problem I was having before was due to not adding a rigid body to my ground volume. I thought I had done that but it was just a regular collider. Once I added that, the physics behaved correctly.

avatar image Owen-Reynolds · Jul 15, 2014 at 03:48 PM 0
Share

Wow! I just noticed the same problem you had, and realized I had only tested this with moving rigidbodies. Never on resting, and it completely didn't work them them -- the sliding problem you noticed. I never would have guessed giving the base a kinem RB worked.

avatar image
1

Answer by Kiwasi · Jul 14, 2014 at 07:27 PM

Physics works fine if you simply add your move level script to every GameObject that needs to move with the level. I've done the same thing in my side scroller. I would suggest not parenting the RigidBody, as this can cause weird effects.

In other words use transform.position to keep all of your GameObjects moving past the camera. Then use rigidBody.AddForce to get realistic physics movement on top of the base movement.

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 Owen-Reynolds · Jul 14, 2014 at 07:45 PM 0
Share

...and to be more specific on that 1st sentence, suppose an object is falling straight down. If it gets non-physics moved (translate, position=, move parent... ) the physics speed won't change. If will still be falling straight down. If won't "see" the sideways motion and turn that into a diagonal fall.

Now, if the level spins you have a problem, but even then, I think spinning the velocity will work.

avatar image Jacktang · Jul 14, 2014 at 08:27 PM 0
Share

Interesting. I'll have to try that out. I tried calculating a velocity that is counter to how fast the level is moving and applying that to each rigid body, but that didn't work. Never thought of moving each object individually though. Sounds so crazy that it just might work.

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

24 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

Related Questions

Rotate and transform in local space 2 Answers

ignorecollision return error 0 Answers

How to disable and enable HingeJoint? 0 Answers

Rotating child doesn't move parent Rigidbody? 1 Answer

Is there a solution to when colliders bypass? 2 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