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
2
Question by adityajaix · Oct 31, 2020 at 07:30 AM · movementrigidbody2dplatformer

How to Move Platform up and down even if player stands on it.

I made the following script in bolt where the Platform moves down and up perfectly. But when the Player Stands on the object the platform falls like a light Wooden plank. I mean it can not handle the wait of the player. It falls in ground. I don't know how to move object without RigidBody. It would be better if i could get answer in Bolt. But solution in C# will also help.alt text

screenshot-5.png (270.3 kB)
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
Best Answer

Answer by yuvaansh · Oct 31, 2020 at 11:25 AM

@adityajaix I think you should create a moving platform script (C#) and then attach to your platform. You can use this code.

     [SerializeField] private Transform targetA, targetB; 
     private float speed = 1f; //Change this to suit your game.
     private bool switching = false;

     void Update()
     {
             if (!switching)
             {
                     transform.position = Vector3.MoveTowards(transform.position, targetB.position, speed * Time.deltaTime); 
             }
             else if (switching)
             {
                     transform.position = Vector3.MoveTowards(transform.position, targetB.position, speed * Time.deltaTime); 
             }

             if (transform.position == targetB.position)
             {
                     switching = true;
             }
             else if (transform.position == targetB.position)
             {
                     switching = false;
             }
     }

Also on your player it would be a bit jerky so to fix this try make it so that on your player script it shuld be void FixedUpdate instead of Update as FixedUpdate runs every physics frame and Update runs every frame.

I hope this would move that platform and help you :>)

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
1

Answer by adityajaix · Nov 02, 2020 at 06:50 AM

@yuvaansh Thanks for answering. I copied pasted your exact script but I got a lot of console errors (see image 1). I am complete new in C#. But I tried to convert the script in bolt ( see images 2alt text) and it is working perfectly.alt text


screenshot-6.png (161.4 kB)
screenshot-9.png (307.7 kB)
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 yuvaansh · Nov 02, 2020 at 09:01 AM 0
Share

@adityajaix

You need to fix some errors. Follow these steps to fix those

  • Put a open curly brace ( { ) just below where it is written as "public class" and another brace but the closing one ( } ) just below the last closing curly brace.

  • Wherever there is a curly brace you have to move all the code inside those curly braces 8 spaces (which is the tab key) so make all your code go 8 spaces this will also include braces. Also, in the Update function there is another pair of curly braces so you have to move the code more (8 spaces) and inside the Update function there is a if statement so inside it you have to move it 8 spaces more.

I hope this would help ;D

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

210 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 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 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rigidbody2D jumping off of slopes 0 Answers

Iam working on a platformer game and my player is getting stuck at random positions in the map by an invisible barrier. 1 Answer

I want to move the player once while he is jumping 1 Answer

Character dragging ground with it. 1 Answer

Rigidbody2D character movement problem 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