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

i don't know where it needs the ;

Discussion in '2D' started by exploding_toaster, Jun 29, 2020.

  1. exploding_toaster

    exploding_toaster

    Joined:
    Jun 5, 2020
    Posts:
    46
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. public class movement : MonoBehaviour
    4. { public float yf = 10;
    5.   public Rigidbody2D rb2d;
    6.  
    7.         // Update is called once per frame
    8.     void FixedUpdate()
    9.     {
    10.      //to add force upwards
    11.      rb2d.AddForce(0,100,0)ForceMode.AddVelocity;
    12.     }
    13. }
    14.  
    unity's console wont stop yelling at me to put a ; somewhere but i don't know where

    btw this is a 2d project
    also i use wordpad so it doesn't give me heads ups
     
  2. SINePrime

    SINePrime

    Joined:
    Jan 24, 2019
    Posts:
    54
    ForceMode.AddVelocity is a method argument; it needs to be inside the parenthesis, like so:

    rb2d.AddForce(0,100,0,ForceMode.AddVelocity);
     
  3. exploding_toaster

    exploding_toaster

    Joined:
    Jun 5, 2020
    Posts:
    46
  4. exploding_toaster

    exploding_toaster

    Joined:
    Jun 5, 2020
    Posts:
    46
    rb2d.AddForce(0,100,0,ForceMode.AddVelocity);

    it gave me a error
    Assets\movement.cs(12,38): error CS0117: 'ForceMode' does not contain a definition for 'AddVelocity'
     
  5. Mazer83

    Mazer83

    Joined:
    Mar 14, 2016
    Posts:
    19
    That's because there is no method called ForceMode.
    What you're trying to do is this:

    rb2d.AddForce(new Vector2(0, 100), ForceMode2D.Force);

    or this:

    rb2d.AddForce(new Vector2(0, 100), ForceMode2D.Impulse);

    I'm not sure whether what you want is Force or Impulse, but those are the only 2.
     
  6. exploding_toaster

    exploding_toaster

    Joined:
    Jun 5, 2020
    Posts:
    46
    thanks it worked pefectly