# New Page

`<span data-offset-key="apbfk-0-1" style="font-weight: bold; font-style: italic;"><span data-text="true">public float </span></span><span data-offset-key="apbfk-0-2" style="font-weight: bold; font-style: italic; text-decoration: underline;"><span data-text="true">speed</span></span><span data-offset-key="apbfk-0-3" style="font-weight: bold; font-style: italic;"><span data-text="true"> = 5.0f;</span></span>`

the word public can be changed to private, this denotes the accessability of the variable/class/other

`<span data-offset-key="apbfk-0-3" style="font-weight: bold; font-style: italic;"><span data-text="true"><span data-offset-key="apbfk-0-1" style="font-weight: bold; font-style: italic;">private float </span><span data-offset-key="apbfk-0-2" style="font-weight: bold; font-style: italic; text-decoration: underline;">speed</span> = 5.0f;</span></span>`

also this is done to initialize the default value of the variable in the script's component tab   
they are also known as access modifiers :D

when we do 5 as a variable, its only valid as an intiger, a whole number, so if we want to do fractional speeds we need to make it a floating point, a decimal number, so we could do 5.0, but its not understandable because its a decimal number

so since its not an intiger we need to use float to do decimals coz its a floating point number  
so then can do 5.0f to turn 5.0 into a readable understandable number for the game  
:D  
what happens when we do dword :D it doesn't tell us ;-;  
  
anyways next line of code  
this is similar to the public float speed = thing BUT  
it doesn't give us the number, or object its just a name

normally this doesn't work unless you assign a value in some programming languages but with c# if the script is assigned to an object ex. the camera you can drag an object into the player variable to reference what the player variable is, so ex we want the tank to be the player, (later the player model)

we can just put this code in the first level of the script in the public class and it will allow us to assign an object to the variable. whoa python is hard lmfao

 public GameObject Player;

ok so next line

in the void update() area

  
 transform.position = Player.transform.position;

<div class="flex-shrink-0 flex flex-col relative items-end" id="bkmrk-"><div class="w-[30px]"><div class="relative flex"><span style="box-sizing: border-box; display: inline-block; overflow: hidden; width: initial; height: initial; background: none; opacity: 1; border: 0px none; margin: 0px; padding: 0px; position: relative; max-width: 100%;">![User](https://chat.openai.com/_next/image?url=https%3A%2F%2Flh3.googleusercontent.com%2Fa%2FAGNmyxYznFTCHQPRIoyzvpOPF9nvwe3_Ef9StfW1veunMQ%3Ds96-c&w=96&q=75)</span></div></div></div><div class="relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]" id="bkmrk-so-basically-this-tr"><div class="relative flex w-[calc(100%-50px)] flex-col gap-1 md:gap-3 lg:w-[calc(100%-115px)]"><div class="flex flex-grow flex-col gap-3"><div class="min-h-[20px] flex flex-col items-start gap-4 whitespace-pre-wrap break-words">so basically this transforming the position of the camera to be exactly the same as the Players, including its transformed(updated) position  
so since we want to offset that  
we can add   
`<span data-offset-key="4ns9t-0-1" style="font-weight: bold; font-style: italic;"><span data-text="true">+ new Vector3(0, 5, -7)</span></span>`  
</div></div><div class="min-h-[20px] flex flex-col items-start gap-4 whitespace-pre-wrap break-words">we need to use a new vector3 variable (xyz)  
but since we need to be able to change that   
  
I messed with the code more and got the ideal maybe ggz angels   
</div></div></div>[![image.png](https://library.naruzkurai.tk/uploads/images/gallery/2023-05/scaled-1680-/kat3fOEPivN6WvnT-image.png)](https://library.naruzkurai.tk/uploads/images/gallery/2023-05/kat3fOEPivN6WvnT-image.png)

```c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FollowPlayer : MonoBehaviour
{

    public GameObject Player;
    private Vector3 offset;
    public float camera_x_offset = 0.0f;
    public float camera_y_offset = 5.0f;
    public float camera_z_offset = -7.0f;

    // Camera rotation offsets
    public float camera_x_rotation_offset = 0.0f;
    public float camera_y_rotation_offset = 0.0f;
    public float camera_z_rotation_offset = 0.0f;

    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        offset = new Vector3(camera_x_offset, camera_y_offset, camera_z_offset);
        transform.position = Player.transform.position + offset;

        // Apply the rotation offsets
        Quaternion rotationOffset = Quaternion.Euler(camera_x_rotation_offset, camera_y_rotation_offset, camera_z_rotation_offset);
        transform.rotation = Player.transform.rotation * rotationOffset;
    }
}

```

this still follows the player when they move away and jump but hayyy its what I want later on when I deny up/down / in / out movement  
  
okok so important thing  
to midiage or remove studder we could make a smoother with another script  
OR fix the problem at the core sortof  
do void LateUpdate() instead of Update()  
this will make the camera's movement update be after the players position updates :D  
BRO  
someone should've told me sooner you can make the playmode color change wayyy more noticable

```
    From the top menu, go to Edit > Preferences (Windows) or Unity > Preferences (Mac) 
    In the left menu, choose Colors, then edit the “Playmode tint” color to have a slight color
    Play your project to test it, then close your preferences



```

programming/unity essentials xp +5 each