Play wont stay on moveing platforms
So i have been working on a puzzle game but am starting to run into an issue Ive been pushing off for to long. The player just wont stay with moving platforms... Ive try to make them the child of the platform and translate them using and offset. but regardless he just slides right off. I'm not sure if its a problem of the platform move script or the script used to make him stay but its really slowing down my work at this point an could use a hand.
Here is the move script
void Update()
{
if (shouldMove)
{
blockIsMoving = true;
rigid.position = Vector2.SmoothDamp(transform.position, moveToPos, ref velocity, Time.deltaTime * speed);
if (transform.position == moveToPos)
{
shouldMove = false;
blockIsMoving = false;
DirectionCheck();
}
}
}
Here is the script i tried to use to make him stay with the platform:
public class OnTriggerStay : MonoBehaviour {
public GameObject target = null;
public Vector2 offset;
public Vector2 currentPos;
void Start()
{
target = null;
}
void OnTriggerStay2D(Collider2D col)
{
target = col.gameObject;
offset = target.transform.position - transform.position;
}
void OnTriggerExit2D(Collider2D col)
{
target = null;
}
private void Update() {
currentPos = transform.position;
}
void FixedUpdate()
{
if (target != null)
{
target.transform.position = currentPos + offset;
}
}
}
Your answer
Follow this Question
Related Questions
How to stop previous animation? 1 Answer
Prevent Character from Falling off Edge when more than Half Off (2D) 1 Answer
Player passenger moving when being pushed by two platforms 0 Answers
Unity3D Fog Bug Please Help 0 Answers
Problems with player jumping (Welcome to Unity Answers The best place to ask and answer questions ) 0 Answers