I'm trying to make a jumping spider enemy for a side-scrolling 2D game. I want the enemy to jump, wait, then jump again. the scripting that I have put together causes the spiders to float away instead.
void Update(){
if(!seesPlayer && !patrolling)
{
patrolTimer -= Time.deltaTime;
}
if (patrolTimer <= 0f && !patrolling) {
patrolling = true;
Patrol ();
}
}
void Patrol()
{
moveDistance = Random.Range (-moveSpeed, moveSpeed);
myRigidbody2D.velocity = new Vector2(moveDistance, jumpHeight);
patrolTimer = Random.Range (.1f, 2f);
patrolling = false;
}
↧