Skip to content

Code/mihail lab/butterfly npc - #93

Open
Plintocrow wants to merge 21 commits into
FitiLsan:masterfrom
Plintocrow:code/mihail-lab/butterfly-NPC
Open

Code/mihail lab/butterfly npc#93
Plintocrow wants to merge 21 commits into
FitiLsan:masterfrom
Plintocrow:code/mihail-lab/butterfly-NPC

Conversation

@Plintocrow

Copy link
Copy Markdown
Contributor

бабочка, работает в CombatScene которая лежит в QuestTest

@Plintocrow Plintocrow closed this Oct 23, 2020
@Plintocrow Plintocrow reopened this Oct 24, 2020
@MSnihurska

Copy link
Copy Markdown
Contributor

Бабочке прописать свою собственную логику поведения. Можно без стейт машины.

Comment on lines +70 to +82
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;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Здесь и выше: настолько ли необходима бабочке возможность получать урон?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

получение урона убрал

Comment on lines +16 to +35
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем нужны эти константы?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лишние константы тоже убрал

Comment on lines +72 to +107
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);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Какую функцию выполняет этот код (как должно это выглядеть визуально)?
Можно ли упростить?
Также привести в соотвествие с CodeConvention (убрать магические числа и т. д.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

как упростить я так и не придумал.

Comment on lines +9 to +22
#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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем нужны все эти поля, и можно ли уменьшить их количество?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

лишние поля убрал

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants