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 /
  • Help Room /
avatar image
0
Question by han1993 · Oct 21, 2015 at 09:10 AM · rigidbodymassfirst person

Question about creating a specific first person player prefab

Hi, I am trying to create a first person player prefab that won't affect the physical movement of in-game objects while colliding with them.

for instance, when the player jumps on a moving cube that is not affected by gravity, the cube keeps moving along without any physical affect from the player. and the player is able to stand on it while it is moving and not affect its movement.

Can anybody give me a tip on what are the possible ways to achieve that?

Really appreciated!

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
0

Answer by MrMeows · Oct 22, 2015 at 08:15 AM

In my experience, the only way to stand on a moving object is to make the player a child of the moving object. Add this to the moving object:

void OnCollisionEnter(Collision someCollision)
{
if(someCollision.collider.isPlayer) //Replace isPlayer with your own method
{
someCollision.collider.transform.parent = transform;
}
}
void OnCollisionExit(Collision someCollision)
{
if(someCollision.collider.isPlayer)
{
someCollision.collider.transform.parent = null;
}
}
Comment
Add comment · 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
0

Answer by Statement · Oct 22, 2015 at 12:59 PM

You could do this using layers and kinematic rigidbodies that follow regular rigidbodies.

Kinematic rigidbodies don't react to collisions, and you must move them through scripts.
Regular rigidbodies react to collisions, and movement is automatic.

If you have a bunch of cubes that can collide with each other, but don't want to get affected by the player, but the player affected by the cubes, you could possibly do something like this:

For each cube, you actually have two cubes.

  • One that has a collider and a kinematic rigidbody. Set layer to "KinematicLayer".

  • One that has a collider and a regular rigidbody. Set layer to "RegularLayer".

  • In FixedUpdate, the regular rigidbody copies position to the kinematic rigidbody.

(The KinematicLayer, RegularLayer and PlayerLayer does not exist by deafult, you have to create them yourself)

In the physics collision matrix, make it so that

  • KinematicLayer does not collide with KinematicLayer

  • KinematicLayer does not collide with RegularLayer

  • RegularLayer does not collide with KinematicLayer

  • RegularLayer does collide with RegularLayer

  • PlayerLayer does collide with KinematicLayer

  • PlayerLayer does not collide with RegularLayer

Now, your player should be able to walk on the kinematic rigidbodies. The kinematic rigidbodies position is determined by their regular rigidbody. The regular rigidbody acts like usual.

Note that this can cause the player to get squished under the kinematic rigidbodies since the player can't affect them at all.

Comment
Add comment · 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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbodies that never push back 2 Answers

Adding mass to my rigidbody makes it go through the floor 1 Answer

Rigidbodies colliding with each other ignore mass, details inside. 0 Answers

How to make an objects mass increase the longer its air born? 1 Answer

Modifying mass of all objects 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