I would need help with a basic gravity script

Hei!

Ive been trying to copy a gravity script which turned out to not beeing functional by my fault! Could someone tell me what are the things I need to add and correct? thanks in advance!

using UnityEngine;

public class GravityBehavior : MonoBehaviour

public float gravitymodifier = 1f;

protected Vector2 velocity;

{
void Start()
{

}

void Update()
{
void FixedUpdate()

{
velocity += gravitymodifier * Physics2D.gravity * Time.deltaTime;

Vector2 deltaPosition = velocity * Time.deltaTime;

Physics.gravity = new Vector3(0, -1.0F, 0);
}

}
}

You have your FixedUpdate inside of Update which is incorrect. I suspect you copied the script incorrectly, please share the original.

I took a look and sadly lost the link to the original which have had been a starter tutorial on YouTube. If you still have the stamina do you possible instead have an idea of a basic gravity script for an 2D Plattformer? :slight_smile:

For starters, I would simply move FixedUpdate outside of your Update method. Since they are empty, you can just delete the Start and Update methods too. Or find the original tutorial, or perhaps Google search with “unity gravity tutorial”. If you are not familiar with deleting C# methods, etc, you might want to back up a bit and learn some C# first.

1 Like

Google found this