|
Each character has a script and within the script a "speed" variable. I have an empty GameObject with a script that will handle all the combat mechanics. This script accesses the speed value of every character. It also has these values in an array. How do I script to have the Assign the turns based on speed? For example, 100speedChar goes before 70speedChar who goes before 50speedChar etc. Thanks.
(comments are locked)
|
|
Flip the speeds, so that lower is better, with, say, 100/spd. That gives your speed 100 a 1 and speed 50 a 2. Call that the "ActionDelay." Start everyone off at their ActionDelay. Each turn, lowest number acts, and add their actionDelay: But how do I make it know WHICH character has a speed of 100 or 50 or so? I can understand the reasoning behind flipping the speeds, you're turning them into points in time. (guess I'm going to have to make the "speed" values floats then..) How I want this to work is; Time calculation stops, player chooses actions for each character. AI automatically sets actions for the mobs. Time calculation starts, lowest ActionDelay gets triggered, time calculation stops, action is complete, time calculation resumes, second lowest ActionDelay gets triggered, time calculation stops, etc. p1ActionDelay and p2ActionDelay are just float values, how do I make it understand which combatant they belong to? Pseudocode will be more than enough. Thank you.
Nov 20 '11 at 09:43 AM
Neten
You can leave the base speeds as int -- the internal "lower is better" speeds would be floats. A cheap way is to give everyone an extra "moveNext" var. Each turn, search all mobs and players. Whomever has the lowest, moves. Since it's turn-based, speed doesn't matter. A nicer way is to make your own array of Transform/actionNumber for as many players+mobs. The Transform only points to the real gameObject. Each turn, search it for lowest and that transform acts.
Nov 20 '11 at 06:11 PM
Owen Reynolds
I couldn't: -Find the lowest moveNext(which is what used to be "actionDelay", right?) -Even if I could, find out to whom that moveNext belongs to. (At least when I tried it with Array.Sort(), which only returned a numeric value, which I couldn't identify whom it belongs to.)
Nov 20 '11 at 09:17 PM
Neten
Let's say you use FindObjectsWithTag for each move. Go through the array yourself, finding the lowest Then can call If you have a separate array for them all (trickier,) group nextMove and transform together:
Nov 21 '11 at 12:33 AM
Owen Reynolds
Ok, I got it now. You've been very helpful, thanks a lot.
Nov 21 '11 at 07:57 PM
Neten
(comments are locked)
|
