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
1
Question by NoTakeful · Dec 07, 2012 at 02:28 AM · bodyrigid

How to make a rigid body fall when space is pressed and freeze on trigger enter?

I am kind of new to coding so this may be pretty simple but I've tried a lot of different things to try and get it to work.

I have 2 objects attached with a rope. They are rigid bodies and I want them to both be frozen, (or kninematic) on the start of the game. As soon as I hit the spacebar I want them to drop and when one of the objects enters an area (a red cube I made as a non colliding trigger) to freeze and the other object to keep moving. any ideas? Thanks.

Comment
Add comment · Show 1
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 MountDoomTeam · Dec 07, 2012 at 02:38 AM 0
Share

http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-is$$anonymous$$inematic.html

logically it sounds like you want to do-

if getkeydown spacebar, iskinematic = false

on trigger enter, iskinematic = true

what kind of rope?

if u want to drop ur 2 things, use a blue cube. at least its a drop cubes game notakeful...

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by aldonaletto · Dec 07, 2012 at 02:46 AM

You could use something like this attached to the trigger object:

 // drag the rigidbodies here
 var rb1: Rigidbody; 
 var rb2: Rigidbody;
 
 function Start(){
   // freeze the rigidbodies:
   rb1.isKinematic = true;
   rb2.isKinematic = true;
 }
 
 function Update(){
   // unfreeze the rigidbodies when space pressed:
   if (Input.GetKeyDown("space")){
     rb1.isKinematic = true;
     rb2.isKinematic = true;
   }
 }  
 
 function OnTriggerEnter(other: Collider){
   var rb = other.rigidbody; // who entered the trigger?
   if (rb == rb1 || rb == rb2){ // if it's one of our rigidbodies...
     if (!rb1.isKinematic && !rb2.isKinematic){ // and both are active...
        rb.isKinematic = true; // freeze the rigidbody that entered first
     }
   }
 }

This code will release the rigidbodies to fall when space is pressed, and when one of them touches the trigger, it gets frozen - but the other keeps falling, even if it passes through the trigger volume.
NOTE: Make sure that Use Gravity is checked in both rigidbodies!

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

11 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

Related Questions

rigid body problem 1 Answer

Freezing Rigidbody Rotation 1 Answer

Enemy AI and Rigid Bodies 0 Answers

Colliding with static model 1 Answer

Rigid body enemy 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