- Home /
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.
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 :>)
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 2) and it is working perfectly.alt text
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
Follow this Question
Related Questions
Rigidbody2D jumping off of slopes 0 Answers
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