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
1
Question by Mr-Jester-XIII · May 30, 2012 at 04:59 PM · triggermovingplatformswith

How to trigger a Moving Platform with a collider?

Hey, So I'm making a 2.5D sidescroller and there is a section where i need a lift to start moving down when the player stands on it.

Ive used the moving platform script straight from the 2D sidescroller tutorial and it works perfectly fine on its own, i just need a method of stopping it from running until the player gets there, is this possible?

Im also using the standard 'ActivateTrigger' script straight from the general scripts.

Please Help ASAP, I'm sure its a simple solution I'm just new to Javascript and Unity as a whole and can't seem to figure it out for myself.

All answers appreciated.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by reptilebeats · May 30, 2012 at 05:19 PM

the most simplest solution i can think of is to make an animation so basically just animate it moving from the top to bottom and turn loop off and start on play off.

then put a script on a collider that says

 function OnCollisionEnter(col : Collision){
 if(col.gameObject == gameObject.Find("your character")){
 animation.Play();// if animation isnt on this then you will have to find it
 enabled = false;
 }
 }
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 aldonaletto · May 31, 2012 at 08:49 AM

You should use a different script to control the platform - MovingPlatform.js relies on the current Time.time to set the platform position, thus it can't be stopped. A good solution is to use a coroutine to do the job: once called, it runs in the background, moving the platform to the target point without any extra effort.
To control the movement, create a trigger volume: create a cube, child it to the platform, reset its position/rotation, then adjust its size and position to cover the platform. In the Inspector, set Is Trigger to make it a trigger, and clear the Mesh Renderer checkbox to make it invisible. Finally, add the script bellow to the trigger (not to the platform!):

var targetA : Transform; // drag here the empty game object that defines the start pos var targetB : Transform; // drag here the object that defines the end position var speed : float = 0.1; // speed (0.1 means 10s per movement)

private var curTarget: Transform;

function Start(){ // initialize platform at targetA position: curTarget = targetA; // set curTarget... // and move quickly the parent platform to its position (if not already there) MovePlatform(transform.parent, curTarget, 10); }

private var moving: boolean = false; // flag that warns when the platform is moving

function MovePlatform(platform: Transform, dest: Transform, vel: float){ moving = true; // set a flag to indicate "I'm moving" var from = platform.position; // get start position... var to = dest.position; // and end position... var t: float = 0; // initializes timer = 0 while (t < 1){ // cycle ends when timer reaches 1 t += Time.deltaTime vel; // advance timer at the desired speed... if (t > 1) t = 1; // and clamp it to 1 // then smooth it near to 0 and 1 with a cosine function: var weight = 0.5 (1 - Mathf.Cos(t * Mathf.Pi)); // set the platform position according to weight (0=from, 1=to) platform.transform.position = Vector3.Lerp(from, to, weight); yield WaitForFixedUpdate(); // let Unity free till the next fixed update } moving = false; // movement finished - clear the flag }

function OnTriggerEnter(other: Collider){ if (moving == false){ // if platform not already moving... if (curTarget == targetA){ // swap targets... curTarget = targetB; } else { curTarget = targetA; } // and move platform to the new target: MovePlatform(transform.parent, curTarget, speed); } } Use it like you were using MovingPlatform.js: drag to targetA and targetB the empty objects you've created to define the start and end positions. The platform starts at targetA position, and will move to targetB when any object enters its trigger volume. It will stand at targetB until any object enters the trigger again, what will make it go back to targetA position, and so on.

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 trinitysj96 · Jan 30, 2013 at 05:17 AM 0
Share

can this be modified to use say 4 different waypoints and do the same thing?

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

7 People are following this question.

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

Related Questions

Moving an object between two positions (C#) 1 Answer

Box Trigger and Mesh Collider on one object. 1 Answer

Moving trigger collider and raycast doesnt detect anything 0 Answers

How Can I Make a Moving Object with a trigger reaction ? [C#] 1 Answer

Moving Platforms + Third Person Controller 0 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