public override bool OnCollisionSolid(Entity other) { // check which direction the player relative to me int xDir = Auxs.Sign(other.posX - posX); int yDir = Auxs.Sign(other.posY - posY); // 50% chance if (Random.Range(0f, 1f) > 0.5f) { // This shows the message in the chat and then moves the NPC away because he's shoved ChatController.Show("Hey, quit shoving."); return(MoveTo(-xDir, -yDir, 0.3f)); } else { // This will make two successive messages ChatController.Show("Don't shove me, pal!"); ChatController.Show("Get out of my face."); // Move the other object (the player) away from the npc other.MoveTo(xDir, yDir, 0.3f); return(false); } }
public override bool OnCollisionSolid(Entity other) { // check which direction the player relative to me int xDir = Auxs.Sign(other.posX - posX); int yDir = Auxs.Sign(other.posY - posY); // 50% chance if (Random.Range(0f, 1f) > 0.5f) { // This shows the message in the chat and then moves the NPC away because he's shoved //ChatController.Show("Hey, how ya doing?"); //other.MoveTo(-xDir, -yDir, 0.3f); // We return true because the player shoved him, so now this square is available. // If you return false, it means that the player is not allowed to move into this space. return(false); } else { // This will make two successive messages ChatController.Show("I'm the shop guy. If you want something, just ask"); ChatController.Show("My friend there has a bit of a temper."); // Move the other object (the player) away from the npc //other.MoveTo(xDir, yDir, 0.3f); return(false); } }
void Update() { Vector2 myPos = transform.position; Vector3 targetPos = target.transform.position; float distance2D = Vector2.Distance(myPos, targetPos); dest = Vector3.Lerp( dest, targetPos, 1f / (distance2D + 1f / Constants.CAMERA_SPEED) + Constants.CAMERA_SPEED ); if (isFading) { fadeAlpha = Mathf.Lerp(0f, fadeDestColor.a, fadeTimer / fadeAnimTime); Color newColor = fadeGameObj.GetComponent <SpriteRenderer>().color; newColor.a = fadeAlpha; fadeGameObj.GetComponent <SpriteRenderer>().color = newColor; fadeTimer += Time.deltaTime; } Vector3 newPos = dest + cameraOffset; if (isShaking) { newPos += Auxs.RandomVector3() * shakingIntensity; } if (isCutscene) { cutsceneCurOffset = Vector3.Lerp(Vector3.zero, cutsceneDestOffset, cutsceneTimer / cutsceneAnimTime); // match camera angle cutsceneCurOffset.y *= Mathf.Cos(Mathf.Deg2Rad * cameraAngle); newPos += cutsceneCurOffset; cutsceneTimer += Time.deltaTime; } transform.position = newPos; UpdateAngle(); }