Search Unity

Movement Basics in 2D

Discussion in '2D' started by Sanctumm1, Sep 12, 2019.

  1. Sanctumm1

    Sanctumm1

    Joined:
    May 28, 2018
    Posts:
    2
    So guys i have been struggling the last few days trying to find out how to make some basic scripting for moving. Im new to programming but getting rally frustrated cause NONE of the video tutorials i find actually work.

    Left Right up down on a flat empty screen. NO GRAVITY :-o

    But this is what i ended up with and i dont have a clue why its working it was copypastedd from a tutorial somewhere.. AND YES i found out that "Rigi" in my script before MonoBehavior is my name of the script :-o oh i have been struggling because i have been copy pasting 100 of scripts to see if they worked just to get a complete faul cause the name of the script didnt match anymore --- remember that guys :-D



    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    public class Rigi : MonoBehaviour
    {
    public float speed = 10;
    public Rigidbody2D rb;
    public void Update()
    {
    float h = Input.GetAxis("Horizontal");
    float v = Input.GetAxis("Vertical");
    Vector3 tempVect = new Vector3(h, v, 0);
    tempVect = tempVect.normalized * speed * Time.deltaTime;
    rb.MovePosition(rb.transform.position + tempVect);
    }
    }





    The next struggle is to get animations like "Idle" and "Running" written into the script.. But.. Again the tutorials i find doesnt work :-(




    If u guys know a GOOD starting guide id like to get a link tyvm.
    The struggles ive had so far is beyond aanything ive ever tried!
     
  2. Cornysam

    Cornysam

    Joined:
    Feb 8, 2018
    Posts:
    126
    Brackeys is a great YouTube page to follow, whether you are a newbie or more advanced. Check this video out for movement:



    He also has videos on animations.
     
  3. Sanctumm1

    Sanctumm1

    Joined:
    May 28, 2018
    Posts:
    2
    Tanks alot :-D
     
    Cornysam likes this.