Horje
Add Force or Velocity in Unity 2d Code Example
Add Force or Velocity in Unity 2d
void FixedUpdate()
{
    //Use Velocity
	if (Input.GetKey(KeyCode.D))
        {
        	//add velocity to rigidbody 3 units along x axis and 0 units along y axis
            //Velocity is not affected by Gravity
            //Velocity i constant in every frame I.e Force=3
            //Velocity starts from the initial value stated which in this case is 3
            //rigidbody2d.velocity = new vector2(x,y);
            //x is sideways and y is upwards
            
            rb2d.velocity = new Vector2(3,0);
            
            
           //To gradually increase Velocity in each frame see the line of code below
           
           rb2d.velocity += new Vector2(3,0);
        }
        
	//OR Use Force
	if (Input.GetKey(KeyCode.D))
        {
        	//Gradually adds Force/velocity to rigidbody 4 units to the right along x axis
            //Force is affected by gravity and Drag
            //Force starts from 0 and increases gradually by 4 units per frame
            rb2d.AddForce (Vector2.right * 4);
        }
}




Csharp

Related
[Package Manager Window] Error while fetching labels: User is not logged in or user status invalid. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) Code Example [Package Manager Window] Error while fetching labels: User is not logged in or user status invalid. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&) Code Example
how to find current country c# Code Example how to find current country c# Code Example
drop multiple database mongo Code Example drop multiple database mongo Code Example
C# Unknown column 'FundAllocation' in 'field list Code Example C# Unknown column 'FundAllocation' in 'field list Code Example
how to combine constructors in c# Code Example how to combine constructors in c# Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7