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 kamilkot · Jan 22, 2017 at 09:46 PM · rotationtransformorientationlocalglobal

Simulating different gravity, how to make falling platform fall in the desired direction?

Hello, Im doing a 3d platformer with gravitation changing in certain places. There are platforms that should fall after certain amount of time after player touches it. If the platform is oriented in the part of level where i changed gravitation for player, i want it to start falling in current players down direction.

Im using transform.Translate(fallingDirection fallingSpeed Time.deltaTime); to make platform fall.

I tried using -transform.up as the local downwards for collapsing platforms. While debug.ray made while using it looks fine, platform rotated 90 degrees on x axis starts goin up.

I managed to do it using public Vector3 fallingDirection and manually finding in Inspector which direction will get me the desired fall.

But i got so confused and i dont like this solution cause its not elegant and potentially problem making. Can anybody help me, and explain what am i doing wrong maybe ?

full code of collapse platform script : using System.Collections; using System.Collections.Generic; using UnityEngine;

public class CollapsingPlatform : MonoBehaviour{

 //////////////VARIABLES//////////////////////////////////
 private bool startFalling = false;
 public Vector3 fallingDirection;
 public float fallingSpeed;
 public float waitTime;
 private float startFallingTime;
 private bool contacted = false;
 ///////////////START///////////////////////////////////
 void Start(){

 }
 //////////////ONTRIGGERENTER///////////////////////////////////
 void OnTriggerEnter(Collider other){
     if(other.tag == "Player")
     {
         startFalling = true;
         if (contacted == false)
         {
             startFallingTime = Time.time + waitTime;
             contacted = true;
         }
     }
 }
 ////////////////UPDATE//////////////////////////////////
 void Update (){
     Debug.DrawRay(transform.position, transform.up, Color.green);

     if(startFalling == true && Time.time > startFallingTime)
     {
         transform.Translate(fallingDirection * fallingSpeed * Time.deltaTime);
     }
 }

}

Platform game object has: box collider to interact with player, so that he can stay on it, trigger collider to trigger falling, mesh of course, and rigidbody added because i couldnt get my boundary->destroy script working in different way.

Thank you for any help in advance, Greetings

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 IgorAherne · Jan 22, 2017 at 11:58 PM

Assuming the player rotates as the gravity changes, then you can update the falling direction as follows:

  if(other.tag == "Player")
      {
          fallingDirection  =  other.transform.up; //update the direction for the platform to match up-diction of the player

          startFalling = true;
          if (contacted == false)
          {
              startFallingTime = Time.time + waitTime;
              contacted = true;
          }
      }

If your player never rotates, and it's only the gravity that's changing, then you can do:

 fallingDirection   = currentGravityDirection; //gravity which you've set for player


If you would want to change the entire gravity, use Physics.gravity

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Local Rotation and then Global Rotation 1 Answer

Maya objects with different transforms. 1 Answer

bone rotations changed in 4.3.2 inspector? 0 Answers

use world axis when using transform.rotate 3 Answers

Transform global quaternion from local quaternion 2 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