• 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 aramusss · Mar 21, 2012 at 06:44 PM · collidercharacter controllerfallingelevatorcharacter motor

Falling Through an Elevator

Hello,

Im having an issue with a really simple elevator. I got a simple movement script (with character controller) in my player, and another script for the elevator:

 var pointB : Transform;
 private var pointA : Vector3;
 var speed = 1.0;
 
 
 
 function Start () {
     pointA = transform.position;
     while (true) {
         var i = Mathf.PingPong(Time.time * speed, 1);
         transform.position = Vector3.Lerp(pointA, pointB.position, i);
         yield;
     }
 }

My problem is that, when the elevator goes up with my player on it, the player just falls through, while when it goes down the player can stay on it. Both have a box collider attached.

I would like just to make the player go up with elevator. The rigidbodys didnt work, and a charactermotor neither.

Thanks!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by DaveA · Mar 21, 2012 at 08:21 PM

Classic. The ground moves up into your character's collider, so it's now 'below' the floor, and in freefall. You either need to translate the character up too, enough so gravity won't kick him down, and/or turn off gravity for him while riding; or reparent the character to the elevator while he's riding, and unparent when he gets out.

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
avatar image
0

Answer by aramusss · Mar 25, 2012 at 08:54 PM

Thanks for answering. I found that it could be solved with parenting both objects, but i have tryed many things and i cant solve it. Could you explain me how the script would be to parent both objects when they touch each other and then unparent when the other object exits? If you need more information, tell me. Thanks a lot!

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
avatar image
0

Answer by dre38w · Mar 26, 2012 at 01:18 AM

I was having a very similar problem, but just now figured it out. On your elevator, do you have a box collider? I had to zero out my center parameters in the Inspector on my elevator's box collider for it to stop falling through.

Also I hear you need to have the character controller's (if you are using one) collision to be slightly above the characters feet. So basically their feet are sticking out of the bottom of the character controller oh so slightly. Me personally have never had that issue with the controller's positioning but maybe that'll help you.

You said you figured out the script for the parenting deal? If not here's one. =)

 void OnTriggerStay(Collider col)
     {
         if (col.transform.tag == "Stick")
         {
             if (controller.isGrounded)
             {
                 print("stuck");
                 transform.parent = col.transform;
             }
         }
     }
 
     void OnTriggerExit(Collider col)
     {
         if (col.transform.tag == "Stick")
         {
             print("not stuck");
             transform.parent = null;
         }
     }
 Hope it helps.
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Player falling too fast for a collider to stop it 5 Answers

ball penetration 2 Answers

Character Controller won't collide with anything 1 Answer

Colliders on a Humanoid Player. 1 Answer

How to move the character controller and the moving platform it is standing on. 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges