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 destructivArts · Feb 12, 2014 at 02:10 AM · physicscollision detectionsimple

Can I implement basic physics on cubes without writing code?

So I'm creating a game that uses cubes as the meshes for everything. I will relay all the detail through textures (animated when needed). The game is so simple I dont really even need gravity or forces etc. I really just need to keep to cubes from intersecting. Is there a way to do this with the existing rigidbody/collision mesh without too much coding?

Edit: For clarity, this is how I'm implementing things. The player and all environment objects have cube collision meshes and rigidbodies. I'm affecting the transforms of the player to move him around. Note: rigidbody.MovePosition works as well. Its what I have in place now but it doesn't seem to make a difference. When the player hits say a table (whose collision mesh is about half the height of the player) the player goes flying off into space. This is not the kind of physics I'm looking for. I don't need authentic gravity or rotational forces. I want the cubes to always be oriented the same way and to stay on the ground (I guess that I would just attempt moving the player down x units each frame to simulate gravity). All I need from the physics engine is to prevent objects from overlapping.

Here's another way of putting it: I want to the physics engine to limit motion rather than have it attempt to move things in response.

I know how to write things like this in 2D, and I could probably do it for my game, but then, that's the sort of reason I wanted to use Unity in the first place (but in relation to Networking rather than physics.)

Comment
Add comment · Show 7
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 Ashish Dwivedi · Feb 12, 2014 at 03:44 AM 0
Share

Use "iskinematic" property of rigidbody to prevent forces and gravity. Can you explain what type of behaviour you want in your basic physics?

avatar image Domain · Feb 12, 2014 at 04:06 AM 0
Share

if the cubes have box colliders (and rigidbodies, I think) attached to them, they will collide with each other and not intersect.

avatar image destructivArts · Feb 12, 2014 at 04:08 AM 0
Share

Domain: Yes this is true but that implementation brings with it a lot of other interactions that I don't want.

Ashish: I'm editing the post to make it more clear.

avatar image destructivArts · Feb 12, 2014 at 04:39 AM 0
Share

Ok, here's what I've done. If theres a better way of doing this please tell me, because its effectively restricting my game to a 2D environment.

I put colliders on all objects. On the players, I put a rigidbody with constraints on Y motion, and XYZ rotation. It gets the job done, but I'd like to be able to have a 3D and this isn't particularly conducive to vertical motion.

avatar image supernat · Feb 12, 2014 at 04:46 AM 0
Share

I'm not 100% on this! but you don't want rigid bodies. Just attach colliders to the objects in the world. You only need one rigid body, the player. If you update the transform position manually, the physics won't kick in to limit your position. So you'll need to move your player through the rigidbody interface. You can modify the physics parameters for the scene through the Edit, project settings, physics menu. You might be able to tweak the values (for instance turn gravity off, set bounciness to 0, etc).

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by nesis · Feb 27, 2014 at 03:17 AM

You want Colliders (in your case, BoxCollider) with no Rigidbody on objects that you want to collide with, but not push around.

You want a Rigidbody and a Collider (in your case, BoxCollider is fine) on your player. For the Rigidbody, freeze rotation. To move the player, you should be able to use rigidbody.MovePosition(transform.position + someVelocity*Time.fixedDeltaTime) in a FixedUpdate() method in a script attached to your player. You want to use FixedUpdate() for moving objects, since that's the update method used for physics (since it runs at fixed intervals, and occasionally runs multiple times per frame to keep up with the Engine's physics update loop).

Flying off into space as you were saying would only happen if your player's collider ended up intersecting the other collider, perhaps from using transform.Translate() instead of rigidbody.MovePosition(). rigidbody.MovePosition() should never result in intersections with colliders that don't have rigidbodies, as far as I know.

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

23 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

Related Questions

Character Controller Platformer - Hang on to ledges 0 Answers

OnCollisionEnter isnt called when player lands on object 1 Answer

Collision with rigidbody inside a gameobject 0 Answers

Best way to do smooth object movement and obstacle detection+animation reset ? 0 Answers

Did triggers inside loaded gameobjects break in a recent update? 0 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