#⌨coders-cave
1 messages · Page 45 of 1
alright
however
my example is totally flawed in javascript
if i remember correctly
ah i remember what it was
yeah it's totally flawed in javascript
it has a completely different behaviour
var i just takes the last i actually
hm
so it seemed to work the same way as in c#
but that's because i was setting var i = 0
but that's misleading
function someMethod() {
{
var i = 0;
i++;
console.log(i);
}
// i DOES exist here
{
var i; // this i is NOT a new var
i--;
console.log(i);
}
// i DOES exist here
var i; // this i is NOT a new var
i++;
console.log(i);
}
someMethod();
i remember debugging something that fell for this
you expected a local scope like in c# but it actually took over the var from the previous scope
deadly
in javascript it's called shadowing i think
so you have global scope, local scope and variable shadowing
different concept as in c#
I'm vibing with my new codes that I made yesterday
🗿 the title make it sound like an investigation series
The name of steam work shop tho ...
Sends me to nowhere
XD I accidentally deleted it :p
🗿
How do you do that accidentally
but don't worry, uploaded again :p
:3 Don't question it
people work ina mysterious way
Is it the new vehicle mod


intergers are whole values and floating points can have decimals
It was like if you take a float = 1.1
And you subtract it by a int = 1
And I remember the "difference" in math also meant subtracting

I wrote that backwards 🤦🏿♂️
and then there's actual decimal type which no one uses
what code needs 28 digits to function
not even nasa
ok
ok so
creating a variable
and is using the reference Rigidbody
yes
that too
if i'm using this script
on an object that doesn't have the Rigidbody2D, i will get an error ?
as long as it doesnt have switch and enum i will understand the script
._.
no
why
because you are referencing a rigidbody
not the rigidody
you could put the script on a cube with no rigidbody and refrence it to another cube
yes but using this script on an object i'll reference it to the rigidbody2d of this object ?
i don't understand how this is possible
ok so here is an example
ok
wait
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float movementSpeed;
public Rigidbody2D rb;
float mx;
private void Update()
{
mx = Input.GetAxisRaw("Horizontal");
}
private void FixedUpdate()
{
Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);
rb.velocity = movement;
}
}
let's say i have this
public RigidBody2D rb;
i'll reference to the rigidbody of the object with this script
ok ait wrong thing
where the script is there should be a little window where there is a refrrence to the rigidbody
for the rigidbody*
then you drag teh rigidbody into that window
doesnt matter from what object
and boom
lemme show you something else
using UnityEngine;
public class Movement : MonoBehaviour
{
public float moveSpeed = 1;
public Vector2 moveVelocity;
public Rigidbody2D rigidbody1;
void Update()
{
Vector2 moveInput = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
moveVelocity = moveInput.normalized * moveSpeed;
rigidbody1.MovePosition(rigidbody1.position + moveVelocity * Time.fixedDeltaTime);
}
}
very very basic movement script
usually i use character controller but here i cant use that
as i need to have colliders and triggers and yatty yatty yatta
the point is
idk what it is
also if you want a combat script or atleast a representation of one i can give one to you
bUt WhAt If My CoNtRoLlEr IsNt PlUgGeD iN
or is that taking mouse axis
wouldnt think so but 
you plug it in by using unity's attachment system :)
suprisingly enough this is working just as well as if i were to use character controller
kinda i think
the camera rotating in 3d is complicated
using alot of math and stuff
naw
sec
well i mean.. behind the native unity functions yeah probably
but its about as easy as what you showed
the cool thing about it is that you dont have the code that yourself
exactly
float x = rotationRate * Input.GetAxis("Mouse Y");
float y = rotationRate * -Input.GetAxis("Mouse X");
Camera.main.transform.Rotate(x, y, 0);
downside is if you want extra stuff like angle locking... THAT you have to make yourself
Could I make a rigid body move by mouse instead of the normals controls on the keyboard? Like a floaty type movement.
i think you could use what i just showed right?
Input.GetAxis("Mouse Y"); and Input.GetAxis("Mouse X");
instead of the axis you used before
the horizontal and vertical ones?
yeah
i cant
public class DragObject : MonoBehaviour
{
private Vector3 screenPoint;
private Vector3 offset;
void OnMouseDown()
{
screenPoint = Camera.main.WorldToScreenPoint(gameObject.transform.position);
offset = gameObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}
void OnMouseDrag()
{
Vector3 curScreenPoint = new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenPoint.z);
Vector3 curPosition = Camera.main.ScreenToWorldPoint(curScreenPoint) + offset;
transform.position = curPosition;
}
}
I used that
because im not changing the camera, im changing the movement of the player
i mean i could
but then the player would move whenever the mouse moves
well thats what the guy was asking
this question
sorry it was a little confusing lol
ah that question
i didnt understand it at first but now i do
yea im pretty sure that how you do it
Phone died before I got to read cody's response
I was thinking of making a physics-based weapon that's controlled by the mouse that interacts with destructible objects like a wrecking ball connected to the cursor
I wanted to try something new. Maybe I might add tiny NPCs that will try to break the weapon or react
in their attempt to break the weapon they will be demolished lol, this sounds really cool
I got inspired by kick the buddy game and wanted to "expand it"
kick the buddy is amazing in terms of weapon ideas, but the physics on there arent all that great
i mean they arent bad
Cody might be interested to take part in this conversation
yes
he did online stuff for worldbox
I heard it's a new hell from a friend but other than that's out of my knowledge.
to my knowladge he is working on sowmthing similar
What online stuff?
im thinking of streaming some coding here, but dont know if i should
because not many people are interested in coding
@north dune
I think it'll be pretty cool
I meant what was the online stuff cody was doing
not sure i just know he is working on somehting similar
What if two or more online gods made separate civilizations and set them to war to see who would win. That sounds cool in my head
it would be cool yea
oh
People would probably cheat with bubble though
working on an online mod that syncs up many actions/interactions
so far its smooth but ill run into a wall at some point with performance and then the fun really starts
cody
mod is also very easily converted to other games
ive already tested connecting from one game to another, can send commands/chat messages just the same
unet, peer to peer/pc is server yes
hmm ok
So basically you'll run into a point where your code is either too slow or messed up because you lost track of something?
and is it taking much resources ?
the idea right now is for one world/computer to host and be the facilitator of commands for everything else
cuz i want to make a game based on a game i did on Discord
but the fact is that discord is hosting the game
so
more like ill run into a point where my packets/commands are being spammed too much or some other weird problem with them
there is so many stuff i'm wondering cuz damn idk how to start
very slightly more than a normal game
not noticable difference yet
but i cant speak on the ping/lag, i have only tested local connections
Ah I see
and one single online test
hmmm
which was early, before there were any commands/actions being done
the source for this mod will be public as soon as im comfortable posting the mod itself
How do you deal with that problem tho?
currently im sending commands as strings that get converted into commands and parameters on the clients
theres bound to be plenty of ways to optimize how that happens
client does an action like click to place a radius of dirt
client sends this action to the host so the host will mirror it on everyone elses client
host parses the action, executes it on host world, relays it forward
other clients parse the action, execute it on their world, send a response if necessary
im relatively confident so far but eventually something will come up
cody
do you know any place i can find cool texture
other place than unity asset store
Not really, most of the stuff I've played around with husband off of Google searches and not exactly legal all the time
Has been*
so anyone have any idea for how i can randomize what items spawn if i have ALOT of items, kind of like in binding of isaac? i can think of some ways but they would require me to go over every item
i would have an idea
but like
with my python knowledge
i guess it's also possible in C sharp
where do you store your items
my first idea was to give every item a tag that is a single digit, make a random intrange and whatever item i get i instantiate
items
this scares me, dont tell me i will have to write out every single one in a script or something
I was thinking maybe making a list method that generates random items but that can get complicated easily. I summon the coding goat @north dune
yes i would gave them a tag, put all tags in a list and then use a random module to get a random int and use this int as index
we shouldnt ping him this freely,after all he probably has his own work
list.GetRandom?
list of item names or whatever, then pick one at random before doing what you need
haydot need help with spawning a lot of random items binding Isaac style
because i get this random number, i get what item i want but then how do i instantiate it, how do i get its name
my first thought was that it would have a very simple single digit name
that is the same as its tag
hmmm interesting i will try that
because i get this random number, i get what item i want but then how do i instantiate it, how do i get its name
why cant the name be the number? if you need a different string to display for like a name tag or something, give it a new ID string or something
if the name = number, you could just do like you already said and random a number and get the item from that, which is a bit easier than list.GetRandom
and i promise im not a great coder, i give shit advice plenty often, ask @keen shell how many times ive wasted his time
lmao
Hahaha
take what i say with grains of salt and google often
Google is built different
why cant the name be the number? if you need a different string to display for like a name tag or something, give it a new ID string or something
worldbox uses libraries like this
you could have a similar library of items that applies an id/number as theyre set up
Haydot is typing a essay in MLA format
if you mean me i dont mind at all, if im busy i just wont respond
will respond eventually most of the time
so it would work sorta like this:
void OnCollisionEnter(Collider2D collider){
if(collider.gameObject.tag == "player"){
public IntRange item = new IntRange(0, itemCount);
Instantiate(dont know how to get the name here, transform.position);
yes
exactly
i dont use object.instantiate like ever, so i dont have any advice on using it :/
the times ive used it i already had an object to copy from, if im creating a new object id do it differently
alright well you guys helped me enough, i just need to figuere out how to put the name in there and i will almost be free from this script
hell yeah
then i have to make the 10 times more compicated script
which is generating rooms and dungeons
Lmao I never agree that you wasted my time but that's because we always have nice conversations in between and afterwards and it never truly goes wasted because you helped me keep going and be motivated to try other things
youre too sweet to say i wasted your time with the attempt at code help
haha
conversations are always nice either way, but all those times im like "do this! try that! maybe this is a better idea" and it was just a fail

talking to people about code is always nice while coding, it gives you motivation to keep going and lets you take a break from all those floats and ints
for sure
just writing out what my problem is helps me figure it out a lot
will start bitching to someone and stuff will click while im typing to them
this is very true
what programming language is used in world box?
c#
nice
007!help
Ha
Hippity Hoppity, your code is now our property
You're not wrong...Most coding work is just Borrowing other people codes (Mostly in AI, ML development)
most of the things you think or do have been done before, same goes for code
for some things its way better to use someone elses work than redo it all
You have other problems then questioning if it fine to use someone else code...So Yeah, You do you
why can't i use a double in Vector2
Cuz they take more memory and the accuracy isnt needed in game development
At least that's what i think
hmm
i'm new to C sharp and i can't find how to move something smoothly without using Force

2d or 3d ?
2d
What do you mean move smoothly
Like doesn't stop immediately
Or is it just jittering when its moving and u dont want that
i mean
when i use translate
for example
my object is just teleporting
not moving
And why is that a problem
i'm just looking for it, now for a dumb example but i want to make it later for something else
for example
The script will move an object to the left
for like
16
from x 0 to x 16 for example
So
First you need to multiply the movment speed by deltatime
Do you know what that is
?
yes
welp let me send a very very little code
U can make it like a velocity and add a decay for a delayed stop
And i suggest making your own collision system
this is
uh
the thing
it's very small and don't mind why i run the code on a collision event
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public float movementSpeed;
public Rigidbody2D rb;
float mx;
private void Update()
{
mx = Input.GetAxisRaw("Horizontal");
}
private void FixedUpdate()
{
Vector2 movement = new Vector2(mx * movementSpeed, rb.velocity.y);
rb.velocity = movement;
}
void OnCollisionEnter2D(Collision2D collision)
{
print("Test");
transform.translate(-16, 0, 0)
}
}
i think this was my code

Youre not using deltatime
idk how to use it correctly
Just multiply the speed by it
And you dont need the collision event
Because you're using a rigid body and velocity
no i mean
i'm using the collision because
i want my object to go on the left when it collides with the ground
but
it's just to test
yes
yes
Cant you just override the velocity
wdym
Make the velocity -16,0
Yeah
But multiply that by deltatime
Always
So it's the same every time
Or no
Wait
Just when you're mocing the object directly
Im a bit rusty with unity
Its been like 1 year
Now theres a problem with this
yes
What does it say
You forgot new
Don't worry youre still new it will click one day
Even to this day i use ; in python
I cant stop
And the {}
ye
Instead of tabs
Does it say test
But its not moving
Oh
So ehen you dont click any key
The mx is 0
So every frame
Your velocity is being set to 0
So even when u change it
It will be back at 0
That's why
When i make 2D games i dont use unity physics
So
Hmm
Yea i know
Wait
Lemme think a bit
Ok
So
You have to delete everything in the script
Rework time
Did you do that?
Rework
Thats what rework mean
Instead of using a rigidbody
Which is bad in 2d
You're gonna make you're own collision and movement system
i'm a beginner though 
Its not that hard
First
You need your horizontal and vertical velocity
Just make two floats
Hs and vs
Or what ever u wanna name them
public i guess
Because you're not gonna access them from outside the class
And go to your object
In the inspection tab
And make the rigidbody
okey
Kinematic
what's the difference between kinematic and static
static don't move
and kinematic isn't impact by gravity ?
Yea static dont move
Idk i forgot
That's why i want to ask you
Does it still fall?
nope
Nice
Saves work
Now make a public float
Or two
One is called speed
And the other is called gravity
Set them to one
Youre gonna chnage them after
ok
Now lets make it fall
So gravity adds up as you fall
But
It doesnt keep adding up
There's a terminal speed
You might wann add another float called terminal speed
All done and ready to implement gravity?
Yes indeed

what does that mean
is method in C# = Functions in Python
?
lol
Yes
ok
Update runs every frame
i have heard FixexUpdate is better for physics stuff
FixedUpdate runs every 0.2 seconds
So its frame independent
Which makes it better for physics indeed
oh ok
But we are going to use deltatime so it doesnt matter
okey
Ok
So
Every frame
You add the gravity to vertical speed
So it will look something like
vs += gravity;
Yes
Yes
But dont worry about that
Now
Lets see if its working
After adding the gravity
Write
Transform.Translate(new Vector2(0, vs));
Done?
yes
Now run it
You will notice
That youre object is going up
And it becomes very fast
Is that what happened ?
no i got an error and i try to solve it
this wasn't working, so i turned it into ```c
transform.translate = new Vector2(0, vs));
but
i got an error
Expected ";"
Ok
First
Its a method
Not a property
You cant use = on a method
You cab call a method
It shouls be like this
transform.translate(new Vector2 (0, vs));
Assets\Scripts\PlayerMovement.cs(14,19): error CS1061: 'Transform' does not contain a definition for 'translate' and no accessible extension method 'translate' accepting a first argument of type 'Transform' could be found (are you missing a using directive or an assembly reference?)
Ok
So first
You see that +=
Make it -=
So it goes down
And in the Transform.Translate line
Next to vs
Write * Time.Deltatime
The D should be d
I think
It should autocorrect
Wait
Is it not autocorrecting anything unity related
Time.deltaTime it is 
Ok
So its falling fast
Because theres no terminal speed
So we need to check if the speed is above the terminal speed
So before the transform.translate
i think it's so fast the game can't calculate the collisition with the ground 
what do you mean by terminal speed
is it not comparting vs and terminal speed
When you reach the terminal velocity youre acceleration is basically 0
instead of speed and terminal speed
I don't get what youre trying to say
so
to do this, i'll use a if condition
what i got now is
public class PlayerMovement : MonoBehaviour
{
private float hs;
private float vs;
public float gravity;
public float speed;
public float terminalSpeed;
void Update()
{
vs -= gravity;
if (terminalSpeed < speed)
{
}
else
{
transform.Translate(new Vector2(0, vs * Time.deltaTime));
}
}
}
First
You dont need that else statement
You want to keep falling
But you want your speed to be constant
And
should i put the vs -= gravity in the if condition
it will still increase the speed of falling then no ?
You will see after
But with speed
I mean youre vertical speed
The public speed field will be used for moving horizontally
So use vs instead of speed
Done ?
np
Ok go ahead
Let me ask you a question
What do you think we are going to use the publick field speed for ?
Does the player control his vertical speed ?
no
So its the horizontal speed of a player
But its not even a speed
I dont know why i called it speed
Its basically the horizontal acceleration
You might wanna change it to acceleration instead of speed to avoid confusion
Or you can keep it
I have the horizontal speed and the vertical speed, the vertical speed is to calculate the speed of the falling
the speed is the speed of my player
Oh wait
Im dumv
Yes its speed
Yes its the speed of your player
Ok
Terminal speed should be a negative number
Cuz falling is considered negative
So change ot to -1 instead of 1
All done and ready to continue?
No need to make it realistic
When we are done you can play with the numbers
Until it feels natural
ok so let's say i put it on 1.5
no
2
on 2
what should my terminal speed be
-3 ?
something like that
Idk
You just have to play with the numbers
When we are done
Until you like how it feels
Are you ready ?
ok
uh
i don't know why to use my if statement yet
and what to put inside
and what to compare
So
The last pic u send me
Is correct
Inside the if statement
Set the vs to the terminal speed
wait so let me resume
every frame , i do vertical speed - gravity
if my vertical speed is higher than my terminal speed
i set the vertical speed to the terminal speed
Yes
and i apply the translation
Yes
ok
Basically youre vs cant get under your terminal speed
So tou cant fall faster than your terminal speed
Go test it
ok now it's falling
Not very fast?
You guys have been talking here for so long, very nice
xd
I have a lot of free time and im bored af
Cube go brrr
Is gray supposed to be a floor?
I think so
ok
First comment the transform.translate part
So the cube dont fall out od the screen immediately
//
Yes

wdym by that
Because there's no collision the cube will fall out of the screen and you cant test horizontal moving
Dont worry when we are done you can uncomment it
Get me a picture of the whole script
Why no collisions first?
Ok all looking good
The way i implement this is after you move you check if youre colliding then you move back if you are
All on the same frame
So it looks smooth
Oh so for smoothy
why not add a simple collision while testing and improve later tho?
Dont worry
We'll implement a simple version bod what i said first
It wont be very good
Ok lets continue try to finish as much as we can before you have tongo
So now you want to check what keys you have pressed
If A go left else if D go right Else dont move
yes
So write the first if statement
In it you need
Input.GetKeyDown("a")
This is the condition
Before we fill it in you can erite the other if statement
what's the difference between GetKey and GetKeyDown
Getkeydown sounds like it updates when the key is being pressed
Get key sounds like an activation that happens once or twice but I'm not sure
@barren shale i'll have to go now ^^
but
I remembered the difference
i got this
Bey
Soo this is where all the nerds go
if (Input.GetKey("d"))
{
}
if (Input.GetKey("q"))
{
}
Oh really lmao
Np
can i add u friend ?
Sure
C#
🗿 most of the time you ask that on #🔧modding-talk
But this place is fine
well crap i don't know anything about C#
oo ok
how does one send and receive packets from 1 machine to another machine
rather confusing for me
how do things like socket work inside it
the sending the actual bytes
bytes into radio waves or something and into bytes again
networking is weird
Its weird
people dedicate their whole lifes to it and still don't understand it all in some cases
but it's super super super important
especially wireless which is the weirdest thing in iy
aw yeah
i forgot its just electricity
yes i agree
it would be easier and less latency with cable connection
0 means no electricity and 1 electricity actually but little thing
its basically super super small electrical current
Actually no
but well it's way less practical
I thought it was like this
basically just a piece of metal
But rhen i read about it
cpu is mostly just a clock but in drugs
or a super busy executive
it doesn't process bits mostly
Its more complicated than that
it reads ram which has those instructions and runs them. Or this is the basics of iy
ram are just harddisk
it's way more complicated but it's not important to know much better
except faster
actually no
it's way too hard to explain ngl
Go read a book about it
im poor
just watch this if you're interested https://youtube.com/playlist?list=PLH2l6uzC4UEW0s7-KewFLBC1D0l6XRfye
i already did that
Way better than asking someone to explain
YouTube is better
i watched bunch of random crap
about bytes
and low level things
even to the point of how electric flows
in a gaming way
More fun
more ram = more performance
Oh yes
better gpu = better graphics
Downloading ram
yes and no, ir depends on other factors too
I personally have 20 gigs for ram but you don't really need that much
it doesn't help much
the hell
i only have 2-4
lol
Have two 4gb is better than having one 8gb like me
I only use like one fourth of my ram usually
and i use 100% of it
but when I code it might go to like 12 gigs used
how
yep
Shit
are you making
find square root of ur mom
Only AI would rake that much ram
I like GitHub
do you use gitlab then?
no
GitHub and gitlab are the 2 I know
i use github
but not often
just when i need to TEACH THIS KID HOW TO USE GITHUB EVEN THOUGH I HATE USING IT
oh wait let me connect my account to github
I use git in bash because I use WSL for coding
well mostly for coding @bitter sedge but still
eh it says failed to connect
here's a weird things
i use my phone

i can't afford a pc so i use my phone
Wtf
damn
Programming on phone
it's actually relatively easy
U just said u had two 4gbs
meh you'll get used to environmental issue, compatibility error, missing permission, lib missing, headers not found, directory conflict
also npm will suck your internal storage dry
Woah
symlink are broken
How tho?
and binary files aren't running in internal storage
i dont have a pc because im poor
It's easy tho to get shitty pc almost free, I used pc I got with 12€ until last week when I bought decent pc
im a minor
I mean, which way of Coding you do with what kind of app
and my family is having a financial crisis
Electricity is other thing tho
what do you mean by that
ah
Like where do you code on phone
Visual studio on phone
not available
Would be nice
unless i install linux with gui
I actually got it to work with 2 fps once
is this sarcasm
lemme find the google article I used to help me
and most of my storage are filled with numbers
I used termux
yes
they discontinued the play store version
now only on f droid
with latest update
so the newest package doesn't scream at you
https://wiki.termux.com/wiki/Graphical_Environment
I used this and just normally installed vs after I got the gui working
Probably start saving from now and get yourself a cheap pc
how to save money
which app?
i dont even get an allowance
termux
No they didn't
Even if it is 1 euro per day
I have it in play store
Don't you get school allowance
newest is in f droid
no why
Wtf
What newest?
why would you give ur kids school allowance for online class
version
Oh online school
version of what
ohh
How old are you
so no new package will be fetched
Cant you get a part time job
14
yes and no


