Movement script errors

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float moveSpeed = 5f;
public Rigidbody2D rb;
Vector2 movement;
// Update is called once per frame
void Update()
{
movement.x = Input.GetAxisRaw(“Horizontal”);
movement.y = Input.GetAxisRaw(“Vertical”);
}
void FixedUpdate
{
rb.MovePosition } rb.position + movement * moveSpeed * ; Time.fixedDeltaTime;
}

this is the code and here are the errors: Imgur: The magic of the Internet please someone help me i cant figure out how to fix them

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
    public float moveSpeed = 5f;
    public Rigidbody2D rb;
    Vector2 movement;
    // Update is called once per frame
    void Update()
    {
        movement.x = Input.GetAxisRaw("Horizontal");
        movement.y = Input.GetAxisRaw("Vertical");
    }
    void FixedUpdate
    {
        rb.MovePosition
    }
    rb.position + movement* moveSpeed * ; Time.fixedDeltaTime;
}

Hey,

I reposted your code with formatting to make it easier to see.

Line 15 is missing () after FixedUpdate.
Line 17 isn’t doing anything.
Line 17 doesn’t have a ; at the end.
Line 19 isn’t in a method.
Line 19 you have a ; between moveSpeed and Time.fixedDeltaTime;

I recommend starting with some basic tutorial videos on youtube, unity learn, or udemy. This is basic syntax, and you’ll likely learn faster if you have examples to go by.

You copied code wrong from whatever source you were reading. add () after FixedUpdate, add a ; (semicolon) after rb.MovePosition and change the colon from line 14 that’s between moveSpeed * and Time.fixedDeltaTime to an asterisk → *
then, stop using whatever learning material you’re using and look up some c# core programming tutorials (free often) and just learn to program that way. If you don’t, you’re in for a difficult, miserable experience with Unity that doesn’t need to be so. Learn the basics of programming and revisit later. Spend a few hours each day for a whole week straight without using Unity and go back. It’ll make way more sense after that and these type of mistakes will be easy to catch, especially using an IDE that will red underline this. Are you using Visiual Studio on Windows?

Hi thanks for the help and i am just re writing it from a youtube tutorial so thats why there is so many mistakes and i am using Visual Studio on Windows

Hello! This might not be the right place to ask this question on but since unity answers site is down i can’t find another place to ask this question on.

So i’m creating an android game in Unity version 2020.3.13f1. I have a script so the player moves upwards immediately on start and then the player should move around and dodge obstacles and so on… But i have a problem, i only want the player to be able to move on the X axis. The Y axis should be “locked” so he can’t move up and down by touching on the screen. I can’t figure out how to code this correctly, it always ends up in a mess somehow…

Here is my move by touch code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MoveByTouch : MonoBehaviour {

    // Update is called once per frame
    void Update()
    {

        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            Vector3 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
            touchPosition.z = 0f;
            transform.position = touchPosition;
        }
    }
}

@Jacooboo

Hello,

The Unity forums is a great place to ask questions, but next time it you should probably create a new thread as this question isn’t related to the original topic.

I recommend using a Vector2 instead of a Vector3 since you’re only dealing with 2D movement, and with locking the Y axis, it would look something like this:

        if (Input.touchCount > 0)
        {
            Touch touch = Input.GetTouch(0);
            Vector2 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
            transform.position = new Vector2(touchPosition.x, 0f);
        }

When you set the transform.position, you create a new Vector2 with the X axis of touchPosition, and set the Y axis to 0. I hope that helps, good luck.