I’ve uploaded a video to demonstrate what happens. (Jump to 00:47)
https://www.youtube.com/watch?v=hZIYI6yhjZ4&feature=youtu.be
I want the rock to move right, in a straight line. Then fall down if there is a hole in the surface. Not do the confusing jumpy thing.
And btw. the cubes which the rock is standing on, are also of the same “ground” prefab in both levels.
Any help will be appreciated ![]()
And here is some of the code I am using for my “Rock”.
private PlayerController player;
private bool dropped = false;
private float originalY;
private Vector2 newPos;
private float speed = 5f;
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "Player")
{
if (player.shape == 4)
{
this.newPos.x++;
StartCoroutine(MoveRock(this.newPos, this.speed));
}
}
}
void Start () {
this.originalY = this.transform.position.y;
this.newPos.x = this.transform.position.x;
player = GameObject.Find("Stickman").GetComponent<PlayerController>();
}
IEnumerator MoveRock(Vector2 newPos, float speed)
{
float timer = 0f;
while (timer < 0.5f) //0.5
{
timer += Time.deltaTime;
yield return null;
float step = speed * Time.deltaTime;
if (dropped == false)
{
this.transform.position = Vector2.MoveTowards(this.transform.position, newPos, step);
}
if (transform.position.y < originalY - 0.1f)
{
dropped = true;
}
}
}
If you also think this is some kind of dark magic, please upvote this question.
Had no effect :(
– GimLeeCheck my edit versión maybe is that. Hope it is.
– RyujoseNo, because the ground is also the same in the 2 scenes.
– GimLee