Unity Tutorial: Roll A Ball - Part 2: Player & Camera Movement

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 21

  • @Digestible
    @Digestible  10 месяцев назад +2

    ******************************************************************************
    After this video your PlayerController class will look like this:
    ******************************************************************************
    using UnityEngine;
    using UnityEngine.InputSystem;
    public class PlayerController : MonoBehaviour
    {
    public float speed = 10.0f;
    private Rigidbody rb;
    //holds movement x and y
    private float movementX;
    private float movementY;
    // Start is called before the first frame update
    void Start()
    {
    rb = GetComponent(); //sets rigidbody component to rb
    }
    void OnMove(InputValue movementValue)
    {
    //create a vector 2 variable and store the x and y movement values in it
    Vector2 movementVector = movementValue.Get();
    movementX = movementVector.x;
    movementY = movementVector.y;
    }
    // Update is called once per frame
    void FixedUpdate()
    {
    //set the movement to the x and z variables (keep y at 0)
    Vector3 movement = new Vector3(movementX, 0.0f, movementY);
    rb.AddForce(movement * speed);
    }
    }
    ******************************************************************************
    and your CameraController class will look like this:
    ******************************************************************************
    using UnityEngine;
    public class CameraController : MonoBehaviour
    {
    public GameObject player; //will reference the player game object's position
    private Vector3 offset; //will set the offset position from the player to the camera
    // Start is called before the first frame update
    void Start()
    {
    //calculate the offset position between the camera and the player at the start of the game
    //it subtracts the player's position from the camera's
    offset = transform.position ­ player.transform.position;
    }
    // Update is called once per frame
    void Update()
    {
    //sets the camera to where the player is plus the offset set above
    transform.position = player.transform.position + offset;
    }
    }

  • @BatzorigVaanchigEnjoyer
    @BatzorigVaanchigEnjoyer Год назад +3

    thanks for making this!

  • @-VORTEX-VR
    @-VORTEX-VR Год назад +1

    When i put in the script the player still didn't move

  • @ZenoVoids
    @ZenoVoids Год назад +3

    Mine just said it had a compiler error

  • @knows20
    @knows20 4 месяца назад

    3:30 I can’t find player input😢

  • @Cosmitm
    @Cosmitm 8 месяцев назад

    Hey I’m back and I have a question do you know how to make a rotatable cam? I know it’s possible but I need it because I’m planning on making a racing ball game and I need a rotatable cam just a question and if you don’t know how to that’s okay

  • @Cosmitm
    @Cosmitm 10 месяцев назад

    For me the compiler errors were
    Vector2 could not be found 2 of these were not found
    And
    The name ‘movement’ does not exist in the current context

    • @Digestible
      @Digestible  10 месяцев назад

      I replied to your other comment but you have several typos in your code which is causing the errors. Vector is spelled "Vecter" in several places and FixedUpdate() is spelled wrong and you also are setting movementX twice - you may need to look at it line by line

  • @Cosmitm
    @Cosmitm 10 месяцев назад

    It worked it worked it worked!!!!!

  • @sanjaykrishna9477
    @sanjaykrishna9477 9 месяцев назад

    How to install visual studio. That has opened when u create c#(5:10)?

    • @Digestible
      @Digestible  9 месяцев назад

      I installed mine when i installed unity - my video for installing unity shows this: ruclips.net/video/Kh_FD0Ypdhg/видео.html So if you install a new version of unity (through hub and archives) you can choose to install it still through unity hub. You could also install visual studio community (also free)separately but you may have to set the editor in unity after - i didnt do it that way so i'm not sure of the steps visualstudio.microsoft.com/downloads/

  • @DrDwarven
    @DrDwarven Год назад

    It just says compiler error

    • @Digestible
      @Digestible  Год назад

      If you get a "compiler error" that means there is an error in your code somewhere. C# is very picky so it could be a typo, it could mean that you are missing a semicolon on a line, it could be even as small as you have a capital X when it needs to be a lower case x. Without seeing your code I cant say where it was so you will have to look through it. Check to see if you have any red squiggley lines under your code. If you dont see any check to see if your code says "Assembly C-Sharp" in the top left corner - if instead you see "Miscellaneous files" you should fix the link between unity & visual studio so it shows your errors - i have a video to fix that if needed. ruclips.net/video/5r3O3VMXA0c/видео.html

    • @-VORTEX-VR
      @-VORTEX-VR Год назад

      ​@@DigestibleI checked my code and dint see any of each

  • @Cosmitm
    @Cosmitm 10 месяцев назад

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.InputSystem;
    public class playercontroller : MonoBehaviour
    {

    private Rigidbody rb;

    //holds movement x and y
    private float movementX;
    private float movementY;

    // Start is called before the first frame update
    void Start()
    {
    rb = GetComponent(); //sets rigidbody component to rb
    }

    void OnMove(InputValue movementValue)
    {
    //create a Vecter 2 veriable and store the x and y movement values in it
    Vecter2 moveVecter = movementValue. Get();

    movementX = movement.X;
    movementX = movement.y;

    }
    // Update is called once per frame
    void FixwdUpdate()
    {
    //set the movement to the x and z variables (keep y at 0)
    Vecter3 movement = new Vecter3(movementX, 0.0f, movementY);
    rb.addforce(movement);

    }
    }
    code at the time of putting this in it is kinda of broken but she uploaded a video on how to fix it

    • @Digestible
      @Digestible  10 месяцев назад +1

      I'm not sure what you are asking but if you are looking for why it says there are errors it is because you have typos in your code - at least a couple I see. you have "FixwdUpdate()" instead of "FixedUpdate()" and also "Vecter3" instead of "Vector3" in a couple of places, as well as "Vecter2" and it should be "Vector2" . Code on your OnMove also has errors with the spelling of Vector and also you are setting movementX twice... I hope this helps. there may be more but those are the ones that jump out at me

    • @Cosmitm
      @Cosmitm 10 месяцев назад

      @@Digestibleoh thank you I did not see it plus it was like 10 pm when I was followed along so I will retype the code and see if it works because I have had so much problems on just making a simple game thx for your feed back *side note I was to tired to type the first sentence but I thought I typed something in the beginning sorry lol I was so embarrassed when I seen the code typos*

    • @Cosmitm
      @Cosmitm 10 месяцев назад

      @@DigestibleI will tell you da problem so I retyped it but is says movement does not exist in the current context it says that 2 times and it also says rigidbody does no contain a definition for addforce and no accessible extension method addforce accepting a first argument of type rigidbody could be found and then (are you messing a using or directive or an assembly reference?) reply when ready

    • @Digestible
      @Digestible  10 месяцев назад

      @@Cosmitm there are still likely some typos. I added a comment (should be pinned to the top) that shows how the script should look after this video so you can compare. even look for capital letters - something little can make it not work.

    • @Cosmitm
      @Cosmitm 10 месяцев назад +1

      @@Digestiblethank you I just came back from school and I’m going to retype it thx