Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

movement

Discussion in 'Scripting' started by michele2000bon, Dec 1, 2019.

  1. michele2000bon

    michele2000bon

    Joined:
    Nov 29, 2019
    Posts:
    40
    hello guys, i know only this script for movement ,now my player go left and right and this is not okay because player moves slowly like a ball , and i want that he moves fastly from left to right . can you modify the script?:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class basicmovementunity : MonoBehaviour {
    5.  
    6.     public float speed;              
    7.  
    8.     private Rigidbody2D rb2d;      
    9.  
    10.  
    11.     void Start()
    12.     {
    13.        
    14.         rb2d = GetComponent<Rigidbody2D> ();
    15.     }
    16.  
    17.    
    18.     void FixedUpdate()
    19.     {
    20.      
    21.         float moveHorizontal = Input.GetAxis ("Horizontal");
    22.  
    23.        
    24.         float moveVertical = Input.GetAxis ("Vertical");
    25.  
    26.      
    27.         Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
    28.  
    29.        
    30.         rb2d.AddForce (movement * speed);
    31.     }
    32. }
     
    MilchBrocken likes this.
  2. AlexN2805

    AlexN2805

    Joined:
    Nov 27, 2019
    Posts:
    33
    This might sounds obvious, but can't you just increase the speed?
     
  3. MilchBrocken

    MilchBrocken

    Joined:
    Nov 5, 2019
    Posts:
    33
    Do you want it easy or better but difficult?

    If you want it difficult go to YouTube and search for: 2d Movement Brackeys. On the Thumbnail there is a Fox.

    Enjoy and have Fun ;)
     
  4. MilchBrocken

    MilchBrocken

    Joined:
    Nov 5, 2019
    Posts:
    33
    Oh wait sorry it's easy

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class basicmovementunity : MonoBehaviour {
    4.     public float speed = 30f;            
    5.     private Rigidbody2D rb2d;    
    6.     void Start()
    7.     {
    8.      
    9.         rb2d = GetComponent<Rigidbody2D> ();
    10.     }
    11.  
    12.     void FixedUpdate()
    13.     {
    14.    
    15.         float moveHorizontal = Input.GetAxis ("Horizontal");
    16.      
    17.         float moveVertical = Input.GetAxis ("Vertical");
    18.    
    19.         Vector2 movement = new Vector2 (moveHorizontal, moveVertical);
    20.      
    21.         rb2d.AddForce (movement * speed);
    22.     }
    23. }
    24.  
    You don't specified the Speed it's
    Code (CSharp):
    1. public float speed = 30f;