Hello
I’m creating a game, and I created an bridge that move to right and left.
I want my player when colliding with the bridge go along on the move.
I’m trying set position player with position of the bridge, but when my player is on the bridge his doing small jumps
How can I do this ?
I’m trying this.
public class MoveBridge : MonoBehaviour {
private bool isLeft = false;
public float speed = 5f;
public float delaySpeed;
private float moveTime;
public GameObject player;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
move();
}
private void move(){
moveTime += Time.deltaTime;
if (moveTime <= delaySpeed){
if (isLeft){
gameObject.transform.Translate(-Vector2.right * speed * Time.deltaTime);
}else{
gameObject.transform.Translate(Vector2.right * speed * Time.deltaTime);
}
}else{
isLeft = !isLeft;
moveTime = 0f;
}
}
void OnCollisionStay2D(Collision2D coll){
if(coll.gameObject.name.Equals("PlayerObject")){
player.transform.position = gameObject.transform.position;
}
}
}