TowerDefense ToolKit 4

A simple hack you can do is to add a coroutine to set the move speed of the unit to 0 for the duration of the hit animation.

You can call this from AnimPlayHit() in Unit.cs, which is the function to play the hit animation. You can even pass the duration of the animation to the coroutine so the stop duration auto matches your hit animation. Something like this:

protected void AnimPlayHit(){
	if(animator!=null && clipHit!=null){
		animator.SetTrigger("Hit");
		StartCoroutine(StopDuringHitAnimation(clipHit.length));
	}
}
		
IEnumerator StopDuringHitAnimation(float delay){
	float cache=statsList[level].speed;
	statsList[level].speed=0;
	yield return new WaitForSeconds(delay);
	statsList[level].speed=cache;
}

Thank you very much Song.

Hi All,

I have two issues;

1. Second resource on tower build popup disappears after I mouse over ability popup
Iā€™ve checked and this also happens in fresh TDTK project without any modifications. Easy to reproduce; create a new project. Install TDTK and create a new scene Tool-> TDTK ā†’ News scene. Without any modifications on code you can see this issue.
Here is the video:
Second Resource To Build Tower Disappears After Ability Popup

2. Creep stops suddenly on a path
Unfortunately this is the biggest issue Iā€™ve faced until now. Creep stops but animation continues. You can check on this video:
Creep stops in the middle of the path

I think there is a similar post for the 2nd issue in this topic. Itā€™s posted by someone else but I couldnā€™t see the solution.

Thanks in advance,
Fatih

BTW, If I choose Endless mode or Generate On Start options on SpawnEditor, creep stop happens more frequent than manual waves.

The second issue is probably because of the IEnumerator StopDuringHitAnimation() change Iā€™ve done above.
Iā€™ve performed test for 2hrs. Issue is gone when I revert back Unit.cs and it appears again if I include StopDuringHitAnimation.

Iā€™ve sent you a fix for the first issue.

As for the second one. Iā€™m not quite sure whatā€™s wrong. Itā€™s either the cache value being 0 or the delay value is somehow very long. But please try this:

IEnumerator StopDuringHitAnimation(float delay){
	float cache=statsList[level].speed;
	
	if(delay>0 && cache!=0){
		statsList[level].speed=0;
		yield return new WaitForSeconds(delay);
		statsList[level].speed=cache;
	}
	else{
		Debug.Log("StopDuringHitAnimation  value error?   delay-"+delay+"   cache_speed-"+cache);
	}
}

Hopefully with that, it wonā€™t break the unit, or at least it will tell us whatā€™s wrong.

Thanks Song. UI Tooltip is working properly now.

Iā€™ll check StopDuringHitAnimation and let you know how it goes.

I get ā€œsubWpIdx exceed subpath length?ā€ warning on some scenes. Does anyone know what it means?

Iā€™m not sure. Do you have the full warning message?

Sure, it usually happens when I place platforms inside path and especially when I use auto generated spawn.

Here are the warning screenshot and code details.

Warning message on console:

UnitCreep.cs line 221:

UnitCreep.cs line 396:

Sorry for the slow respond.

Iā€™m not sure how it happen. I canā€™t reproduce the warning myself. But unless you see the creep exhibiting strange pathing behaviour, it should be harmless.

No, I havenā€™t noticed any major issues. Iā€™ll ignore it for now. Thanks.

Hi Again Song,
Finally I had time to test hit anim stop again.

Delay is -1
I donā€™t know if this is the reason for creep freeze in the middle of the path.
Here is the screenshot:

The value of delay is 1. Thatā€™s fine. The problem is the value of speed (cache) is somehow 0.

I think I know what happened. Iā€™m guessing this happen when another attack hit the creep when it stop for the first time. You can try this:

private bool stopDuringHit=false;

IEnumerator StopDuringHitAnimation(float delay){
	if(stopDuringHit) yield break;
	
	stopDuringHit=true;
	
	float cache=statsList[level].speed;
	
	if(delay>0 && cache!=0){
		statsList[level].speed=0;
		yield return new WaitForSeconds(delay);
		statsList[level].speed=cache;
	}
	else{
		Debug.Log("StopDuringHitAnimation  value error?   delay-"+delay+"   cache_speed-"+cache);
	}
	
	stopDuringHit=false;
}

I should say that while this may fix the problem. The simple logic with this function may not be perfect if you have multiple towers attacking one creep at the same time. The creep will only stop in response to the first attack but ignore the rest until it starts moving again.

Thank you Song, Iā€™ll give that a try.