Code/mihail lab/butterfly npc - #93
Conversation
Mvp/april update
Code/rina marina/base npc
…able Code/rina s/rabbit killable
|
Бабочке прописать свою собственную логику поведения. Можно без стейт машины. |
| private void OnTakeDamage(Damage damage) | ||
| { | ||
| _context.ButterflyModel.CurrentHealth -= damage.PhysicalDamage; | ||
| Debug.Log("Butterfly got " + damage.PhysicalDamage + " damage"); | ||
|
|
||
| if (_context.ButterflyModel.CurrentHealth <= 0) | ||
| { | ||
| _context.ButterflyModel.IsDead = true; | ||
| Debug.Log("You killed a Butterfly! You monster!"); | ||
| _context.ButterflyModel.Butterfly.GetComponent<Renderer>().material.color = Color.red; | ||
| _context.ButterflyModel.Butterfly.GetComponent<InteractableObjectBehavior>().enabled = false; | ||
| } | ||
| } |
There was a problem hiding this comment.
Здесь и выше: настолько ли необходима бабочке возможность получать урон?
There was a problem hiding this comment.
получение урона убрал
| private const float TIME_UNTIL_CAN_CHANGE_STATE = 10.0f; | ||
| private const float IDLE_ANIMATION_DURATION = 3.0f; | ||
| private const float STOP_FLEEING_TIME = 2.0f; | ||
| private const float DANGEROUS_OBJECTS_MAX_COUNT = 4.0f; | ||
| private const float STOP_RETURNING_DISTANCE_FACTOR = 3.0f; | ||
|
|
||
| private const float HOP_FREQUENCY = 0.5f; | ||
| private const float MAX_HOP_FREQUENCY = 0.01f; | ||
| private const float FLEE_ACCELERATION_FACTOR = 1.3f; | ||
| private const float ROTATION_SPEED = 5.0f; | ||
| private const float HOP_FORCE_MULTIPLIER = 40.0f; | ||
| private const float MAX_ANGLE_DEVIATION = 40.0f; | ||
|
|
||
| private const float FRONT_RAYCAST_DISTANCE = 2.0f; | ||
| private const float DOWN_RAYCAST_DISTANCE = 1.0f; | ||
|
|
||
| private const float TURN_FORWARD = 0.0f; | ||
| private const float TURN_BACK = 180.0f; | ||
| private const float TURN_RIGHT = 270.0f; | ||
| private const float TURN_LEFT = 90.0f; |
There was a problem hiding this comment.
Зачем нужны эти константы?
There was a problem hiding this comment.
лишние константы тоже убрал
| butterfly.TimeLeft -= Time.deltaTime; | ||
| butterfly.TimeElapsed += Time.deltaTime; | ||
| if (butterfly.TimeLeft < 0.0f) | ||
| { | ||
| bool canHop = false; | ||
| if (butterfly.TimeElapsed >= MAX_HOP_FREQUENCY) | ||
| { | ||
| canHop = true; | ||
| } | ||
| if (canHop) | ||
| { | ||
| butterfly.ButterflyRigidbody.AddForce(new Vector3(0, 150, 0)); | ||
| Hop(butterfly.ButterflyRigidbody, butterfly.NextCoord); | ||
| butterfly.TimeLeft = HOP_FREQUENCY; | ||
| butterfly.NextCoord = new Vector3(Random.Range(-100, 100), Random.Range(10f, 80f), Random.Range(-100, 100)); | ||
| butterfly.TimeElapsed = 0.0f; | ||
| } | ||
| } | ||
| if (butterfly.ButterflyTransform.position.y <= -10 || butterfly.ButterflyTransform.position.y > 420) | ||
| { | ||
| butterfly.ButterflyRigidbody.velocity = new Vector3(0, 0, 0); | ||
| butterfly.ButterflyTransform.position = new Vector3(492, 1, 481); | ||
| } | ||
| if(butterfly.ButterflyTransform.position.y < 0.4f) | ||
| { | ||
| butterfly.ButterflyRigidbody.AddForce(new Vector3(0, 80, 0)); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
| private void Hop(Rigidbody rigidbody, Vector3 direction) | ||
| { | ||
| rigidbody.AddForce(direction); | ||
| } | ||
|
|
There was a problem hiding this comment.
Какую функцию выполняет этот код (как должно это выглядеть визуально)?
Можно ли упростить?
Также привести в соотвествие с CodeConvention (убрать магические числа и т. д.)
There was a problem hiding this comment.
как упростить я так и не придумал.
| #region Fields | ||
|
|
||
| public float TimeLeft = 1.0f; | ||
| public float TimeElapsed = 0.0f; | ||
| public float TimeElapsedAfterStateChange = 0.0f; | ||
| public float TimeElapsedAfterStartFleeing = 0.0f; | ||
|
|
||
| public float CurrentHealth; | ||
| public bool IsDead; | ||
|
|
||
| public List<Transform> DangerousObjects; | ||
| public Vector3 NextCoord; | ||
|
|
||
| #endregion |
There was a problem hiding this comment.
Зачем нужны все эти поля, и можно ли уменьшить их количество?
There was a problem hiding this comment.
лишние поля убрал
бабочка, работает в CombatScene которая лежит в QuestTest