Susan Harkins (408) [Avatar] Offline
#1
Please post errors found in the published version of Unity in Action, Second Edition here. If necessary, we'll publish a comprehensive list for everyone's convenience. Thanks!

Susan Harkins
Errata Editor
Manning Publications
MatanK (4) [Avatar] Offline
#2
In section 4.5.2, page 92, it says to drag the imported texture into the texture slot in unity. When I followed the instructions in my version of unity (2017.4.1f1) the material was disabled and I could not change the texture slot. After searching, I found the following video: https://www.youtube.com/watch?v=xOeodlLTx8g
Which shows the problem I had (at minute 4:05 of the video). Eventually, as explained in the video, this was fixed by going to the "materials" tab in the imported model and clicking "Extract Materials..."

Would be nice to add this to the errata so future people will have an easier time finding the solution to this smilie

Otherwise, super awesome book so far. Thank you!
jhocking (202) [Avatar] Offline
#3
Thanks! I'll double-check that issue; looks like this will be the first thing on the list of errata I'm compiling.

This must be a change from Unity 5 that I hadn't noticed, because these instructions worked fine before.
TokyoDan (3) [Avatar] Offline
#4
What version of Unity does this new 2nd Edition cover?
jhocking (202) [Avatar] Offline
#5
TokyoDan wrote:What version of Unity does this new 2nd Edition cover?


(fyi this thread is for reporting errors in the book; it would have been better to ask this in a new thread)

The version of Unity used in the book is 2017.1
MatanK (4) [Avatar] Offline
#6
Errata for Listing 6.8 (page 143):

"if (deltaX != 0)"

should be replaced by

"if (!Mathf.Approximately(deltaX, 0))"

I don't think it matters much in this case, but this is the way it was coded in Listing 6.2.
jhocking (202) [Avatar] Offline
#7
doh you're right, I'll have to mark that mistake in errata. Originally 6.2 was written the same way, but after this suggestion I changed that code and forgot to change 6.8 as well.
577389 (1) [Avatar] Offline
#8
Section 2.4.2 - Dead link to article on quaternions
Section 2.4.2 references Q47 of www.flipcode.com/documents/matrfaq.html. That link is a dead end, but one can get to the content via the Internet Archive http://web.archive.org/web/20171213210351/www.flipcode.com/documents/matrfaq.html.
jhocking (202) [Avatar] Offline
#9
Thanks, I'll probably find a different live article for that link.

EDIT: This one looks good https://www.gamasutra.com/view/feature/131686/rotating_objects_using_quaternions.php
MatanK (4) [Avatar] Offline
#10
Just found an error due to watching streamers playing my Ludum Dare game on twitch. It was glitched for some people, and after some debugging I finally found out it was due to a bug I got from page 132:

void Update() {
float deltaX = Input.GetAxis("Horizontal") * speed * Time.deltaTime;
Vector2 movement = new Vector2(deltaX, _body.velocity.y);
_body.velocity=movement

Apparently, you should not multiply velocity by deltaTime. This makes sense since distance = velocity * time, so you don't want time to be multiplied twice when calculating the distance...

(by the way, my jam entry is at https://ldjam.com/events/ludum-dare/42/pyramidion)
jhocking (202) [Avatar] Offline
#11
ah good spot. I had copied that line from the 3D movement code, and forgot about the difference between manipulating the position directly, and manipulating the velocity.
Susan Harkins (408) [Avatar] Offline
#12
An updated errata list for Unity in Action, Second Edition is available at https://manning-content.s3.amazonaws.com/download/a/f5a5e21-7743-43c7-88dd-0dcd9bf7cd2b/Hocking_UnityinActionSE_err2.html. Thank you for participation in this process!

Regards,
Susan Harkins
Errata Editor
fct (6) [Avatar] Offline
#13
I was just going over RelativeMovement script in section 8.2.1 when I noticed that it can be simplified to use less resources.

The code given in the book rotates the camera in order to get a fixed reference point for rotating the player character. Yet, there are quite a few transformations going on behind the scenes with the given code. There's a local to world transformation, followed by a local to world transformation, followed by a quaternion to euler transformation, followed by a euler to quaternion transformation, followed by world to local transformation. All of that was just to rotate the camera in order to use the camera's Transform as a reference rotation for changing the character's direction. There's also a final transformation from world rotation to local rotation for re-setting the camera after finding the direction you want to face the character.

The thing is, as long as we have two of the three axis, we can find the third one through the cross product. We already know that we want the Right direction to be in line with the screen's right, which means that we can grab the camera's right value (an X-Axis). We also know that by default, the Up direction in Unity is the Y-Axis. Taking the cross product of those two vectors will give as the Vector3 axis that's equivalent to the Vertical input. After that, finding the movement direction is just two multiplications and one addition.


using System.Collections;
using System.Collections.Generic;

using UnityEngine;


public class RelativeMovement 
    : MonoBehaviour 
{
    [SerializeField] private Transform _target;

    private void Update()
    {
        float horInput  = Input.GetAxis("Horizontal");
        float vertInput = Input.GetAxis("Vertical");

        if (horInput != 0 || vertInput != 0)
        {
            var right    = _target.right;                 // Screen Right & Movement Right-Axis
            var up       = Vector3.up;                    // Movement Up-Axis
            var forward  = Vector3.Cross(right, up);      // Movement Forward-Axis
            var movement = (horInput * right) + (vertInput * forward);  // Movement Direction

            transform.rotation = Quaternion.LookRotation(movement);
        }
    }
}

jhocking (202) [Avatar] Offline
#14
oo great optimization! I'm not sure I can add this to the errata directly, since this change would affect more in the book than just overwriting this one code listing (eg. I would need to add an explanation of the cross product) but I'll definitely do something with this change, even if only keeping it in the holster for a possible third edition.

btw there are a couple minor adjustments needed in order to properly integrate your new code. For starters, you will want to keep the 'movement' vector initialized outside the conditional (ie. the 'movement = Vector3.zero' bit) so that it can be used later.

You will also want to add this line right after the 'movement = blah' line in your code to correct the movement speed:
movement *= moveSpeed;
fct (6) [Avatar] Offline
#15
jhocking wrote:oo great optimization! I'm not sure I can add this to the errata directly, since this change would affect more in the book than just overwriting this one code listing (eg. I would need to add an explanation of the cross product) but I'll definitely do something with this change, even if only keeping it in the holster for a possible third edition.

btw there are a couple minor adjustments needed in order to properly integrate your new code. For starters, you will want to keep the 'movement' vector initialized outside the conditional (ie. the 'movement = Vector3.zero' bit) so that it can be used later.

You will also want to add this line right after the 'movement = blah' line in your code to correct the movement speed:
movement *= moveSpeed;


Sweet.

Sorry about the code not being fully integrated yet. I've been using the book as brush-up material, so I'm not quite going through it at the same pace I did when I read the first edition. I thought about optimizing the code I submitted a bit more, but I figured that things like Vector3.zero and Vector3.up would be easier for beginners to deal with. Now, that I think about it, a section on common vector math might not be a bad idea. This is one thing that a lot of game programmers may need to deal with no matter what framework they're building on. Half the reason I was able to optimize this code was due to all the odd vector math I had to do while building a custom camera-framework for my previous job.

I'll be sure to edit my previous response once I get a bit further in the book, but that might have to wait a week or two. Right now I'm doing a bit of research for a possible job.