• 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 Jdogmaster · Apr 23, 2018 at 10:39 PM · collisioncollidertriggercolliderstriggers

changing gravity OnTriggerEnter

so basically all i want to do is when a rigidbody enters a triggercollider with the correct tag the gravity will change to how i want to change it. then once it exits the collider gravity will return to normal.

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

Answer by NEGATIVERAGDOLL · Apr 24, 2018 at 12:50 AM

Hello, are you wanting the gravity bool to be set on and off or are you wanting the mass to be changed? I will attach a script as an example in a minute.

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 NEGATIVERAGDOLL · Apr 24, 2018 at 12:54 AM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class ExampleGravity : $$anonymous$$onoBehaviour {
 
     public Rigidbody Rigid;
 
 
     
 
      void OnTriggerEnter(Collider other)
     {
         if (other.gameObject.CompareTag("Player"))
             Rigid.mass = 4; // This can be changed to whatever you want, this is if you want the mass changed;
         Rigid.useGravity = false; // This is if you want to turn the gravity off;
     }
 
 
      void OnTriggerExit(Collider other)
     {
         Rigid.mass = 1; // Back to normal here using mass;
         Rigid.useGravity = true; // This is if you want the gravity to be turned back on;
     }
 
 
     
 
     
 }

avatar image Jdogmaster · Apr 24, 2018 at 01:17 AM 0
Share

hey thanks man ya the reason i wanted to change gravity is cus ihave an up force script and when it was pulling objects up they were vibrating, so i was hoping that no gravity within the collider would prevent it from vibrating, and i think its worked! thanks man

avatar image NEGATIVERAGDOLL Jdogmaster · Apr 24, 2018 at 01:39 AM 0
Share

No problem, have fun creating it! :)

avatar image Jdogmaster · Apr 24, 2018 at 04:14 AM 0
Share

hey man would you $$anonymous$$d hleping me answer another question? so if you go to my questions look at the one that says "pulling objects accross collider". i have a collider script that pulls objects accross it, depending on the axis i want it to pull objects across when it enters the triggercollider. but i want it so that wherever an object enters, it will just be pulled strait across rather than along a specific axis. im not sure how hard that is to figure out, but i couldent figure it out so. thanks again man!

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

144 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 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 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 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 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 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

get only one colliding body 3 Answers

Problems with the Trigger Collider (randomly fictional) 1 Answer

How to Specify a Collider in OnTriggerStay function? 1 Answer

Does OnTriggerStay don't detect a collision with a non-trigger collider? 1 Answer

How do I use colliders and/or triggers to end the game? 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