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 godrollo · Oct 28, 2013 at 07:01 PM ·

Moving platform

Hi there i am trying to make a moving platform that will start to move when the player is on the trigger, i got a working trigger but i can make the platform move. i started with this code but i have absolutely no idea how continue it, please help!!!!

var platform : Transform;

function OnTriggerEnter(col: Collider)

{

if(col.tag == "Player")

{

    col.transform.parent = transform.parent; 
 }

}

function OnTriggerExit(col: Collider)

{

 if(col.tag == "Player")
 {
    col.transform.parent = null; 
 }

}

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
0

Answer by tylo · Oct 28, 2013 at 07:43 PM

Try parenting the platform to the player, instead of the player to the platform. Then, the platform will move with the player when you use the player controls.

If this isn't the the behavior you want, then leave a comment on this answer and provide more info on what exactly you want the platform to do.

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 godrollo · Oct 28, 2013 at 11:22 PM 0
Share

Basicly I need that the platform moves when the player is on it and stays on it while moving from A to B; in case the player jumps off the platform this just stops.

avatar image
0

Answer by FirePlantGames · Oct 29, 2013 at 06:01 AM

try this:

 var platform : Transform;
 
 function OnTriggerEnter(col: Collider)
 
 {
 
 if(col.tag == "Player")
 
 {
 
    col.transform.parent = null; 
 }
 }
 
 function OnTriggerExit(col: Collider)
 
 {
 
 if(col.tag == "Player")
 {
    col.transform.parent = null; 
 }
 }


i don't really understand your problem though

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 godrollo · Oct 29, 2013 at 11:00 AM 0
Share

Ok maybe i did not be clear, i need a platform that moves only if the player is standing on it. btw your script works but the platform does not move.

avatar image
0

Answer by fafase · Oct 29, 2013 at 12:17 PM

Use a boolean to define when the guy is on:

    var isOn : boolean = false;
    var basPos : Transform;
    var target : Transform;
    var step : float = 0.5f;
 
    function OnTriggerEnter(col:Collider){
       if(col.tag == "Player")
           isOn = true;
    } 
    function OnTriggerExit(col:Collider){
       if(col.tag == "Player")
           isOn = false;
    }
 
    function Update(){
        if(isOn)
            transform.position = Vector3.MoveTowards(transform.position, target.position, step);
        else if(tranform.position != basePos.position)
            transform.position = Vector3.MoveTowards(transform.position, basePos.position, step);
    }

This is just a start . You can improve it later but you can strt off with this already.

Comment
Add comment · Show 3 · 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 godrollo · Oct 29, 2013 at 05:30 PM 0
Share

Ok i worked on it and now i got this:

using UnityEngine; using System.Collections;

public class $$anonymous$$ovingPlatform_CSHARP : $$anonymous$$onoBehaviour {

 public Transform DestinationSpot;
 public Transform OriginSpot;
 public float Speed;
 public bool Switch= false;
 
 void FixedUpdate()
 {
     if(Switch)
     {
         transform.position = Vector3.$$anonymous$$oveTowards (transform.position, DestinationSpot.position, Speed);
     }
     else
     {
         transform.position = Vector3.$$anonymous$$oveTowards (transform.position, OriginSpot.position, Speed);    
     }
     
 }
 
 void OnTriggerEnter (Collider other)
 
 {
     Debug.Log ("PlayerIn");
         
     if(transform.position == OriginSpot.position)
     {
         Switch = true;
         Debug.Log ("PlayerStarts");
     }
     
     if(transform.position == DestinationSpot.position)
     {
         Switch = false;
     }
     
     
     
 }

}

It's working but if i don't make the player child of the platform, he is catapulted random.

avatar image fafase · Oct 29, 2013 at 05:39 PM 0
Share

Yes but you had the parenting already.I thought you were after the moving of the platform.

avatar image godrollo · Oct 29, 2013 at 06:12 PM 0
Share

I really thank all of you for the help, the platform now moves when the player steps on it, and i don't even need to parent them!!!

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

17 People are following this question.

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

How to import the object from server to unity 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Material doesn't have a color property '_Color' 4 Answers

Setting Scroll View Width GUILayout 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