Skip to main content

New Page

public float speed = 5.0f;

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

private float speed = 5.0f;

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.05 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;

User
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 
+ new Vector3(0, 5, -7)
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 

image.png

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