Colour never changes, sqrMagnitude seems to be returning strange results

When I drag a new building the colour very, very rarely changes. There’s only 1 other building in the scene (I’m only running it direct from Unity as a Server + Client). I added some debug code which shows that the sqrMagnitude results are all over the place. Here’s the debug for when it works:

RTSPlayer::CanPlaceBuilding, point: (6.0, 0.5, 8.8), building.transform.position: (8.0, 0.5, 8.0), buildingCollider.center: (0.0, 0.5, 0.0), this.buildingRangeLimit: 5, (point - building.transform.position).sqrMagnitude: 4.805718, (this.buildingRangeLimit * this.buildingRangeLimit): 25

Literally with the next move of the mouse I get:
RTSPlayer::CanPlaceBuilding, point: (4.7, 0.5, 5.5), building.transform.position: (8.0, 0.5, 8.0). buildingCollider.center: (0.0, 0.5, 0.0), this.buildingRangeLimit: 5, (point - building.transform.position).sqrMagnitude: 16.7137, (this.buildingRangeLimit * this.buildingRangeLimit): 25

I’ve double checked the code with what is in the files from the final lecture in the course and they match.

Hey there, those sqrMagnitude values make sense to me, and they appear to be within your range. Is the building color not changing to red when within the range?

No they’re not

What are you using for models at this stage, still cubes?

Can you please share your code for the colour changing? I know where were some bugs around change the colour of buildings.

You might have to change the string we use for changing the colour. We use _BaseColor, but I think it needs to be _Color.

Hi there, did you still need help with this bug, let me know!

I’m really sorry I got side tracked. I don’t, thank you for following up

1 Like

Privacy & Terms