#It is driving me crazy But this code
1 messages · Page 1 of 1 (latest)
Here
// Perform prepare logic
if (isPreparing)
{
prepareTimer -= Time.deltaTime;
if (prepareTimer <= 0)
{
isPreparing = false;
enemyState = GroupAIState.MakingAttack;
chargingDirection = (target.position - transform.position).normalized;
chargingDurationTimer = chargingDuration;
}
}
else if (enemyState == GroupAIState.MakingAttack)
{
Debug.Log("MakingAttack!");
transform.position = Vector3.MoveTowards(transform.position, transform.position + chargingDirection, moveSpeed * chargeMultiplier * Time.deltaTime);
chargingDurationTimer -= Time.deltaTime;
if(chargingDurationTimer <= 0)
{
enemyState = GroupAIState.RunningTowardsPlayer;
}
}
else if (Vector2.Distance(transform.position, target.position) <= attackRange && !isPreparing)
{
isPreparing = true;
enemyState = GroupAIState.PreparingAttack;
prepareTimer = prepareTime;
}
else if(enemyState == GroupAIState.RunningTowardsPlayer)
{
transform.position = Vector3.MoveTowards(transform.position, target.position, moveSpeed * Time.deltaTime);
}
I never get MakingAttack debug log even though I supposed to get it. why might it be?
There is a lot of external variables we cant see that would affect this
public enum GroupAIState
{
FleeingFromPlayer,
GroupingUp,
RunningTowardsPlayer,
PreparingAttack,
MakingAttack
}
public float moveSpeed = 5f;
public float attackRange = 4f;
public float prepareTime = 1.4f;
public float chargingDuration = 1.4f;
public float chargeMultiplier = 2f;
public float enemyGroupSearchRange = 20f;
public float enemyGroupFoundRange = 2f;
public float avoidRange = 5f;
public float enemyCountsAsGroupRange = 5f;
public LayerMask enemyLayerMask;
public LayerMask playerLayerMask;
private Transform target;
private Transform playerTr;
private bool isPreparing = false;
private GroupAIState enemyState = GroupAIState.GroupingUp;
private Vector3 chargingDirection;
private float chargingDurationTimer;
private float prepareTimer;
Ok but where do you change isPreparing
not related I hope. other states.
This is called in update right?
And can you show me what object the script is attached to
yes! and to clarify - my problem is that for some deleted weird reason I get isPreparing equals true in Running Towards Player state. The behaviour seems to be like in preparing state though. BUT IT IS SUPPOSED to just.. charge.. and attack...
Also charging duration timer never changes. WHY LOL
Alright well that should be plenty of info for someone to read- try using the rubber ducky method to find the issue maybe
Also
Try splitting code into smalll functions to make it easier to tell whats going on
That way i ususlly find bugs faster
I don't think this will help. I'm missing something fundamental here, like, logic error...
Fixed~
What was the problem
Also thats my point
Its easier to read code in pieces for me
And splitting into functions would make it easier to find logic problems
One of two things, no idea which though
Please elaborate