Search Unity

Question why is vector2.up not working?

Discussion in 'Getting Started' started by Majarin07, Aug 30, 2023.

  1. Majarin07

    Majarin07

    Joined:
    Aug 29, 2023
    Posts:
    3
    this is the code but vector2.up down left or right none of the will work and I don't understand why hear is the code

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class bird : MonoBehaviour
    {
    public Rigidbody2D myRigidbody;


    // Start is called before the first frame update
    void Start()
    {
    gameObject.name = "bord";

    }

    // Update is called once per frame
    void Update()
    {

    myRigidbody.velocity = Vector2.up * 10;

    if (Input.GetKeyDown(KeyCode.Space) == true)
    {



    }
    }
    }
     
  2. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,040
    1. Use code tags when posting code
    2. Define the issue. Not working is vague. Describe what you want and what it is doing right now.
    3. Any errors or warnings?
    4. Can you share the rigidbody settings as well.
     
  3. Majarin07

    Majarin07

    Joined:
    Aug 29, 2023
    Posts:
    3
    1 i downt know gow to
    2 i want it to do a jump but curently it is just doing nothing
    3 no errors or warnaing
    4 they are just standard
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,424
    Here's how Code-tags

    All your code is doing is permanently (per-frame) setting the velocity to (0, 10) i.e. up. That's all it does.

    You should follow one of the many, many tutorials on the subject of 2D physics movement. Then you'll have a better idea on how to control it correctly and should be less frustrating for you. :)

    Search "unity 2d physics movement tutorial".

    Hope this helps.
     
    DevDunk likes this.
  5. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,040
    1. Read the scripting subforum. That's also a more relevant either way.
    2. Learn basic code first by following guides
    3. You need to put the velocity inside the if statement and maybe increase the force
     
  6. Majarin07

    Majarin07

    Joined:
    Aug 29, 2023
    Posts:
    3
    i found a way to fix it but it was way to complecated for me to under stand
     
  7. DevDunk

    DevDunk

    Joined:
    Feb 13, 2020
    Posts:
    5,040
    Learn basic code, maybe try the programming pathway on Unity Learn
     
    Chubzdoomer likes this.