Hello everyone
I made a script that allows to make fight “Turn based Unity game rpg”
here it is
public float SpeedAttack = 5.0f ;
public Transform OffsetEnemy;
public void Attack(){
StartCoroutine (AttackCouroutine());
}
IEnumerator AttackCouroutine(){
anim.Play ("wait");
yield return new WaitForSeconds( 2.0f );
anim.Play ("shiftingtoAttack");
float Step = SpeedAttack * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position, OffsetEnemy.position , Step );
yield return new WaitForSeconds( 1.0f );
anim.Play ("Attacking");
}
the problem is that my charcter remains in his place
Hello @lyokoguerier_unity ,
You are only calling Vector3.MoveTowards
once in your code. This means that your system will only move the player a portion of the intended distance (See Vector3.MoveTowards for more details). Try either moving the full distance in one go, or repeatedly call Vector3.MoveTowards
for the desired effect.
Best of luck, and let us know how it goes!
thanks a lot for your help
my character no longer applies his first line for his first destination
I tried to apply it in these two sence but nothing
private float Cur_CollDown = 0.0f;
private float Max_CollDown = 5.0f;
public enum TurnState
{
PROCESSING ,
ADDTOLIST ,
WAITING ,
SELECCTION ,
ACTION,
DEAD,
}
public TurnState CurrentState;
IEnumerator AttackCouroutine((){
anim.Play ("wait");
yield return new WaitForSeconds( 2.0f );
anim.Play ("shiftingtoAttack");
float Step = SpeedAttack * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position, OffsetEnemy.position , Step );
yield return new WaitForSeconds( 1.0f );
anim.Play ("Attacking");
yield return new WaitForSeconds( 2.0f );
float StepReturn = SpeedAttack * Time.deltaTime;
transform.position = Vector3.MoveTowards (transform.position, -OffsetEnemy.position , StepReturn );
Cur_CollDown = 0.0f;
CurrentState = TurnState.PROCESSING;
}
void Start () {
CurrentState = TurnState.PROCESSING;
}
void Update () {
switch (CurrentState) {
case (TurnState .PROCESSING):
UpgradePrgressBar ();
break ;
case (TurnState.ADDTOLIST):
InputCombatSelectionDisplay ();
break;
case (TurnState.WAITING):
break;
case (TurnState.SELECCTION):
break;
case (TurnState.ACTION):
break;
case (TurnState.DEAD):
break;
}
}
and I also show you that I included this code in a switch () {} system
so tell me a correction to make
So if we break down your AttackCouroutine
method down, I think you will see what is missing and might not work as intended.
- Play animation clip “wait”
- Wait for 2 seconds
- Play animation clip “shiftingtoAttack”
- Calculate Step. If SpeedAttack is still defined as 5.0f, and let us assume you run at 60 frames per second, this value will be roughly 0.083f.
- Move towards OffsetEnemy.position. If we assume that transform.position is located at (0,0,0) at start, and OffsetEnemy.position is located at (1,0,0) and we are allowed to move a maximum distance of Step (0.083f) per call of this method, you will be at (0.83f, 0, 0) after calling this method.
- Wait for 1 second
- Play animation clip “Attacking”
- Wait for 2 seconds
9 & 10. Same as 4 & 5. You should now be at roughly (1.66, 0, 0) if the same numbers applies.
- Set Cur_CollDown to 0.0f
- Set CurrentState to TurnState.Processing
If you are using Vector3.MoveTowards
for incremental movement, then you need to call this method over and over again until the object has reached its destination, for the desired effect. If you only call it once or twice, with a very low 3rd parameter, the object will only move a part of the full distance.
I hope this explanation brings some clarity to the code.
Best of luck with this!
thanks a lot for your help
I have could understand , I message have to tell unity to use these systax several times for it to work
not necessary all this I ask you celement a direct correction in my code
I find that it is not the case all this
I reflected well and I find that I need visual scripting
you can give me links for a free visual scripting for the editor “Unity 5.6.6f2 (64-bit)”
and thank you for all
Hi, Unity has a free Visual Scripting tool called “Bolt”. However, Bolt is only available for Unity 2017.4 or newer.
1 Like
thank you very much for your help