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 Adam Bruns · Apr 03, 2010 at 08:40 AM · collisionmovementphysics

Ride an elevator?

In my game i have 4 pistons set up, they raise and lower themselves and you have to jump from one to another. To raise them and lower them i have this script set up:

private var startPoint : Vector3; var endPoint : Transform; var duration : float = 5.0; private var startTime: float; private var Point2: Vector3; private var position2 : boolean = false; private var number1: int = 0; private var number2: int = 0;

function Awake(){ startPoint = transform.position; Point2 = endPoint.position; startTime = Time.time; } function Update () { if(number1 ==1){ startTime = Time.time; } if(number2 ==1){ startTime = Time.time; } if(position2){ transform.position = Vector3.Lerp(Point2, startPoint, (Time.time - startTime) / duration); } else { transform.position = Vector3.Lerp(startPoint, Point2, (Time.time - startTime) / duration); } if(transform.position == Point2){ number1 +=1; number2 = 0; position2 = true; } if(transform.position == startPoint){ number2 +=1; number1 = 0; position2 = false; }

}

Well they raise and lower just fine and that works out, but if you stand on them and dont move when a piston raises you just stay at that height, until you go through it, then you fall. Though, when you move you raise up with it, is there a way to make it constantly push you up, like riding an elevator (hence the name of the question)?

Comment
Add comment · Show 1
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 straydogstrut · Apr 03, 2010 at 12:08 PM 0
Share

Have you seen this question? http://answers.unity3d.com/questions/694/charactercontroller-falls-through-or-slips-off-moving-platforms I think it may point you in the right direction

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by spinaljack · Apr 17, 2010 at 05:53 PM

You can attach a raycast on the character that points down, when the hit property returns that you're on an elevator you can then update the character's position relative to the platform. The alternative would be to have the platform detect if a character is on it which may be more complicated seeing as any number of characters can be on a platform and a character can only really be on one platform at a time.

Something like this:

 var platPos;
 var ray = new Ray (transform.position, -vector3.up);
 var hit : RaycastHit;
    if (collider.Raycast (ray, hit, 5.0)) {
        if(hit.collider.tag == "platform"){
           platPos = hit.collider.transform.position;
        }
    }

Then do a lateupdate updating the character's position with the change in the platform's position.

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 runevision · Apr 03, 2010 at 02:35 PM

Like straydogstrut wrote in a comment, see this question and the answers:

CharacterController falls through or slips off moving platforms

Comment
Add comment · Show 2 · 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 Adam Bruns · Apr 03, 2010 at 05:20 PM 0
Share

Cant seem to get that to work on my FPS controller, are there any parts that are on the 2D tutorial script that i need to make this work?

avatar image Adam Bruns · Apr 06, 2010 at 02:53 AM 0
Share

Question still needs answering, i couldnt get it to work, any help?

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

No one has followed this question yet.

Related Questions

Every time my character hits or touches the walls he gets stuck or acts as if the object the character hit was a magnet. 0 Answers

Keep Horizontal Momentum after Jump 2 Answers

How having correct bounce on a rotating pinwheel(it's more complicated)? 0 Answers

How to Have Two Child Objects of One Parent Detect Collisions Between Eachother. 1 Answer

Stopping my player from moving when hitting a wall. 5 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