#Movement
1 messages · Page 1 of 1 (latest)
yeah you can use the code that ive sent earlier
just remove movVer
and replace it in rb.velocity with, rb.velocity.y
Well, I tried it and I just fly through the ground at insane speeds
Oh it works now for some reason
wha--
Kind of
can i see ?
Idk how to record
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
private Rigidbody2D rb;
public int speed = 5;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
float movement = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(rb.velocity.y * speed, movement);
}
}
```
I changed it A bit
its not right..
Oh
vector2 stores in x and y
so movement should be on x
Vector2(x, y)
this is how vectors work
or not
rb.velocity = new Vector2(movement * speed, rb.velocity.y);
this is how it should be done
you can think of vectors as axis
although im not sure of that
like x and y axis on Vector2
and x, y, and z on Vector3
Ah, works.
Yeap
oke, wanna hop on vertical or ill explain to you how horizontal works?
Now I just need to add a force to velocity in order to stop inf jumping
Let's hop on vertical first
wait, you'll add jumping?
Yea
U saw it
i forgor
np
oh i see
so we will not use vertical movement in that
instead we will use jump
get it?
Yea
welp its up to you what to use
if its vector like movement script or just addforce
What's better, GetButtonDown or KeyCode
i use new input system
cause its kinda easy to put many diff key binds
welp i use GetKeyDown
in the old input
so should i help you in jump mechanism?
Ya
so what do you want to do here?
AddForce, since it is easier to stop infinite jumping
But shouldn't it be ```If Input.GetKeyDown(KeyCode.W)
and ill just help if it gets any error
Sure
no thats wrong
if(Input.GetKeyDown(KeyCode.W)){
this is how it should be done
you put your condition in the brakets
i mean the way you code it is wrong
but the concept is kinda right
eh??
The other one wont "spawn" lkol
the curly brackets?
yea
what ide are you using?
ide?
Visual studio
then why its not working?
No idea
maybe you didnt install it properly?
It worked fine yesterday though
Nope
lmao
Normal brackets work but curly dont
i dont know any solutions about that sorry
np
Uhh
Lol ya
so what's the problem?
Idk where to start
XD
Yeah wtf
can you fix it? XD
{
rb.AddForce(new Vector2)
}
}``` So start like this right
not finished with vector2 yet
in if statement, you dont need ;
and instead add ';' this in the rb.AddForce
rb.AddForce() ;
like put that at the end of the line of code
So not vector2?
i mean i dont know
its up to you
if you want to use vector2
i dont usually use addforce so i dont have a clue about that
U use velocity?
yep
int jumpForce = 69;
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
kinda like this
lmao
add Input
at the first
Input.GetKeyDown
thatll not work if you didnt put it
Definitely did not forget to add input
{
rb.AddForce(new Vector2(rb.velocity.x * jumpForce, rb.velocity.y));
}
}
}
Doesnt work tho
oke lemme rewrite the code
Gonna try veloicty
and also using addforce is kinda wrong
Works
nope, you use th ejumpForce in the x of vector
XD
wanna have a listen first at how vectors work?
i mean i don't know them fully
Alr
first of all do you know axis or the thing, x y and z?
Yeah
so vectors kinda works like thta
Vector2 only uses x and y
incase of your code, you try to jump which is would be on y axis right
yea
but the way you did it was you put the jumpForce on the x
instead of y
so the jumpFOrce would apply on horizontally
in rb.velocity.x
and not in y
so do you understand it now?
oke lemme have you a quiz then
Alr
48
oh wait
but now you kinda get the idea
y will go up and down
x is left and right
z is forward and backward
which is only on 3d
2d is only ay x and y
Yep
so yeah you need to apply the jumpForce right
Yeah I got it
Yep
you could also rb.AddForce(transform.up)
oh nice
I just need it to stop inf jumping
yeah thatll do also
i think
so to stop jumping we need some complicated stuffs
like ray
or you can just use trigger collider
Hol, what do you think is the best for you tho?
to make the jump mechanism?
idk im a beginner too and havent done jumping yet
yes
i think you have way more knowledge about unity than me
but you do right
then what games are you doing?
or you don't do?
you mean like what types of game im making?
yeah?
sorry, im not that good at english XD
english is not my first language im sorry XD
i just started unity like a week ago so i only did one where you dodge a cube which moves in a box and comes towards you whenever it hits the side of the box
wait really??
yes
i started like half a year now, but i didnt actually use unity
cause my pc can't keep up
i just entered a game jam now
that's why i kinda know a lot of stuff
as a beginner
o
that game was pretty sh*t tho XD
anyways i think quentuhnn said he wanted to use rays
Roblox? lol
Brackey's quit right?
i can't change the zip file cause of the rules of the game jam
yep but he still host jams
here's my game XD
its kinda trash tho
i have like 19 scripts in that game
and just make it in a week
if you want to try it, try reading the instructions on how to dl it first XD
cause i kinda messed up in that zip file
IF YOU'VE DOWNLOADED THE ZIP FILE, YOU NEED TO PUT THE "Ror.exe" FILE INTO THE "Ror_Data" FOLDER, BECAUSE I KINDA MESSEP UP XD. I'm sorry about that.
here's the instructions XD
anyways
hows the code quentuhnn?
How :D
I dunno
for starters why not use collider first?
cause its kinda easy to setup and code
it doesnt need a lot of understanding as well
Sure
yup
and also tag the platforms
so
we need to add ONE more box collider to your player
so where to put i hear you asked
from where the feet is
or where the player touches the floor
make it lower a bit
and smaller
did you get it?
done
can i see?
that is scene lol
and search for documentations if you want XD
alr
https://docs.unity3d.com/ScriptReference/Collider2D.OnTriggerEnter2D.html
https://docs.unity3d.com/ScriptReference/Collider2D.OnTriggerExit2D.html
might wanna read these until he comes back
since i think this is what you'll be using
Yup