#how do I make a thread I am sorry

1 messages · Page 1 of 1 (latest)

tame edge
#

here

fluid spoke
#

thank you

tame edge
#

next time use the thread button when hovering over someones message

fluid spoke
#

okay so cant i just write isGrounded = hit

tame edge
#

i mean you can but why not just do
isGrounded = Physics2D.Raycast(transform.position, Vector2.down, rayDistance);

fluid spoke
#

well yes i understand that but isnt that the same thing as
isGrounded = hit

tame edge
#

yes but you are overcomplicating it by using hit

#

just call the raycast with the boolean

fluid spoke
#

so get rid of "RaycastHit2D hit" and replace it with isGrounded

tame edge
#

yes

#

and those if statements

stuck vector
#

you could even do the raycast before the input if statement and just make isGrounded a local variable since you don't appear to be using it anywhere else anyway

fluid spoke
#

so then the if statements become
isGrounded = isGrounded?

tame edge
#

what

#

no

#

just remove them

fluid spoke
#

oh

#

sorry

tame edge
#

the boolean is set to true with isGrounded = Physics2D.Raycast(transform.position, Vector2.down, rayDistance);

#

dont be

tame edge
fluid spoke
#

and "1" in unity is a meter when refering to distance right?

stuck vector
#

1 unit typically represents 1 meter, yes. in physics 1 (world space) unit is always 1 meter

fluid spoke
#

my caracter is like 40 pixels so should i set my rayDistance to something really small like .01

tame edge
#

i would set it higher

#

or else it wont hit

fluid spoke
#

like .1?

stuck vector
#

do not equate pixels to units. if your character is 40 pixels wide and you want it to be 1 unit wide then its pixels per unit setting in the import settings should be 40.

tame edge
#

like 1 or 10 etc

fluid spoke
tame edge
#

also a beginner asking good questions is refreshing

#

so i appreciate it

fluid spoke
#

tbh i thought most of my questions were dumb 💀

#

also how do i make a feild readonly

#

its saying that in my IDE messages

tame edge
#

show us the error/warning

fluid spoke
#

how

tame edge
#

a !screenshot

#

!screen

#

!shot

#

i know there is a command for it

#

but you get what i mean

stuck vector
fluid spoke
#

its for line 12 (my bool variable)

#

but its a bool variable that i havent used yet "private bool facingRight;"

stuck vector
#

you don't need to make it readonly, that is just a suggestion since you aren't assigning to it anywhere (yet)

fluid spoke
#

ohhh okay

#

my code isnt working, i cant still jump as much as i want

tame edge
#

and how it isnt working

stuck vector
#

are you using an Impulse force or the default ForceMode2d?

fluid spoke
#

yes

#
public class PlayerMovement : MonoBehaviour
{
    public float speed;
    public float jumpForce;

    private bool isGrounded;

    private bool facingRight;
    [SerializeField] private float rayDistance;

    Rigidbody2D rb;

    void Start()
    {
        rb = GetComponent<Rigidbody2D>();

    }
    void FixedUpdate()
    {
        rb.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, rb.velocity.y);
    }

     void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space)&& isGrounded)
        {
            rb.AddForce(new Vector2(rb.velocity.x, jumpForce), ForceMode2D.Impulse);
        }

        isGrounded = Physics2D.Raycast(transform.position, Vector2.down, rayDistance);

        


    }
tame edge
#

are you grounded?

fluid spoke
#

no

tame edge
#

the raise the raydist

#

until you are

fluid spoke
#

ohhh

#

i was doing the oposite

#

i had my ray too short so it thought i was in the air

#

wait

#

hold on lemme js test it first

#

yeah i can still jump infinitely

tame edge
#

via discord embeded mp4

fluid spoke
#

how do i emb a video

tame edge
#

make an video

#

and click the + button

#

and click upload a file

#

make sure its short though since you will need nitro for over 25mb

fluid spoke
#

also why is my character like 1 pixel above the ground i checked the colliders, and that shouldnt happen

#

@tame edge

#

no matter what value i put the rayDistance to, i can still infinitely jump

tame edge
#

put [SerializedField] behind private bool isGrounded;

#

so i can see it

#

then send another video

fluid spoke
#

okay

#

i literally set it to 1000 to show its not triggering

#

i dont know why its not

tame edge
#

try using a layermask with the raycast
[SerializedField] private Layermask Groundmask;

#

put Groundmask after raydistance

fluid spoke
#

rayDistance, Groundmask?

tame edge
#

also make a new layermask, and assign your ground the "ground" layermask

#

then assign in inspector

fluid spoke
#

oh.

#

my.

#

god.

#

it works

tame edge
#

neato

fluid spoke
#

um not be annoying but how do i make a double jump

#

because i could just set the value of the rayDistance higher but then i could still jump multiple times until im too far

tame edge
#

so rapid presses

#

but i personally dont know how to do that

fluid spoke
#

is rapid presses the thing in unity i need to learn?

tame edge
#

i would look up a tutorial on youtube that you understand

#

then for any questions you can come back here

fluid spoke
#

i mean like is that what its called though, like in script do i put rapid presses

#

or is that the termanology for it

tame edge
fluid spoke
#

oh okay

fluid spoke
#

@tame edge

tame edge
#

show me your character heirarachy

#

mainly the character object and the character parent colliders

fluid spoke
#

i lost the thread and just found it again sorry for the late response

#

but my player inst a parent or child, it's just its own game object

#

@tame edge

tame edge