Lecture 103. Questions, questions, questions?

Right I’m at Lecture 103. And I’m being told I have to create a Player Controller - with the only help being given as an IF statement.

Well, ok, I know about IF statements not a problem I can get Unity to respond to key presses well, enough, but what about player movement - that is moving the ship.

Do we add the ship item in the hierarchy to the player controller, or do we leave those separate?

We never actually moved the Paddle in Block Breaker in the typical sense, we just made the paddle magically appear at a stop location ie where the mouse was, it was given the appearance of moving because Unity draws that stuff incredibly quickly. So looking at Block Breaker isn’t going to help. So, to do the movement are we going to be using translations or just transform.position and vector (vector.left and vector.right)? Are we going to be using vectors to set/get the initial position? How far is the ship going to be moved on the X axis left and right? Is there any movement on the y axis? It’s not specified. Are we going to be using time.deltaTime in the movement? Are we going to be using the Update of FixedUpdate for the movement? Do we constrain the movement to the PlaySpace at 800*600? Or are we going smaller or bigger? This was a rather big topic in BlockBreaker, also setting the Pixels per Unit, I’m still not sure about all the details of that you know setting the local/world co-ordinates and setting the screen at 16 units wide and all that stuff. And I do remember that we set the playspace to have the origin at the left bottom, I sort of liked that as there were no negative values on the playfield - can’t remember off-hand how we did that, so are we doing that again?

So, just being told to write a controller without more information seems to the greatest oversimplification in the history of oversimplifications.

I’m sorry if that comes across as a bit harsh, but, it’s been over 40 C where I live and I’m hot and I’m tired and haven’t slept well for the last week, and it’s not going to let up anytime soon.

Help!!!
Vaughan.

Basically, you asked yourself almost all the right questions needed to solve the problem of moving the player ship.

The next lessons will give you an answer, BUT you can always try to answer them by yourself, and with all the answers written down, you can proceed to write some code that follows those answers.

An example of how to proceed is this, I’ll take a couple of your questions:

  • Are we going to use Update or FixedUpdate?

  • Since FixedUpdate, as per Unity docs, is used by the physics engine, whereas Update is used by the graphical engine, the answer would be Update, since we’re dealing with a graphical update and not a physics one.

  • Are we going to use Time.deltaTime?

  • Since we’re going to use the Update method, and since this method is called every graphic frame update, the answer is yes.
    This stems from the fact that we’re trying to move something on screen with code, and this movement is based on a velocity, which is defined dimensionally as [space]/[time], so if we want to be consistent with the velocity dimension, and we change the position in the Update method, which is fired once every frame (i.e.: dimensionally is [frame]), to get the right amount of [space]/[frame] we need to multiply velocity * Time.deltaTime every Update call ( [space]/[time] * [time]/[frame]).

Same goes with all your other questions, write down the answers, and then write down the “gap fillers” among the various answers: the rest of the work will be just converting all these answers in code, but most of the work will be already done. :wink:

2 Likes

Actually that answer was very informative. I had no idea about Update vs FixedUpdate! And the same with Time.deltaTime, I noticed some really strange results when I had the ship moving without using time.deltatime, like the ship started off slow and started to speed-up (and I mean really speed up), plus other weird problems, whereas with time.deltatime the movement was smooth and constant - well, until I let go of the button.

So, thanks greatly for your response. I now have movement code that constrains movement to the playspace. Now I suppose with the rest of the tutorial, I get to find out how wrong I am :laughing:.

1 Like

Privacy & Terms