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 Bruno-Fludzinski · Jun 16, 2012 at 12:00 AM · gameobjectcubemoving platform

Moving Platform

in my game I want to make a platform (cube) move between two objects, bouncing back and forth at at all times so my first person controller can get on it and move across to a different set of land can i please have a script to make it do that i havent figured one out yet. Thank you

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 JWdell · Sep 14, 2015 at 10:17 AM 0
Share

Sorry to bump an old thread but I've been testing out this moving platform code and for the most part it works perfect.

There is one issue with this code though. When you exit the trigger that is attached to the moving platform, any child objects of the parent that have a box collider do not return with the parent/player object.

While you can still move around and have normal controls as usual, the box collider child objects still remain stuck as children of the moving platform.

Is there a way to resolve that?

4 Replies

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

Answer by aldonaletto · Jun 16, 2012 at 12:44 AM

Just make a script to move the platform - the First Person Controller prefab already can ride moving platforms: if you jump over a moving platform, the FPC will move with it as you would expect.

There are several alternatives to create a moving platform - this is one of the easiest ways:

 var amplitude: float = 5; // platform excursion (+/- 5 units, in this case)
 var speed: float = 0.2; // movements per second
 var direction: Vector3 = Vector3.forward; // direction relative to the platform
 private var p0: Vector3;
 
 function Start(){
   p0 = transform.position;
   while (true){
     // convert direction to local space
     var dir = transform.TransformDirection(direction);
     // set platform position:
     transform.position = p0+amplitude*dir*Mathf.Sin(6.28*speed*Time.time);
     yield; // let Unity free till the next frame
   }
 }

Create a Unity's cube, adjust its dimensions and add this script to it, then tweak the parameters speed, amplitude and direction - the last one is a vector that defines the movement direction relative to the platform.

Comment
Add comment · Show 6 · 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 Bruno-Fludzinski · Jun 16, 2012 at 02:17 AM 0
Share

it says "Assets/Scripts/$$anonymous$$oving_Platform.js(12,48): BCE0017: The best overload for the method 'UnityEngine.$$anonymous$$athf.Sin(float)' is not compatible with the argument list '(UnityEngine.Vector3)'." and "Assets/Scripts/$$anonymous$$oving_Platform.js(12,28): BCE0051: Operator '+' cannot be used with a left hand side of type 'UnityEngine.Vector3' and a right hand side of type 'float'. "

avatar image Bruno-Fludzinski · Jun 16, 2012 at 02:36 AM 0
Share

fixed the error but it doesnt work, u said that there are more than one way. can i have another? thanks for the help

avatar image aldonaletto · Jun 16, 2012 at 06:10 PM 1
Share

I was almost sleeping over the keyboard, and made some stupid mistakes - that's the right instruction:

 transform.position = p0 + amplitude * dir * $$anonymous$$athf.Sin(6.28 * speed * Time.time);

Answer fixed!

avatar image Bruno-Fludzinski · Jun 17, 2012 at 01:44 AM 0
Share

thank you it works now-- i have moving platforms and elevators thanks to you! thanks

avatar image 8l33d · Oct 01, 2013 at 03:00 PM 0
Share

I dont understand why but the First Person Character doesnt moves with the platform. For example when the things moves forward and backwards i have to use the controls (press w or s) to go with it, otherwise i fall.On a platform which is moving on y coords, things are diffeent. In the first step i "feel" the collission, but as soon as it moves up i glitch trough the platform and stay on the floor. Any suggestions?

Btw thanks a lot for the script!

Show more comments
avatar image
1

Answer by Berenger · Jun 16, 2012 at 12:56 AM

If you don't like iTween, use an AnimationCurve. The result of Evaluate will be between 0 an 1, you can use it in a Lerp.

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 rubenpvargas · Jun 16, 2012 at 12:14 AM

Use itween, it´s free :) http://itween.pixelplacement.com/index.php

Comment
Add comment · Show 1 · 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 Bruno-Fludzinski · Jun 16, 2012 at 12:35 AM 0
Share

no cant you just give me a script i dont like itween

avatar image
0

Answer by theVirtunaut · Jun 13, 2014 at 06:42 PM

whats the 6.28 in there for?

Comment
Add comment · Show 1 · 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 k3min · Nov 10, 2014 at 06:41 PM 0
Share

π × 2 ≈ 6.28

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Collision with specific object... 2 Answers

Detection if a GameObject is below you or next to you? 1 Answer

Melee-like function? 1 Answer

GameObject AddComponent and MonoBehaviour problem 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