#help
1 messages · Page 1 of 1 (latest)
yea
Give me a sec to type I'm on mobile after all
its ok
its 2:33am
gotta get the grind
what if i was to create 2 bools where 1 tests if mouse is down and the other tests if the button has been pressed
if the mouse was up then set the other bool to false
3 bools sorry
left bool right bool mouse bool
if left bool and mouse bool = true player move ect
its ok
Public rigidbody2d rb;
Public float Speed;
//True Dir is right
//False Dir is left
MyMethod(bool IsMoving, bool Dir)
{
if(IsMoving)
{
If(Dir)
{
rb.velocity = new Vector2(Speed, 0);
}else
{
rb.velocity = new Vector2(-Speed, 0);
}
}else
{
rb.velocity = new Vector2(0, 0)
}
}
If you try to copy and paste that it will give errors becuase I miss spelt things
er
Some variables are capitals where they shouldn't be
do i just copy it
Dont
I can't use the Tab button on mobile
So I put spaces to make it more readable
Write what you see
Let me know when your done and send a screen shot so I can see if possible
It shouldn't take long to code. When you have your cursor in between things like {} just hit enter and it will put it where it where it should go.
nearly done
K
.
I didn't mean actually write exactly what I had
oh
done
Send new screenshot
Now rigidbody2d
If you hit tab while writing the code it will put the highlighted word
That's what visual studio is for
It's to be faster
So remove the rigidbody2d rb
And start typing rig...
Then hit tab
You will see it autofill
Yea
ok
It can MASSIVLY help
ok
what method
ok
its PlayerMovement
34
Can I see a picture?
Play so these are green indicating that these are classes
You did something wrong
Oh
you need "void"
That needs to be in front of playermovement
You put a - in your code😆
changed nothing
even more errors
Send a picture
its all good now
i get the rb.velocity stuff but everything else sure
The IsMoving will get set to true when we press the buttons
ok
The if statement that is checking the IsMoving is checking to see if it's true
It's short for
if(IsMoving == true)
oh ok
Then we check for the direction we will be moving by making a left/right bool
I just called that Dir
ok
BTW that top info I changed to this in the message
Not positive and negative. I wrote the wrong thing😆
i dont want the charator to move all the time
ok
See that bottom else statement?
else statements are like saying "if the opposite happened do this"
ye
So if we do
{
}
else
{
//This is what happens when it's not true in this case
}```
ok i get that#
So then we will call this method and set that to be false when we release our finger from the screen
👍
Now to set up the buttons then we are done
ok
Remember those components I said to add onto both buttons?
yea
wtf
What?
ah foud it
So you got both buttons all set up?
What are your button names?
left and right#
ok
Make it 1 for now
done
Now go to one of your buttons
Oh and change the comment to this if you havent
change what now
Instead of
//Positive Dir is right
//Negative Dir is left
oh ok
Positive and negative have nothing to do with this. I got those messed up with true and false
ok
I typed the wrong thing basically
Okay so save that
Then go to your right button
Go to that component
Drag the Player gameobject into the gameobject slots for both pointer down and up
wht gameobject
The function we made 🙂
cant findit
Oh that's becuase it's private
And public in front of the void
When you just have void it's short for
private void
cant find it
You need to put the public
i did
Can you send a picture of the menu?
public void PlayerMovement(bool IsMoving, bool Dir)
You selecting the move script of gameobejct?
ye
Can you send a picture of the script and a picture of the component on the button?
That should be all I will need
what component
The component you added to the button
Is the Main Camera the player?
no
Is it the gameobject with the script?
Okay so it was a mistake?
yea
It should be there now.
it still wont show
Hmm
You might not be able to pass multiple peramiters through one button
So change the peramiters to only have int dir
You will get errors again
is moving dosnt exist
Yes
cannot change a int to a bool
still cant change an int to a bool
Let me see the code
Okay now change that Dir to Dir ==1
Okay now change that else below that to
Dir == 2
K
says ; expected
yea
Fixed?
fixed
Good, now lets change those comments again in the script
//0 = don't move, 1 = move right, 2 = move left
ok
Good your understanding it!
Let's go to the components on each button and select the method
Do this for each field
all the buttons are dont with the thing
Okay good!
So on pointer down on the right button make it 1
Then on the left button on the on pointer down make it 2
Then leave the on pointer ups to 0
done
Wdym?
if i hold it it only goes forword 1 bit then stops
Okay
So this is probably your friction
Where you created your script now created a physics material 2d
ok
And set the friction to 0
where is it
lol
Send a picture of the menu
No when your trying to create it
create what
The physics material 2d
how do i get that
R8ght click that grey area where the script is
yea
It's very useful for things like this
Okay so when in create what options pop up?
i did
Like you got the physics material 2d made?
Assign it to the rigidbody 2d
thank you soo much
Wait you did?
yea
Lol
thank you so much
No problem
its 4 am rn bro ☠️
Pm
u in austraillia or smthin
That's why, becuase I'm not doing anything right now
Im not going into details
At 4?
It's am??????
yea
Geeeeez
Lol
Good so if you put a wrong value you now what its doing now and you'll be able to fix it?
yea
when the button is pressed it gives that value and the player detects fro that value and givs an output
Yes! It's checks to see what the value is
yea
yea
It might cause problems
ill add a jump later
not right now im gonna sleep
Okay
tmr?
Gn glad I could help!
what timezone are you so i know when
Maybe. Just ping me, I don't mind
ok well im gmt so yea gn
Gn