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 /
avatar image
0
Question by Daev · Apr 07, 2010 at 07:29 PM · collideristrigger

changing state of collider

okay I'm going to try this again because I'm still stuck, and unfortunately appending to unityAnswers is almost unreadable.

I am trying to have a game where my foe throws things at my character. When they are in the air, I want my character to be hit and lose a life. However if they are sitting on the ground I want to be able to pick the stuff up.

I start with the objects and add the function below, with the attempt to turn the trigger to false if it hits my false (and floating) ground plane about half a foot above the ground.

I cannot figure out how to change the state of the variables, like the collider's trigger.

function OnTriggerEnter(hit : Collider) {

if (hit.gameObject.tag == "TRIGGER_OFF" ) {

 collider.isTrigger=false;

 }

}

Please note. I could use some feedback on what script I'm writing, vague suggestions to try this or that without some pointers on how to go about just leave me scratching my head. I've tried programming this behavior in about 50 different ways so far and cannot get it to work.

thanks

Daev

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by e-bonneville · Apr 07, 2010 at 07:46 PM

One approach is to delete the foe-thrown object when it hits the ground and replace it with a throwable object, like this:

var deadReplacement : Rigidbody;

function OnCollisionEnter (collision : Collision) { var contact : ContactPoint = collision.contacts[0]; var rotation = Quaternion.FromToRotation(Vector3.up, contact.normal);

 Destroy(gameObject);  
     if (deadReplacement) {
        var throwableObject : Rigidbody = Instantiate(deadReplacement, transform.position, transform.rotation);
        throwableObject.rigidbody.velocity = rigidbody.velocity;
        throwableObject.angularVelocity = rigidbody.angularVelocity;
     }

}

You then put all the scripts for the throwable object on the replacement, and put the scripts for the foe-thrown object on the original.


EDIT:

The way this works is you have two objects. One object will be deleted when it hits the ground. The other, deadReplacement, will be instantiated in its place. For example, say the original object is a cube. If you put a sphere as deadReplacement, the cube will change into a sphere when it hits the ground, but will maintain the objects speed and such to keep the physics realistic. You could then put a pick-up script on deadReplacement that won't be enabled until it hits the ground. That way, the first object in the air can have a script that will decrease life on contact, but when it hits the ground will be pickup-able.

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 Daev · Apr 07, 2010 at 08:36 PM 0
Share

Hi I'm going to try this out but I may have some questions, thanks for the quick response.

avatar image Daev · Apr 07, 2010 at 09:02 PM 0
Share

okay I've tried this but I'm not really sure what I'm looking at.

What would be the collision check or does this function mean that it just needs to contact anything.

Also, I don't need the object to be throwable I just need to pick it up it has come to a rest or at least made contact with the ground.

I basically made a duplicate object to my thrown object called deadReplacement. Then I attached the function above to the original object that I'm throwing.

i'll keep working at it.

thanks

avatar image e-bonneville · Apr 08, 2010 at 02:20 AM 0
Share

@Daev I've edited my answer for you.

avatar image e-bonneville · Apr 08, 2010 at 02:27 AM 0
Share

@Daev Yes, the function is enable whenever you hit anything. You can fix that by using tags to check if it hits the ground or not. If you need more help, just let me know, I'm glad to be of service.

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

No one has followed this question yet.

Related Questions

A Collider problem. 1 Answer

Rigidbody bounce or character controller istrigger issues 0 Answers

Is Triggered Collider Issue 1 Answer

Possible Unity BUG? Or am i missing something 1 Answer

Ignore Collision after passing a collider 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