I need help with some coding

i am new with coding so i need some help
when unity compiles the script it says that it needs ‘;’ at the ends of lines 41 and 46

If(Input.GetAxisRaw(“Horizontal”) < 0.5f && Input.GetAxisRaw(“Horizontal”) > -0.5f) <---- line 41
{
myRigidBody.Velocity = new Vector2(0f, myRigidbody.velocity.y);
}

If(Input.GetAxisRaw(“Vertical”) < 0.5f && Input.GetAxisRaw(“Vertical”) > -0.5f) <----- line 46
{
myRigidBody.Velocity = new Vector2(myRigidbody.velocity.x, 0f);
}

when i add it it then screws up the if statement
please help!
ps. i use notepad as i cant use visual studio (ik its sad but whatever rlly)

This syntax looks correct something must be missing on previous lines, check yourselft or post full script. Btw, are you using capital I for If or it’s just a typo or autocorrection?

nvm i changed it to lower case and that fixed it
Thanks!

What do you mean you cant use visual studio? Why? Visual studio code is free and small, runs on literally potato pcs. Can you explain why you cant use visual studio?

why do you need to know?

Because I am trying to help you. Didnt realise it was going to be sensitive information.

If you cant answer why your not using an IDE, then good luck getting any useful answers out of anyone here :slight_smile:

2 Likes

Because not using a decent IDE makes the job of programming much more tedious than it needs to be.

2 Likes

Use code tags as shown in the stickied thread at the top of every forum here, and please don’t waste people’s time being combative about really simple questions or they’ll choose not to help you. There’s zero reason not to be using an IDE of some sort, no matter what OS or system specs you have- you can even use a free web-based IDE without installing it locally.

The irony here is that the code tags will do a better job of displaying your code than your “IDE” does…

1 Like

i just realised i signed in with the wrong acc (i dont have access on one)
im stoopid sometimes

Try this

If(Input.GetAxisRaw("Horizontal") < 0.5f && (Input.GetAxisRaw("Horizontal") > -0.5f))
{
   myRigidBody.Velocity = new Vector2(0f, myRigidbody.velocity.y);
}

If(Input.GetAxisRaw("Vertical") < 0.5f && (Input.GetAxisRaw("Vertical") > -0.5f))
{
   myRigidBody.Velocity = new Vector2(myRigidbody.velocity.x, 0f);
}

I guess I should explain why your code is not working. On your if statements you forgot the ( on the second Input and at the end you needed another ) to finish. If you had been using visual studio it would have red lined you and let you know there was a mistake.
Now if you don’t want to use visual studio, then you could use notepad++. I use it from time to time for quick edits with out having unity even opened. It will let you know if you are making a mistake in C#, but not in unity syntax.
Hope this helps.

1 Like

also is there a way to increase the characters horizontal speed in this script?

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

public class PlayerController : MonoBehaviour
{
public float moveSpeed;

private Animator anim;
private Rigidbody2D myRb;

private bool playerMoving;
private Vector2 LastMove;

void Start()
{
anim = GetComponent<Animator>();
myRb = GetComponent<Rigidbody2D>();
}

void Update()
{
playerMoving = false;

if(Input.GetAxisRaw ("Horizontal") > 0.5f || Input.GetAxisRaw ("Horizontal") < -0.5f)
{
//transform.Translate (new Vector3(Input.GetAxisRaw("Horizontal") * moveSpeed * Time.deltaTime, 0f, 0f));
myRb.velocity = new Vector2(Input.GetAxisRaw("Horizontal"), myRb.velocity.y * moveSpeed);
playerMoving = true;
LastMove = new Vector2(Input.GetAxisRaw ("Horizontal"), 0f);
}

if(Input.GetAxisRaw ("Vertical") > 0.5f || Input.GetAxisRaw ("Vertical") < -0.5f)
{
//transform.Translate (new Vector3(0f, Input.GetAxisRaw("Vertical") * moveSpeed * Time.deltaTime, 0f));
myRb.velocity = new Vector2(myRb.velocity.x, Input.GetAxisRaw("Vertical") * moveSpeed / 2);
playerMoving = true;
LastMove = new Vector2(0f, Input.GetAxisRaw("Vertical"));
}

if(Input.GetAxisRaw("Horizontal") < 0.5f && Input.GetAxisRaw("Horizontal") > -0.5f)
{
myRb.velocity = new Vector2(0f, myRb.velocity.y);
}

if(Input.GetAxisRaw("Vertical") < 0.5f && Input.GetAxisRaw("Vertical") > -0.5f)
{
myRb.velocity = new Vector2(myRb.velocity.x, 0f);
}

anim.SetFloat("MoveX", Input.GetAxisRaw("Horizontal"));
anim.SetFloat("MoveY", Input.GetAxisRaw("Vertical"));
anim.SetBool("PlayerMoving", playerMoving);
anim.SetFloat("LastMoveX", LastMove.x);
anim.SetFloat("LastMoveY", LastMove.y);
}
}

thanks!