Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In regards to coding in Unity and Microsoft Visual Studio In your player control

ID: 3592226 • Letter: I

Question

In regards to coding in Unity and Microsoft Visual Studio

In your player controller script, add the following attributes:

distance, of type float

pastPosition, of type Vector3

In Start(), do the following:

initialize distance to 0f

initialize pastPosition to the current position of the player object, or transform.position. The name “pastPosition” will make sense to you when you do the next part of the work.

Create a LateUpdate() header and in that method:

write a conditional expression to see if the pastPosition is not equal to the transform.position (aka current position). If they are not equal, this means the player has moved! You have some work to do if they are different.

Increase the distance variable by 1

Assign transform.position to the pastPosition variable. This gives you a new value to compare to the current position if the player moves again.

Explanation / Answer

//give distance in float

float distance = Vector3.Distance(other.position, transform.position);

//vector declaration

Vector3 pastPosition = new Vector3(var1, var2, var3);

void start()

{

pastPosition = player.transform.position;

[Header("LateUpdate")]

if (pastPosition != player.transform.position)

{

distance = distance + 1;

player.transform.position = pastPosition;

}

[Header("LateUpdate")]

}

(Please leave comment if further modification required)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote