i am trying to use Rigidbody2D to add jump physics to create my first c# project and the code i am using is Rigidbody2D.AddForce(Vector2 force);
this is what i am using to get the force physics and the rest of my code is this
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
Rigidbody2D.AddForce(Vector2 force);
public class NewBehaviourScript : MonoBehaviour
{
public Rigidbody2D rb;
public float jumpAmount = 10;
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
rb.AddForce(Vector2.up * jumpAmount, ForceMode2D.Impulse);
}
}
}
any assistance would be amazing, i am on unity version 2021.3.8f1
thanks in advance
If you have an error, you really should be telling us what the error says.
But just from looking at your script, you should get rid of line 4. It is outside your class and I doubt it would be valid is it even was in your class.
right yes i completely forgot to add the error and thank you, the error is
Assets\NewBehaviourScript.cs(4,30): error CS1003: Syntax error, ‘,’ expected
but as soon as i add the comma it gives the errors
Assets\NewBehaviourScript.cs(4,31): error CS0103: The name ‘force’ does not exist in the current context
and
Assets\NewBehaviourScript.cs(4,22): error CS0119: ‘Vector2’ is a type, which is not valid in the given context
Not sure why you would be trying to assign a sprite to a Rigidbody2D property in the inspector. Just set the property rb in the inspector to be the Rigidbody2D that is attached to the game object that this script is on.
Perhaps show a screenshot of the inspector for this game object?