tisdag 10 december 2019

Game Code

I created the MainScript.cs and Model.cs, among other things. MainScript is our games "main"-method. Funnily enough, we use its looping Update and FixedUpdate to loop the game logic. Model.cs is a more condensed class with the core game logic defined in it. The name is inspired from the design pattern called Model-View-Controller. The idea with this pattern is to handle all of the core logic separately, in order to make it easier by having less coupling in the code.

I also create some other separate functions for aiming and moving. In regards of moving I first wanted to make it from scratch, but in order to speed things up I made use of Unity's pre-defined moving controllers. As an extra help I used some code from "Brackeys", a famous tutorial persona on YouTube. I also viewed one of his videos when I was creating colliders for characters.

I created Unit.cs, which can be used as a base for any kind of unit in the game. In this case, we never made a player class that inherits from Unit, but instead just used the Unit class directly for the players.

When a player aims, an ellipse, or circle is drawn around the player. This was done by using straight lines fom Unity's Linerenderer. How can lines be used to draw circles? Well, I created many points in a diamond shape around the player. Then, if I recall correctly, I projected each of these points to the closest position on the ellipse around the player using this formula from StackOverflow: https://math.stackexchange.com/questions/22064/calculating-a-point-that-lies-on-an-ellipse-given-an-angle/22067#22067

This gives an acceptable ellipse, but I think if done in a better way, the points could be distributed more evenly accross the elipse. After projecting the points, I used them to draw lines.

In a similar fashion I made use of the mathematical to position an arrow for aiming.

Inga kommentarer:

Skicka en kommentar