Posted at 8:58 am , on December 29, 2017
I use Rigidbodies on the player objects in 1st & 10 Football but I have them set to Kinematic. When you have a Rigidbody set to Kinematic you cannot access the gameObject.transform.velocity property, it will give you an error. I needed to calculate the Velocity myself and thought I would post a quick bit of code in case it might be useful to someone else.
It’s pretty straightforward to calculate Velocity. Inside of your Update method you need to store the current position of the player, calculate the new position, and then subtract the two and divide it by deltaTime. How you decide to store the Velocity for use elsewhere is up to you, I store it in a property on the Player object outside of the movement FSM where the calculation takes place.
public Vector3 previousPosition = Vector3.zero;
public void Update()
previousPosition = player.transform.position;
player.transform.position = Vector3.MoveTowards(player.transform.position, destination, step);
player.Velocity = (player.transform.position - previousPosition) / Time.deltaTime;
Posted at 11:13 am , on December 19, 2017
I wanted to post a quick update since I hadn’t in awhile about the progress of the game. As you can see from the screen above I have decided to go the 3D route and abandon 2D. The change came about due to a few considerations, mostly that I have been dabbling in 3D for a few years now and I am MUCH better at it than 2D. While technically it is harder to code, I believe the time saved in the art creation will make up for the additional coding time I’ll encounter.
It took a few weeks to get everything I had previously done in the 2D version of 1st & 10 Football over to the 3D version but I have now already eclipsed in this new version where I was in the 2D version.
Currently work is mainly focused on the data structure of a “play”. My desire is to create a structure that can be stored in external files such as XML and then the community can use those as a template to create their own plays and import them into the game.
Happy Holidays to everyone and here’s too exciting things to come in 2018!
Posted at 5:37 pm , on December 12, 2017
Currently, in Unity, I have my MainCamera rotated at an angle to the ground. If I use the Translate() method on the camera’s transform object, it moves in local space meaning if I move it in the Z-axis, it moves closer or farther away to the ground at an angle.
What I wanted, was to move parallel to the ground on the Z-axis when using the W & S keys, and move in the X-axis when using the A & D keys even though my camera is rotated. I knew Global space would allow me to do that but I couldn’t easily find how to affect the transform global space instead of in local space. After some Googling & tinkering, I bore the fruit of my labors with this script attached to my MainCamera (ignore the TODO & NOTE).
I have a custom input defined in Project Settings -> Inputs called “CameraHeight” that is mapped to the Q & E keys. That moves the camera straight up in the Y-axis. It seems that modifying the transform.position value affects the Global space coordinates. Using the Translate() method affects the camera’s transform in local space.
Thought this might be helpful to someone else, I had a hard time finding the answer in my search.