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 Wesley21spelde · Feb 14, 2016 at 11:08 AM · scripting problemtriggertimegravity

time dilation & gravity Effect Not working propperly

Hey guys i tried to make a time dilation & gravity Effect. The Effect works Verry Simple but works the only problem is that enything is affected by the effect. and it should be only Objects within the Field(Trigger) How can i fix this

also if somone knows a better way of doing this. or for a better effects please let me know thanks

 using UnityEngine;
 using System.Collections;
 
 public class LowGravityZone : MonoBehaviour {
 
     // Use this for initialization
     void Start () {
         Physics.gravity = new Vector3(0, -10.0F, 0);
         Time.timeScale = 1.0F;
     }
     
     // Update is called once per frame
     void Update () {
     
     }
 
     void OnTriggerEnter(Collider other)
     {
         Physics.gravity = new Vector3(0, -1.0F, 0);
         Time.timeScale = 0.07F;
     }
 
     void OnTriggerExit(Collider other)
     {
         Physics.gravity = new Vector3(0, -10.0F, 0);
         Time.timeScale = 1.0F;
     }
 }
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 WillNode · Feb 14, 2016 at 04:28 PM

You can do that by put a custom script for manage the acceleration of gravity on each object. simply attach this to your object:

 [RequireComponent(typeof(Rigidbody))]
 public class CustomGravity : MonoBehaviour
 {
     public Vector3 gravity;
     public float timeScale = 1;
     Rigidbody Body;
 
     void Start ()
     {
         Body = GetComponent<Rigidbody>();
         Body.useGravity = false;
     }
 
     void FixedUpdate()
     {
         Body.velocity += gravity * Time.fixedDeltaTime * timeScale;
     }
     
     public void ChangeTimeScale(float now)
     {
         //The tricky part: simply rescale the velocity
         //But try never put the value to zero.
         Body.velocity *= now/timeScale;
         timeScale = now;
     }
 }

and for your LowGravityZone is done like this:

 public class LowGravityZone : MonoBehaviour {
      void Start () {
 
      }
  
      void OnTriggerEnter(Collider other)
      {
         CustomGravity cg = 
             other.gameObject.GetComponent<CustomGravity>();
         //It's not clear whether you want to change the gravity 
         //since you also slows down the time.
         cg.gravity = new Vector3(0, -1.0F, 0);
         cg.ChangeTimeScale(0.07F);
      }
  
      void OnTriggerExit(Collider other)
      {
         CustomGravity cg = 
             other.gameObject.GetComponent<CustomGravity>();
         cg.gravity = new Vector3(0, -10.0F, 0);
         cg.ChangeTimeScale(1F);
      }
 }






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

43 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

Related Questions

How to disable player gravity 2 Answers

C# | How to disable gravity for a certain amount of time? 1 Answer

Animation Problems 1 Answer

Animation Trigger is saved even if it is not used immediately. 1 Answer

Collison detection not working? 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