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 DoctorMoney · Mar 12, 2013 at 03:12 PM · collisionmovementplatformerplatform

Collision problem

I'm making a game to just try and learn the ropes of unity as I'm too good with it. I'm making a simple platformer with an up and down moving platform. However when I set the platform to start moving when the player collides with it, nothing happens. I know there's nothing wrong with my movement script as it works perfectly when I have it set to be on at the start.

If someone could look at my collision code and tell me why nothing's happening it would be appreciated.

 var speed : float;                //speed at which the platform moves
 var startOn : boolean;            //If the platform should move at the start
 var pause : float;                //How long it pauses for
 var onTime : float = 0.0;        //amount of time that the object will move before pausing
 var up : boolean;                //direction the platform moves in
 var target : Transform;            //What must collide with the platform for it to start moving
 
 function OnCollisionEnter (collision : Collision)
 {
 
     if (collision.gameObject == target)
     {
         if (startOn == false)
         {
         startOn = true;
         }
     }
     
 }
 
 function Movement () {
 
     var controller : CharacterController = GetComponent(CharacterController);
 
         if (up == true)
         {
             controller.Move(Vector3.up * speed * Time.deltaTime);
         }
         
         if (up == false)    
         {
         controller.Move(Vector3.down * speed * Time.deltaTime);
         }
         
     if (Time.time > onTime) {
     
         startOn = false;
         yield WaitForSeconds (pause);
         onTime = Time.time + onTime;
         startOn = true;
         }
 
 }
 
 function Update () {
 
 if (startOn == true)
 Movement();
 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Catlard · Mar 12, 2013 at 05:04 PM

Are you parenting your player to the moving platform when he lands on it? That way, it will automatically stand on the platform correctly.

I don't know what kind of player you're using, but the player code that comes with Unity does not use a rigidbody, and one of your colliding objects must be a rigidbody for a collision data object to be generated. If that's what you're using (the out-of-the-box player), then you should just attach a rigidbody shape to the player so that it will also hit your moving platform at the same time as the player. Is that what's going on? Let me know.

Also, where are you changing the value of the variable "up"?

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 DoctorMoney · Mar 12, 2013 at 05:28 PM 0
Share

I was still working on the platform movement but i'm just about done with that part, the up variable is being changed by the user in the component menu and in the code i have now.

That said, I do have a rigidbody on the player object but when I go to stand on it it doesn't move.

Also I heard parenting objects to each other for moving platforms isn't the best choice, I want the player to be able to move around while he's on top of it.

Thanks for the reply

avatar image Catlard · Mar 12, 2013 at 05:33 PM 0
Share

Yeah, parenting the object to the platform will allow you to move the player on that platform...it works for me. Anyway. As far as rigidbody, make sure that the rigidbody object is actually the object that you're detecting a hit for. And try using other objects with rigidbodies. Is it just the player htis is happening with? Let me know.

avatar image DoctorMoney · Mar 12, 2013 at 05:55 PM 0
Share

I changed the "target" variable from a Transform to a Rigidbody and it didn't make a difference. It is testing to see if player collides with the platform unless my code is wrong for the collision detection.

I don't see how there is anything wrong with my script though. How would I go about doing the parenting?

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

11 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

Related Questions

How to move multiple dynamic gameobjects with one moving platform which is controlled by the player 0 Answers

Moving a 3D player without player controller 1 Answer

2d Platformer Jumping Not Working 1 Answer

How to prevent Character Controller from falling through moving Platforms? 4 Answers

One-way platform's side causes collision with Platform Effector 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