Post by 7thsage on May 4, 2020 7:58:02 GMT
So I'm still making tweaks to the code. At the moment I'm working on tying my overhaul of the board system into the tutorial code and my other modifications. I don't have that quite at a place to share yet, but I have a little snippet that I thought someone might find useful?
When the camera rotates around, I wanted it set up so the arrow keys adjust to go along with it. That way when I press up, I get a predictable result. This one depends a little bit on my current code, but it should be easy enough to tweak to make work.
In battlestate.cs I added this function so that I can access it from whichever state I decide needs it. I didn't want to add this to the pure directional code because I didn't want to accidentally change how menus or anything work.
Then in MoveTargetState.cs I call it like this
I pared it down a little to be closer to the original tutorial, so hopefully I didn't add any bugs in the process, but I'm fairly sure I got it. My code uses a modified Point class that is x,y,z. The only thing left is just tying the camera rotation to the angle variable that will depend on however whoever's camera code is set up.
When the camera rotates around, I wanted it set up so the arrow keys adjust to go along with it. That way when I press up, I get a predictable result. This one depends a little bit on my current code, but it should be easy enough to tweak to make work.
In battlestate.cs I added this function so that I can access it from whichever state I decide needs it. I didn't want to add this to the pure directional code because I didn't want to accidentally change how menus or anything work.
//change movement so when the camera is rotated, left still moves left etc.
protected virtual Point AdujustedMovement(Point originalPoint)
{
float angle = cameraRig.GetRotationX();
if ((angle >= -45 && angle < 45) || ( angle < -315 || angle >= 315))
{
return originalPoint;
}
else if ((angle >= 45 && angle < 130) || ( angle >= -315 && angle < -210 ))
{
return new Point( originalPoint.z, originalPoint.x * -1);
}
else if ((angle >= 130 && angle < 210) || ( angle >= -210 && angle < -130 ))
{
return new Point(originalPoint.x * -1, originalPoint.z * -1);
}
else if ((angle >= 210 && angle < 315) || ( angle >= -130 && angle < -45 ))
{
return new Point(originalPoint.z * -1, originalPoint.x);
}
else
{
Debug.Log("Camera angle is wrong: " + angle);
return originalPoint;
}
}
Then in MoveTargetState.cs I call it like this
protected override void OnMove (object sender, InfoEventArgs<Point> e)
{
Point rotatedPoint = AdujustedMovement(e.info);
SelectTile(rotatedPoint + pos);
}
I pared it down a little to be closer to the original tutorial, so hopefully I didn't add any bugs in the process, but I'm fairly sure I got it. My code uses a modified Point class that is x,y,z. The only thing left is just tying the camera rotation to the angle variable that will depend on however whoever's camera code is set up.