|
Post by candymancriminal on Jan 28, 2016 4:18:09 GMT
In the flying movement I encounter an occasional lock up right before the unit lifts off the ground. I'm not sure what's causing it as I haven't changed anything about it.
My other issue is that I've added a greater range and a chance for teleports to fail. However after a failed teleport an AI unit will still attack and use skills as if they had reached their target location. Not sure why this happens, was hoping someone could point me in the right direction.
|
|
|
Post by Admin on Jan 29, 2016 19:58:38 GMT
I'm not sure about your first problem. I've never noticed a lock-up in the project. Also, what do you mean exactly? Like does the whole Unity interface lock up or does the unit itself just get stuck?
If you look in the "TeleportMovement" script, the line of code which is responsible for moving the Unit to another location on the board is right at the beginning: unit.Place(tile);
However, you should note that this is just assigning the references between the board tiles and the unit, and does nothing to update the visual location of the unit. If you want to allow the teleport to fail, make sure you are doing so before allowing the "data" to be updated.
|
|
|
Post by candymancriminal on Jan 29, 2016 20:41:11 GMT
when the flying unit locks up it simply fails to lift from the ground, and no further action takes place
i added a rotation + zoom to the camera and that part still functions while the unit just stays where it is
the TeleportMovement script has been modified to
using UnityEngine;
using System.Collections;
public class TeleportMovement : Movement
{
public override IEnumerator Traverse (Tile tile)
{
//calculate distance between current tile and target tile
float dist = Mathf.Sqrt(Mathf.Pow(tile.pos.x - unit.tile.pos.x, 2) + Mathf.Pow(tile.pos.y - unit.tile.pos.y, 2));
//store current tile
Tile oldTile = unit.tile;
GameObject cursor = GameObject.FindGameObjectWithTag("Cursor");
//spin me right round, baby
Tweener spin = jumper.RotateToLocal(new Vector3(0, 360, 0), 0.5f, EasingEquations.EaseInOutQuad);
spin.loopCount = 1;
spin.loopType = EasingControl.LoopType.PingPong;
//shrink user in size
Tweener shrink = transform.ScaleTo(Vector3.zero, 0.5f, EasingEquations.EaseInBack);
while (shrink != null)
yield return null;
//calculates odds of succeeding the teleport
float distCalc = Mathf.Clamp ((Mathf.Round (dist) - 3), 0, 10);
float calc = 100 - (distCalc * 10);
int ranRoll = Random.Range (0, 100);
if (ranRoll > calc)
{
//teleport fails
//change the target tile to the current tile
tile = oldTile;
//set cursor to current tile
cursor.transform.position = tile.center;
//need to add that you cannot undo a failed teleport
}
transform.position = tile.center;
unit.Place (tile);
//set location
//regrow user
Tweener grow = transform.ScaleTo(Vector3.one, 0.5f, EasingEquations.EaseOutBack);
while (grow != null)
yield return null;
}
}
|
|
|
Post by Admin on Jan 29, 2016 20:59:02 GMT
Ah... I missed that you specified that only the A.I. had the problem. The way that the A.I. works is that it formulates a plan for moving and attacking right at the beginning of a move - it only does this once and stores the results. I had not accounted for a chance that movement could fail, so there is nothing to cause the A.I. to re-evaluate based on that condition.
Start looking in the "CommandSelectionState" script and the "ComputerTurn" method - this is where the A.I. decides how it's turn should look, as well as what phase of presenting it to the player it is currently on. If you notice there is a chain of if statements, and you could check to see that the "turn" is marked showing that the Unit has moved, but also check to see that the current position of the unit is not where it planned to be. On those cases, you will need to handle a "re-evaluate" for the A.I. or as a quick solution, just ignore whatever else the unit had planned to do for that turn.
|
|
|
Post by candymancriminal on Jan 29, 2016 23:08:35 GMT
teleport failure is now a success, thanks for the help
now i just need to figure out why the flying isnt working properly
|
|
|
Post by Admin on Jan 30, 2016 18:55:41 GMT
For the flying problem, are you noticing any errors or warnings in the console output while playing the game? When you say "no further action takes place" do you mean that the game is stuck in that game state, or does the unit stay still but the game continues?
|
|
|
Post by candymancriminal on Jan 30, 2016 19:29:56 GMT
no errors pop up, and no further actions take place it never makes it through the tweener that sends it upwards so the tweener doesnt become null, so it cant move into position
i cant figure out why the lift off tweener doesnt like to work the weirdest part is its not 100% of the time, it doesnt even happen often
|
|
|
Post by Admin on Jan 31, 2016 1:12:50 GMT
It's hard to comment on what could be the problem since I've never seen it happen myself. I have a few thoughts that might be worth checking: 1.) Be extra sure there wasn't an error (like a null-ref etc) which could cause the Traverse method to be aborted before it got to the tweener code. 2.) Make sure you haven't modified time scale to zero (this is one way people commonly pause their games) because that would also stop the animation code. 3.) Verify all of the variables each step of the way. For example, what if duration could be negative due to the layout of your board? I haven't tested what that would cause. 4.) Make sure you haven't disabled the "destroyOnComplete" property of the Tweener 5.) Make sure you haven't setup the tweener to be able to loop infinitely because then it would never "complete" and thus be destroyed.
Other than that, I would try to find better reproduction steps for the bug. When you can get it to occur consistently with a certain sequence of steps then it will be easier to tell what the problem might be.
|
|
|
Post by candymancriminal on Jan 31, 2016 1:34:25 GMT
Bingo! threw in a bunch of variable checking and found out duration was, in fact, going below zero! everything should be all set now, thanks for the help =]
|
|
|
Post by 7thsage on Jan 18, 2022 3:35:51 GMT
My son started doing the tutorial as well and he also ran into the flying bug. Problem is with the line
In FlyMovement.cs
float duration = (y - jumper.position.y) * 0.5f; Whenever the flying unit's height starts on ground above a certain value(I think at height 5 or 10?) the duration becomes negative.
His solution was to add an Abs() in there, though its not quite right either, it at least won't crash, and I'm proud that he found the problem and a solution himself. Thought I'd mention the whole thing anyway though, since its not based on changes to the code, but happens in the base tutorial code as well.
|
|
|
Post by Admin on Jan 18, 2022 14:27:51 GMT
Congrats to your son for figuring out where the problem was. If you look at the lines above that:
// Fly high enough not to clip through any ground tiles float y = Tile.stepHeight * 10; float duration = (y - jumper.position.y) * 0.5f;
I made an assumption that boards would not go as high as 10 steps, and clearly didn't communicate my assumption well. The inclusion of the magic number "10" in there was sloppy on my part. In order to make this work for every scenario, I would probably need to create some kind of variable that controls the air zone height for flying units. It could be dynamic and scan for the max step height of any board, or could be manually placed per board.
|
|
|
Post by 7thsage on Apr 4, 2024 5:07:36 GMT
Now that I'm examining the code a bit more closely. I think the correct solution is probably to change it to something like
// Fly high enough not to clip through any ground tiles
float y = Tile.stepHeight * 10;
float duration = y * 0.25f;
We are moving jumper up 10 tiles in local position, so the duration should always be the same, because we are always going up the same height. I suppose if we really want to make sure that we are getting over all objects we could do a raytrace or something from 10 units above both start and end position to see if there is anything in the way.
|
|