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
0
Question by MadManAdam · Apr 22, 2015 at 04:21 PM · 2dvector3scene

Elevator Motion Going Up Smooth, Going Down Not Smooth

Hey all, I'm having trouble wracking my brain trying to figure out why my elevator going up is smooth but coming down it is very jerky in motion. Any help would be greatly appreciated. Thanks for your time.

 using UnityEngine;
 using System.Collections;
 
 public class ElevatorController : MonoBehaviour {
 
     public float elevator_speed;
     public bool going_down = true;
     public bool going_up = false;
     public GameObject Elevator1;
 
     // Use this for initialization
     void Start () 
     {
         going_up = false;
         elevator_speed = 0;    
     }
         
     void OnCollisionStay2D(Collision2D coll)
     {
 
         var xfer = GetComponent<Transform>();
 
         if (coll.gameObject.tag == "hero")
 
         if (going_down == true)
          
         {
             elevator_speed = 2;
             xfer.Translate(Vector3.down.normalized * elevator_speed * Time.deltaTime); //going down is herky jerky
         
         }
 
         else if (going_down == false && xfer.position.y < -0.57f)                  
         {
             //gameObject {Get Elevator1}
             //elevator = gameObject.tag == "elevator";
             elevator_speed = 2;
             xfer.Translate(Vector3.up * elevator_speed * Time.deltaTime); //going up is smooth
         }
 
         if (coll.gameObject.tag == "elevator_bottom") 
         {
             going_down = false; // does not work
             elevator_speed = 0; // does not work
         }
     }
 }
Comment
Add comment · Show 3
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 Jessespike · Apr 22, 2015 at 05:19 PM 0
Share

Could it be cause of the normalization? "Vector3.down.normalized" Why not just Vector3.down?

You can also try copying your going up code and making it negative:

       xfer.Translate(-Vector3.up * elevator_speed * Time.deltaTime);
avatar image JoeStrout · Apr 22, 2015 at 05:22 PM 0
Share

Vector3.down.normalized is the same as Vector3.down. So, pointless, but also harmless.

avatar image MadManAdam · Apr 23, 2015 at 07:28 AM 0
Share

Thank you very much JoeStrout! Being very new to Unity I hadn't thought about that. @Jessespike - I was just trying different things and left normalized on there.

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by JoeStrout · Apr 22, 2015 at 05:24 PM

I bet it's because you're doing this motion in OnCollisionStay2D. The elevator only moves when something is colliding with it. Going up, it continues to collide with whatever's on top of it, so you get (mostly by accident) smooth motion. Going down, it departs from whatever's on top of it, stops moving, waits for whatever that is to fall down and hit it, and then moves again.

You should move your elevator in the Update (or perhaps FixedUpdate) method instead. If you need it to respond in some way to things colliding with it, then use the collision events only to set the flags that make it move (e.g. going_up and going_down).

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

Decrease players health depending on distance of enemy. 1 Answer

2D Sprite in a 3D Game 1 Answer

2d physics problem 1 Answer

Projectile speed changing by distance to target 1 Answer

Should I use Vector3D in a 2D 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