#how do I make a thread I am sorry
1 messages · Page 1 of 1 (latest)
thank you
next time use the thread button when hovering over someones message
okay so cant i just write isGrounded = hit
i mean you can but why not just do
isGrounded = Physics2D.Raycast(transform.position, Vector2.down, rayDistance);
well yes i understand that but isnt that the same thing as
isGrounded = hit
yes but you are overcomplicating it by using hit
just call the raycast with the boolean
so get rid of "RaycastHit2D hit" and replace it with isGrounded
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
so then the if statements become
isGrounded = isGrounded?
the boolean is set to true with isGrounded = Physics2D.Raycast(transform.position, Vector2.down, rayDistance);
dont be
he is using it for the input, wait nvm i get what you mean
and "1" in unity is a meter when refering to distance right?
1 unit typically represents 1 meter, yes. in physics 1 (world space) unit is always 1 meter
my caracter is like 40 pixels so should i set my rayDistance to something really small like .01
like .1?
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.
like 1 or 10 etc
this is very helpful im gon na do that right now thank you.
tbh i thought most of my questions were dumb 💀
also how do i make a feild readonly
its saying that in my IDE messages
show us the error/warning
how
a !screenshot
!screen
!shot
i know there is a command for it
but you get what i mean
the screenshots command is the one that says not to take screenshots. use https://screenshot.help to learn how to take one
its for line 12 (my bool variable)
but its a bool variable that i havent used yet "private bool facingRight;"
you don't need to make it readonly, that is just a suggestion since you aren't assigning to it anywhere (yet)
show us your code
and how it isnt working
are you using an Impulse force or the default ForceMode2d?
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);
}
are you grounded?
no
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
show us whats happening
via discord embeded mp4
how do i emb a video
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
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
put [SerializedField] behind private bool isGrounded;
so i can see it
then send another video
okay
i literally set it to 1000 to show its not triggering
i dont know why its not
try using a layermask with the raycast
[SerializedField] private Layermask Groundmask;
put Groundmask after raydistance
rayDistance, Groundmask?
yes
also make a new layermask, and assign your ground the "ground" layermask
then assign in inspector
neato
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
there are tutorials on yt for that, but you would usually check if you pressed the jump button under a certain amount of time while in the air
so rapid presses
but i personally dont know how to do that
is rapid presses the thing in unity i need to learn?
if you want a double jump
i would look up a tutorial on youtube that you understand
then for any questions you can come back here
i mean like is that what its called though, like in script do i put rapid presses
or is that the termanology for it
its not a built in thing, you have to implement it
oh okay
also do you know why this is happening?
@tame edge
show me your character heirarachy
mainly the character object and the character parent colliders
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
i would put the playermesh (playermodel) without a collider and have the parent object with the rigidbody and colliders and scripts the move the playermesh to desired height