#💻┃code-beginner

1 messages · Page 498 of 1

rich adder
#

just an example like if it were a loop. Each iteration is adding an offset + the iterator value (the i in the loop)

#

its not once you learn all the basic pieces

#

your only limit after that is how much your brain can muster some logic 😛

sand snow
#

like i understand the logic of it, i just dont know how to write it out

turbid robin
verbal dome
#

If you can already understand the logic then you have a good headstart

#

The syntax etc. comes with practice

sand snow
verbal dome
#

How long have you been learning?

turbid robin
#
gridCube.transform.position = new Vector3((bottomLeft.x + (blockSize/2f)), (bottomLeft.y - (blockSize/2f)), gridCube.transform.position.z);```
why with this line of code the blcoks get placed here? (blocksize = 24f)
sand snow
#

3 days 💀 but like 12+ hours each day

steep rose
#

ah i forgot, jumping with addforce is fine Unless you have Forcemode.impulse at the end of it i said it the complete opposite

verbal dome
#

Yeah no one knows what they are doing after 3 days

rich adder
#

I think

sand snow
steep rose
#

i said it complete opposite

#

LMAO

sand snow
#

oh so i need to add impulse to it?

verbal dome
#

Impulse for one-shot forces

rich adder
#

Impulse is fine in Update / One frame function if its in Impulse

turbid robin
# rich adder again you're using world position
                // Bottom left corner
                Vector3 bottomLeft = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, 0)); 

                // Place block
                gridCube.transform.position = new Vector3((bottomLeft.x + (blockSize/2f)), (bottomLeft.y - (blockSize/2f)), gridCube.transform.position.z);```
this is the full code
steep rose
#

you need Forcemode.impulse if you are going to jump in update

#

sorry im a wreck

sand snow
#

where do i put it

#
 void Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        rb.AddForce(new Vector2(rb.velocity.x, jumpForce));
    }
}
rich adder
sand snow
#

okay so after jumpForce)?

rich adder
turbid robin
verbal dome
rich adder
#

yes you need 2d version

verbal dome
#

This is how I usually reach the documentation

sand snow
#

like this?

 void Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        rb.AddForce(new Vector2(rb.velocity.x, jumpForce)ForceMode.impulse);
    }
}
rich adder
#

no

sand snow
#

oh thank you for reminding me

rich adder
#

ForceMode is wrong

turbid robin
rich adder
steep rose
#

you need ForceMode2D

rich adder
#

impulse is also capitalized which leads me to believe OP does not have configured IDE

steep rose
#

its most likely not

#

!ide

eternal falconBOT
sand snow
rich adder
steep rose
rich adder
sand snow
#

is that the thing when you connect your unity to visual studio?

rich adder
#

yes

sand snow
#

I have that set up

steep rose
#

visual studio is an IDE

rich adder
#

visual studio is the IDE

turbid robin
# rich adder do you have a loop or is that the only code ?

i have a loop, let me send it all

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                GameObject gridCube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                Renderer renderer = gridCube.GetComponent<Renderer>();
                if (height % 2 == 0)
                {
                    renderer.material.color = Color.black;
                }

                // Bottom left corner
                Vector3 bottomLeft = Camera.main.ViewportToWorldPoint(new Vector3(0, 0, 0)); 

                // Place block
                gridCube.transform.position = new Vector3((bottomLeft.x + (blockSize/2f)), (bottomLeft.y - (blockSize/2f)), gridCube.transform.position.z);
            }
        }```
widh and height are both 10
sand snow
#

oh

rich adder
#

it would give you an underline red

steep rose
#

or squigglys

rich adder
sand snow
#

this has no errors so there are no red squigglys

     void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            rb.AddForce(new Vector2(rb.velocity.x, jumpForce), ForceMode2D.Impulse);
        }
    }
}
turbid robin
eternal falconBOT
rich adder
steep rose
#

configure it, right now its like using notepad

turbid robin
rich adder
sand snow
#

yes i have it setup already

turbid robin
steep rose
sand snow
#

yes i have been able to see that

turbid robin
#

but why? as far as i understand +24f (exmaple) should add 24 pixels

steep rose
sand snow
#

sorry for the confusion

steep rose
#

well now you can use the addforce in update()

sand snow
#

yes it is all fixed now

#

thank you guys 🙏

rich adder
# turbid robin i also think that

try rq

  gridCube.transform.position = new Vector3(
            bottomLeft.x + (i * blockSize) + (blockSize / 2f),
            bottomLeft.y + (j * blockSize) + (blockSize / 2f),
            gridCube.transform.position.z
        );```
steep rose
#

and yw

sand snow
#

i have another question, when i jump midair and walk in to a wall (while still being airborne), why do i stick to the wall instead of keep falling @steep rose

rich adder
# turbid robin

ah shit lol myb I think you want

      bottomLeft.x + (i * blockSize), 
            bottomLeft.y + (j * blockSize), 
            gridCube.transform.position.z
        );```
sand snow
#

but why do i not fall down?

rich adder
#

you keep applying force towards a wall

#

thats unnatural

sand snow
#

is there anyway to make my character fall?

rich adder
#

when something hit the wal it stops velocity forward then falls down

turbid robin
# turbid robin

now it stats from the bottom left, but still it isnt added the half pixel size

sand snow
rich adder
rich adder
sand snow
#

im guessing ill need to use tags and like a wall check or something?

rich adder
#

your blocks dont look like 24 meters big

turbid robin
#

meters?....

sand snow
turbid robin
#

should it be pixels?...

rich adder
verbal dome
rich adder
rich adder
#

what I typically do is use a SweepTest or raycast

#

if the path is blocked dont apply force that way

steep rose
#

you either would make a different collider for wall collisions or write your own friction code

sand snow
#

is it just a ground check but for a wall?

rich adder
rich adder
polar acorn
steep rose
#

and make it only when you are airborne as well

turbid robin
rich adder
#

eg
32 pixel square, set to 32 PPU
32 pixels = 1 unit = 1m in unity

sand snow
steep rose
polar acorn
rich adder
#

dont you have a isGrounded?

turbid robin
sand snow
steep rose
polar acorn
rich adder
turbid robin
steep rose
sand snow
#

so private bool isGrounded

rich adder
turbid robin
#

oh the black box

rich adder
sand snow
#

hold on I will be right back I am going to try to make a code

polar acorn
turbid robin
#

i was thinking the main camera

polar acorn
#

and see what it does

turbid robin
rich adder
#

if you're using the default unity square idk what the PPU is and i dont know how to change is as the texture is hidden for some reason

turbid robin
rich adder
steep rose
turbid robin
rich adder
polar acorn
#

This is Mega Man. He is 21 pixels across. If you wanted Mega Man to be the same size as a cube of scale 1,1,1, you'd make his sprite's PPU 21.

steep rose
rich adder
#

me too i need me some tea

#

🍵

steep rose
#

water for me

rich adder
#

my water is just hot 😛

turbid robin
formal sable
steep rose
sand snow
steep rose
verbal dome
polar acorn
rich adder
#

if you paste link into text it auto creates the required markdown

steep rose
#

neato

rich adder
#

[ThisIsALink](https://)

steep rose
#

i was wondering how you did that

turbid robin
sand snow
rich adder
sand snow
#

it just gives the public effects to the private void?

polar acorn
polar acorn
steep rose
sand snow
wise spoke
#

Hello, someone know how to declare a list in list ?

rich adder
polar acorn
turbid robin
steep rose
#

Public makes it public to all other scripts

polar acorn
steep rose
#

to be used

sand snow
#

OHHHHH so it makes it public for the inspector tab but no other scripts or gameobects, correct?

steep rose
rich adder
turbid robin
polar acorn
polar acorn
sand snow
#

so whats the point of it? why woudl i keep it private instead of making it public at that point

steep rose
rich adder
#

very important concepts of OOP

sand snow
polar acorn
rich adder
#

so other scripts dont accidentally reference it and modify it

turbid robin
polar acorn
#

they just are that size

sand snow
#

literally learning more in a 20 minute conversation in discord than 10+ hours on youtube

rich adder
sand snow
#

i guess just being able to ask questions is that powerful

wise spoke
steep rose
turbid robin
steep rose
rich adder
sand snow
#

yeah i try not to use youtube, its literally so terrible for learning tbh

rich adder
#

just make sure to google anything you do not know etc. and yes doesn't hurt to ask clarification here

turbid robin
#

the problem is that i want to be sure that the block gets placed in the bottom left corner but not from the center

rich adder
#

looks like it

turbid robin
#

it is

sand snow
turbid robin
#

but from the center of the black block

rich adder
#

well yeah thats where the pivot is

steep rose
#

we explain (hopefully)

rich adder
#

transform.position always goes from the pivot

turbid robin
formal sable
rich adder
# turbid robin can i change it?

its tricky in unity, you either make a parent then adjust child until it looks correct as pivot you want (then use parent transform.pos)
or you use modeling program to fix it beforehand

#

or just add offset in code to compensate

turbid robin
rich adder
turbid robin
rich adder
#

if block is 6,6 and pivot is 3,3 you add the 3,3 offset

rich adder
turbid robin
#

the block is 1,1. i should ass .5,.5?

verbal dome
rich adder
#

yes

turbid robin
#

ok let me try

sand snow
#

can i use vector2 instead of vector3 with physics.raycast?

#

or am i just not even understanding the concept correctly

rich adder
#

for 2D colliders

verbal dome
sand snow
rich adder
#

they are interchangeable btw though

turbid robin
rich adder
rich adder
turbid robin
rich adder
turbid robin
#

this is my goal

rich adder
#

if thats default cube

rich adder
sand snow
#

before i make my raycasthit, it makes sense to make a ground check first right? @rich adder

turbid robin
turbid robin
#

there will be things placed right on top of that and i will use the array for the pathfinder (at least i hope)

rich adder
#

look into making the cube an actual Object

rich adder
rich adder
sand snow
#

im about to try to make one right now

rich adder
#

ohh then yes make one first

turbid robin
sand snow
#

i just need a private bool and the use of tags right?

rich adder
# turbid robin why?

so you can easily reference that position,clicks etc. unless you have a 2D rapresentation of it in code

rich adder
sand snow
#

oh

rich adder
sand snow
#

like if my velocity is more then 0 on the Y axis then I am airborne

#

then for isGrounded would be false

#

right?

rich adder
#

if you do that there is no point in raycast

#

I wouldn't rely on that if you're gonna use a raycast

steep rose
rich adder
#

also grounded is not guarnteed to be rb.velocity = 0

sand snow
#

well do i need a raycast?

rich adder
#

as it fluctuates when ur on floor

sand snow
#

i thought the raycast was so i dont stick to walls

rich adder
#

yes but can be used for grounded

sand snow
#

okay just to clarify, I need a raycast for a ground check?

steep rose
#

yes

#

or spherecast/ boxcast / checksphere, etc

frosty hound
#

To clarify, you need a cast of some sort, it does not have to be a sphere.

#

Casting a ray into the world gives you back information. The shape you want to use, be it a ray, a sphere, a capsule, etc. is up to your usecase.

sand snow
#

i think i will use raycast, in order to do the ground check with this, i need to put the max distance of it to a small number though right?

steep rose
#

but yes and no

#

depends on how large/tall your character is

#

you would preferably make it a [SerializedField] private float so it can be changed via inspector

sand snow
#

my character is like 30 pixels tall or something

#

i forgot

#

i made it in photoshop

#

can i show you in dms what he looks like

steep rose
sand snow
#

i just meant like if you wanted to see 😭

steep rose
sand snow
#

what does "public static" mean in this

public static RaycastHit2D Raycast(Vector2 origin, Vector2 direction, float distance = Mathf.Infinity, int layerMask = DefaultRaycastLayers, float minDepth = -Mathf.Infinity, float maxDepth = Mathf.Infinity);
steep rose
#

its the same variable of a class thats created i believe

rich adder
sand snow
#

wait bruh i just realised, i need the ray to be casted in the direction im walking, so dont i need to make a code to recognize which direction im facing too?

rich adder
cosmic dagger
verbal dome
steep rose
sand snow
rich adder
#

my platformers always have transform.right as forward

#

but yeah a bool can work to track

steep rose
#

it really depends on how you made it facing in the first place

sand snow
#

i think I will make a bool

#

is one of the options better then the other?

rich adder
#

no

steep rose
#

both are good

rich adder
#

as long as things work, there is never "better than other" (aside from writing code smells ofc lol)

#

whats good is that it works.

#

everything else is preference

tender stag
#
using UnityEngine;
using UnityEditor;

[CustomEditor(typeof(Interactable))]
public class InteractableEditor : Editor
{
    public override void OnInspectorGUI()
    {
        Interactable interactable = (Interactable)target;

        DrawDefaultInspector();

        if(interactable.useSingleInteraction)
        {
            interactable.useOpenInteraction = false;
        }

        if(interactable.useOpenInteraction)
        {
            interactable.useSingleInteraction = false;
        }
    }
}```
#

why isnt this letting me set the bottom bool?

sand snow
#

why does transform not work here

RaycastHit2D hit = Physics2D.Raycast(tranform.position, Vector2.down);
cosmic quail
tulip nimbus
#

Is there a way to access my prefabs when they are not in Hierarchy? I want the changes to apply to all future prefabs

#

nvm found it

sand snow
tulip nimbus
#

I went to "Open" thats right, right?

rich adder
#

we told them already

cosmic quail
#

my message is blocked by this server apparently

rich adder
rich adder
polar acorn
sand snow
tulip nimbus
# rich adder Openn ?

I clicked on "Open" in the Inspector in the Top Right corner and i could edit the thing. Is there a better way?

sand snow
rich adder
polar acorn
sand snow
#

i didnt realise the typo because when i hovered over the red i was trying to read what it said and when it said it doesnt exist in this context, i thought i was using transform incorrectly, i didnt know that i had misspelled it. now i know i guess

rich adder
cosmic quail
sand snow
rich adder
#

gotta check again lol

cosmic quail
rich adder
sand snow
#

yes i am 10000% it is configured, sorry for the confusion

#

so with all that out the way, this code should theoretically shoot a ray towards the ground wherever my postion is right?

RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down);
rich adder
sand snow
#

so now i can make an if statement using the "hit" right?

verbal dome
rich adder
#

but yeah still use layers, its one of the params

languid spire
sand snow
#

whats iirc

rich adder
rich adder
languid spire
#

nope

slender nymph
verbal dome
#

2D raycast hit has implicit bool cast

sand snow
#

also whats null

rich adder
sand snow
#

null means nothing?

swift elbow
rich adder
#

correct

swift elbow
#

no reference or doesnt exist

polar acorn
sand snow
polar acorn
sand snow
#

well doesnt that line of code just make it so i can refer to it as "hit"? if so than yes i think so

swift elbow
night valve
#

Normally you'd want to dynamically cast these rays multiple times during gameplay

rich adder
#

yes for a ground check you don't want to do it just once 😛

sand snow
polar acorn
sand snow
#

i just need someone to clarify to me that that code just makes it so i can refer to it as "hit" or if it doesnt

night valve
#

Well, you could need a onetime check if you wanted for eg to snap object to the ground once it's created

rich adder
#

but this now will Detect Anything including the player or maybe triggers which you might not want for solid grounding, so we use layers params

sand snow
polar acorn
sand snow
polar acorn
#

You can freely use that result whenever you want to know what the result of that hit was

rich adder
sand snow
#

so its constantly checking if i am on the ground or not right?

polar acorn
#

So putting it in start would mean you could very easily know if the object started on the ground

rich adder
polar acorn
#

but that's not particularly useful information

steep rose
sand snow
#

so this ground check now works?

 RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down);

 if(hit.collider != null)
 {
     isGrounded = true;
 }
 else
 {
     isGrounded = false;
 }
night valve
#

Debug.Log is the tool to check this

steep rose
rich adder
steep rose
rich adder
#

also like above i sent
isGrounded = Physics2D.Raycast(transform.position, Vector2.down);

steep rose
#

also you would want a float for the distance variable in the raycast so you can change it

#

so its not inf

#

and a layermask as well

sand snow
rich adder
#

only in this specific cause because unity does an implicit cast

steep rose
cosmic quail
rich adder
#

hit in general is useful if you want spefic information like how tilted is the collider you hit, or maybe if it has other info you need

sand snow
#

and if i named hit something different like, potato, then i would use "if(potato)" right?

steep rose
#

which is the norm

sand snow
steep rose
#

all the layermask does it only hit "ground"

#

if you set player to "ground" you will always be grounded, which im guessing is not preferred

sand snow
#

oh okay thank you

#

jeez this is all so complicated, literally just to get some movement in my game

steep rose
#

you will get used to it

rich adder
#

took me months to wrap my head around movement, let alone raycasts

cosmic quail
#

if you make a ground layer, you'd need to do the hard work of manually assigning every ground object in your scene to the ground layer, dont you?

rich adder
steep rose
#

just select all of your gameobjects you want and select the ground layer

swift elbow
cosmic quail
steep rose
#

so no

cosmic quail
#

thats pretty tedious tho

steep rose
#

what

#

not really

sand snow
#

also I dont know why but in unity, in my console its saying that "the feild 'PlayerMovement.isGrounded' is assigned but its value is never used" but it is being used because i debuged if my player was touching the ground and it says im touching the ground, which would be impossible if isGrounded wasnt being used, unless I am wrong

cosmic quail
sand snow
#

is it because my bool is private, and not serialized?

steep rose
#

so no

rich adder
slender nymph
sand snow
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

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>();

        RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down);
    }
    void FixedUpdate()
    {
        rb.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, rb.velocity.y);
    }

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

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

        if(hit)
        {
            isGrounded = true;
            
        }
        else
        {
            isGrounded = false;
        }


    }
rich adder
#

oh my..

steep rose
#

and as Ash stated you could just put them all under a parent and literally assign the parent "ground" as well a children, and it will make all children the "ground" layer

slender nymph
steep rose
#

so no its not hard

rich adder
#

what is that local raycast inside the Start doing

cosmic quail
sand snow
#

if(hit)
{
isGrounded = true;
}

#

is that not using it??

slender nymph
#

that is assignment, not actually using it

#

you know, like the warning said. you are assigning it but never using it

sand snow
#

well how do i use it then?

polar acorn
sand snow
#

i thought it was using it?

rich adder
#

if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
🥄

polar acorn
slender nymph
polar acorn
#

Where does your code do anything different based on whether isGrounded is true or false

sand snow
#

ohhhh

verbal dome
sand snow
#

wait i think i solved it

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

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

    if(hit)
    {
        isGrounded = true;
        
    }
    else
    {
        isGrounded = false;
    }

steep rose
steep rose
polar acorn
slender nymph
#

nah, it does have an implicit cast

sand snow
polar acorn
slender nymph
#

why

steep rose
#

so you can do isGrounded = Physics2D.Raycast(transform.position, Vector2.down, rayDistance); in 2D?

steep rose
#

neato burrito

frosty hound
#

@sand snow Can you make a thread please so you don't occupy this channel.

sand snow
#

how do I make a thread I am sorry

#

LMAO

slender nymph
# polar acorn Many why is 2D so goddamn weird

i'm pretty sure they did that to sort of be on par with a 3d raycast which returns a bool. Why they didn't just make the method return a bool with an output parameter like Physics.Raycast is beyond me though 🤷‍♂️

#

i suspect they likely made the change well after they actually implemented these systems though so it was probably just to avoid breaking changes

vagrant fjord
#

why can i see through walls when i get really closer

rich adder
vagrant fjord
#

fix?

rich adder
#

make near clip smaller

#

or make sure ur collider big enough for cam

vagrant fjord
#

ill look into it thx

steep rose
#

it should fix it a bit

vagrant fjord
#

cool

#

also when my player walks into a wall it also sees through, fix?

steep rose
vagrant fjord
#

so just make all the colliders bigger?

steep rose
#

thats not what i said

#

change the clipping plane

#

on your camera

vagrant fjord
#

colliders worked for me but thanks 👍

steep rose
#

okay ig

formal sable
tender stag
#

hits = Physics.RaycastAll(ray, defaultInteractionDistance, defaultObstructionMask, QueryTriggerInteraction.Collide);

#

instead of defaultObstructionMask what was that thing for every layer

#

something like -~

#

i'll just use Physics.AllLayers

earnest iron
#

Hello

#

I'm having difficulties making an inventory system in Unity

#

Can someone tell me how to make one?

deft grail
#

show your code and the difficulty

earnest iron
#

Don't know how to make inventory

cosmic quail
earnest iron
#

My team made a pickup and drop system, but we have no idea how to make an inventory system

#

No

#

No

#

I didn't

tender stag
#

that was all layers

slender nymph
#

it's still better to use Physics.AllLayers as that is much more readable

tender stag
tender stag
#

i didnt know that existed

#

i thought i was only the -1

slender nymph
#

~0 would work too as that is also equivalent to -1

languid spire
earnest iron
#

Is there a cyber role?

marble hemlock
slender nymph
marble hemlock
#

i kind of want to just be able to slot in a script
any script

marble hemlock
#

but what if i want to use several different scripts

slender nymph
#

then it needs to either be a shared base class or interface

#

MonoBehaviour would be too broad because all of your components inherit from that, so you'd want to create either another class that all of the possible items inherit from, or some interface that they all implement

marble hemlock
#

i think i understand
thank you UnityChanThumbsUp

#

got it up and running UnityChanThumbsUp

tender stag
#

how do i compare object layer to a layermask

tender stag
#

so like that

#

what if my layermask has multiple layers

slender nymph
#

that is how you do it

tender stag
#

how does Physics.RaycastAll store the hits

#

apperantly its in order from the closest to furthest

#

so hits[0] would be the closest object right?

languid spire
tender stag
#

right

#

well shit then

slender nymph
#

Just sort the array yourself. or if you just need to find the closest, a simple for loop and a single variable with the index of the closest one found is all you need

tender stag
#

is that fine?

slender nymph
#

i mean, it really depends on what this is going to be used for. do you need it to actually be sorted? and do you need a new array every time you call this or could you use the nonallocating version

tender stag
#

i need it to be sorted

#

cause i need to get all the hit gameobjects before a specific one

#

and i can only do that by distance

polar acorn
slender nymph
#

wdym by "before a specific one" is this "specific one" known before the raycast? because if so, just cast between those objects and you don't need to sort at all

tender stag
#

and its own interaction distance

#

so first im doing a raycastall to get all the results

#

and the distance is 5

#

even tho the defaultInteractionDistance is 2

#

because some object might have an interaction distance of like 3.5
which would be bigger than the defaultInteractionDistance

rancid tinsel
#

is there an opposite of OnMouseOver()?

#

or a way to flip it?

tender stag
#

and find the closest interactable object from the player

#

and check all the hits before that interactable object

#

if their layer is inside the currentInteractable.customObstructionMask

#

and then do the distance calculations

#

but thats the easy part

verbal dome
rancid tinsel
tender stag
#

it is

rancid tinsel
#

no

#

its an opposite to onmouseenter

tender stag
#

u trying to detect when mouse is not over?

rancid tinsel
#

yes

slender nymph
#

so just flip a bool in onmouseenter/exit

verbal dome
#

So you want to call something every frame you are not hovering?

rancid tinsel
#

i should reconsider

#

ill prob just use a bool and then mouseenter and mouseexit

rancid tinsel
#

how do you make these public? i thought it was just public before void but that throws an error

slender nymph
#

what is the error

rancid tinsel
#

oh wait sorry not that

slender nymph
#

those methods are nested inside of another method

rancid tinsel
#

OH

#

i put them all in update...

#

thank you

delicate zinc
#

these scripts are meant to work together to let me pick up and drop items, but whenever i try picking up any item that isnt the latest one created with the script attached it doesnt let me drop it
its rly weird cos the debug.log that ive dropped it shows up in the console, but nothing else happens and it stays parented and kinematic
https://hastebin.com/share/uxuzutemer.csharp

sorrry for reposting it but i genuinely have no idea how to fix it ive tried everything

prime cobalt
#

Idk if this would be a code thing but I assume it would be. Is there a way for a render texture/camera to only show things inside of a collider? Like if there's a sphere collider it hides everything outside of that sphere. And if a part of the sphere is hidden its hidden from the camera/texture as well.

wintry quarry
delicate zinc
#

but what if i wanna interact with something that isnt an item

wintry quarry
#

But basically, all those Updates are running at the same time

wintry quarry
#

That just fires an event or something

#

It doesn't matter what the actual thing is

delicate zinc
#

TYYY

mighty compass
#
    private void MovePlayer(){
        Vector3 movement = Vector3.zero;

        // Calculate movement based on input keys.
        if (Input.GetKey(forwardKey)){
            movement += cameraObject.transform.forward * moveSpeed;
        }
        if (Input.GetKey(leftKey)){
            movement += -cameraObject.transform.right * moveSpeed;
        }
        if (Input.GetKey(backwardKey)){
            movement += -cameraObject.transform.forward * moveSpeed;
        }
        if (Input.GetKey(rightKey)){
            movement += cameraObject.transform.right * moveSpeed;
        }

        // Set the Rigidbody's velocity for snappy movement.
        rb.velocity = new Vector3(movement.x, rb.velocity.y, movement.z);
    }```
#

So I am making a player rb follow the player, problem is, movement is always towards where the camera is pointing, how do reset the z rotation on this reference to the camera object here, so it moves where the camera would be pointing at 0 z-rotation

#

the rb doesn't rotate with the camera, so I can't use it's transform as a reference

verbal dome
#

Not sure I understand, do you want to rotate the movement horizontally only?

mighty compass
#

this is just plain old wasd movement

verbal dome
#

Oh didnt see you posted code somehow

mighty compass
#

the issue is, it adds velocity relative to camera position, so if the camera is looking up, w loses all velocity

verbal dome
#

Before you use tha camera's forward, set its Y to zero

#

Then normalize it to make sure it is 1 length

mighty compass
#

kk, how would the y affect it in this situation? I would have thought the rotation on the z axis (when the camera looks up) would be the culprit

verbal dome
#

Z axis is normally the "twist" or "roll" axis, I doubt it is relevant here

#

Maybe you mean X axis rotation

#

Which is normally up/down

mighty compass
#

yes , sorry

#

x axis lol

#

how do i reset its y value without actually changing the gameobjects y value

#

can I hold a vector3 reference and then do it

verbal dome
#

Make a new vector3 from it

mighty compass
#

kk

verbal dome
#

Make sure to normalize it after removing the Y though

mighty compass
#

what is a value type haha

#

is it an instance?

verbal dome
#

Value types are always passed as a copy

mighty compass
#

ah c# things I guess lol

verbal dome
#

Pretty important stuff that you should learn

#

To avoid all sorts of headaches

mighty compass
#

weirdddddd, I haven't seen value types in java or any web languages

#

just a c# thing I guess

#

Or it's called something different in those languages

verbal dome
#

Broadly speaking:
-classes (MonoBehaviour, custom classes etc.) are reference types
-structs (Vector3, Quaternion, etc.) and primitive types (int, float) are value types

#

Seems to be similiar in java

mighty compass
#

what is a struct xD

polar acorn
mighty compass
#

kk, i have some c# learning to do

#

I never heard the term value type in my java classes

marble hemlock
#

before i start on a scale from 1-10 how difficult is it to code enemy movement, with them following the player?

#

just following the player, to start with

mighty compass
#

there's types, idk what value type is

verbal dome
mighty compass
#

there was instances of objects, references to them etc

verbal dome
#

And assuming that you have obstacles and need pathfinding

polar acorn
mighty compass
#

13

marble hemlock
polar acorn
mighty compass
#

okay so they're jsut called something else xD

#

primitive types are value types?

polar acorn
mighty compass
#

what! xD

polar acorn
#

Primitive types are value types, but they're not synonymous. Like how all squares are rectangles

mighty compass
#

wrinkling my brain

#

I remember writing BigInteger classes, making abstract types lol

#

so value types is just another name for primitive types

#

Looks like they are

#
    private void MovePlayer(){
        Vector3 movement = Vector3.zero;
        Vector3 camera = cameraObject.transform.position;
        camera.y = 0;

        // Calculate movement based on input keys.
        if (Input.GetKey(forwardKey)){
            movement += camera.forward * moveSpeed;
        }
        if (Input.GetKey(leftKey)){
            movement += -camera.right * moveSpeed;
        }
        if (Input.GetKey(backwardKey)){
            movement += -camera.forward * moveSpeed;
        }
        if (Input.GetKey(rightKey)){
            movement += camera.right * moveSpeed;
        }

        // Set the Rigidbody's velocity for snappy movement.
        r```
#

How do i qualify camera with a type name?

polar acorn
#

What do you mean? The type is Vector3

mighty compass
#

error CS0176: Member 'Vector3.right' cannot be accessed with an instance reference; qualify it with a type name instead

polar acorn
#

Because Vector3.right is static

#

It's a constant with a value of 1, 0, 0

mighty compass
#

ah

#

thankyou

livid nova
#

I'm trying to expand on the A*pathfinding system, and I'm currently trying to get the AI to do 2 things. Only follow the player when within the grid, and I want the AI to return to it's start position when the player exits range. Any help or suggestions would be appreciated.

verbal dome
#

Is it your custom A*?

#

These problems don't seem really related to the pathfinding itself though

#

Just a couple of if-statements

#

Or events

mighty compass
#
    private void MovePlayer(){
        Vector3 movement = Vector3.zero;
        Vector3 camForward = cameraObject.transform.forward;
        Vector3 camRight = cameraObject.transform.right;
        camForward.y = 0;
        camRight.y = 0;

        // Calculate movement based on input keys.
        if (Input.GetKey(forwardKey)){
            movement += camForward.normalized * moveSpeed;
        }
        if (Input.GetKey(leftKey)){
            movement += -camRight.normalized * moveSpeed;
        }
        if (Input.GetKey(backwardKey)){
            movement += -camForward.normalized * moveSpeed;
        }
        if (Input.GetKey(rightKey)){
            movement += camRight.normalized * moveSpeed;
        }

        // Set the Rigidbody's velocity for snappy movement.
        rb.velocity = new Vector3(movement.x, rb.velocity.y, movement.z);
    }``` Okay it works great until the camera points at exactly 90 degrees, then all movement stops
#

should I just give each vector a minimum value it can be when pressing a certain key

stiff fjord
#

what was the command to check i had visual studio code and unity setupo proper;ly?

rich adder
stiff fjord
#

that shows the guide

rich adder
eternal falconBOT
#
Visual Studio Code guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

https://on.unity.com/vscode

rich adder
#

just click the link

#

dont need to call the command

stiff fjord
#

ty

tender stag
#
if((currentInteractable.customObstructionMask & (1 << currentHitTransforms[i].gameObject.layer)) != 0)
{

}
// This objects layer is not in the accepted layers of the interactable
else
{
    isBlocked = true;
    break;
}```
#

how do i reverse the first statement

#

cause i dont need it to be true

#

do i just wrap it in extra brackets and slap a !?

#

would that work

polar acorn
#

What logical combination of X with Y would result in

X | Y | Result
T   T   F
T   F   T
F   T   T
F   F   T
tender stag
#

i dont understand what ur asking me

polar acorn
#

I'm trying to explain how you'd use boolean logic to reason this out yourself, instead of just being told the answer

tender stag
#

well yeah but what i wrote works

polar acorn
#

The first truth table is what you've current got. The second is what you (presumably) want

tender stag
rancid tinsel
#

how would i go about getting the x and z position of the mouse in the 3D world?

polar acorn
#

Sure, NAND (Not-and) is one valid solution

#

You could also do !X OR !Y

tender stag
#

thats what i did

#

oh use the or

#

im comparing two different things tho

#

so i cant

#

wait i can

#

but thats gonna be a long ass line

#

and the code is going to have to compare both

polar acorn
#

If you're checking two different things, then you're not asking for the inverse of a condition, you're asking for two conditions

tender stag
#

this is in a loop already

polar acorn
#

the value of Z has no bearing on the result of X AND Y

ruby python
#

I have a reeeeeally stupid question that I can't seem to get my head around.

I have an array of floats and I need to increment the value of a float based on it's index.

    public void UpdateOreCount(int indexID, float oreAmount)
    {

        ores[indexID] = ores[indexID] + oreAmount;
        oreAmountText[indexID].text = oreAmount.ToString();
    }

This is my function, first time it runs, it adds the oreAmount value and updates, but subsequent values don't get added.

What am I doing wrong? (And yes, I completely believe that I'm being a complete spanner. lol.)

polar acorn
#

So, you're setting the text at that ID to the amount you added, not the new total

ruby python
rancid tinsel
#

any idea what im doing wrong from lines 55 to 70? i want to convert mouse position into its real world position but instead of going where i click, the units go elsewhere https://gdl.space/epulezusoc.cs

mighty compass
#

Can someone help me with this

#
    private void MovePlayer(){
        Vector3 movement = Vector3.zero;
        Vector3 camForward = cameraObject.transform.forward;
        Vector3 camRight = cameraObject.transform.right;
        camForward.y = 0;
        camRight.y = 0;

        // Calculate movement based on input keys.
        if (Input.GetKey(forwardKey)){
            movement += camForward.normalized * moveSpeed;
        }
        if (Input.GetKey(leftKey)){
            movement += -camRight.normalized * moveSpeed;
        }
        if (Input.GetKey(backwardKey)){
            movement += -camForward.normalized * moveSpeed;
        }
        if (Input.GetKey(rightKey)){
            movement += camRight.normalized * moveSpeed;
        }

        // Set the Rigidbody's velocity for snappy movement.
        rb.velocity = new Vector3(movement.x, rb.velocity.y, movement.z);
    }``` Still trying out how to make the movement based off the camera as if it's x-rotation was 0
#

because when the player looks directly 90 degrees at the ground or sky, there's no movement, because forwards is straight down or up

thorny fern
#

is there a way to override GameObject ToString() method? I want it to show something else other than name. as an extension method or something?

rocky canyon
#

.name is a string

ruby python
rancid tinsel
#

i think ive spotted the issue though

#

the y and z values seem to be flipped

#

swapped* i mean

rocky canyon
#

gameObject.ToYourCustomString();

steep rose
#

AKA make it a child of your player

#

not camera

mighty compass
#

That's what I was thinking, but I just didn't want to add a ton of random objects in the scene following the camedra

#

camera

#

But I guess I could convert that object to the player model eventually

steep rose
thorny fern
# rocky canyon i dont see why u couldn't use an extension method

sry. i shouldn't have mentioned extension methods -> I led you in the wrong direction. I'm using a generic class which i'm instantiating with GameObject type at runtime. for debug purposes i need to Debug.Log stuff. but in code I don't know yet that the class will use GameObject as type. hence i wanted to override GameObject.ToString()

mighty compass
#

Yeah I understand, thankyou. I wil ldo that then

rocky canyon
#

ya, not sure im savvy enough to know bout that

#

imo using abstract classes and overrides and stuff are code-general ++ but i could be just a newb 🤣

thorny fern
#

yeah. stack overflow sugested that i subclass GameObject, use that and override my ToString

rocky canyon
#

aye, that sounds solid

thorny fern
rocky canyon
#

well ur the odd crowd. lol

verbal dome
verbal dome
#

Like YourClass<GameObject>

thorny fern
#

yep

rocky canyon
#

osmal entering the ring 💪

mighty compass
buoyant cove
#

@rocky canyon Hey! I have a business inquiry. What’s your email?

verbal dome
#

Can you show a code example of what you roughly would like to do?

verbal dome
#

Unless you already found the answer

buoyant cove
#

Thank you!

verbal dome
mighty compass
#

I kinda wanna make a bunker building game where you have to try and reinforce a base as like a welder dude, and zombies try to destroy it

#

what yall think lol

steep rose
#

sounds neat if implemented well

mighty compass
#

and then move it towards a rust sortof game once I have ai mechanics down

steep rose
mighty compass
#

kk

thorny fern
# verbal dome Unless you already found the answer

pretty much i found the answer. but the code looks like this now:

class Algos<T>{
  genericFunctionAlgorithm(...){
    List<T> myArray;
    //do stuff
    Debug.Log(myArray.ToString());
  }
}
____________________
some script with class:MonoBehaviour
...
void Start(){
  Algos<GameObject>.genericFunctionAlgorithm();
}

the answer I think i found tells me this:

class MyGameObject : GameObject{
  GameObject myObject;
  public override string ToString(){
    return myObject.transform.position.x.ToString();
  }
}
____________________
some script with class:MonoBehaviour
...
void Update(){
  Algos<MyGameObject>.genericFunctionAlgorithm();
}
verbal dome
#

Please link me to the answer because you cant inherit from GameObject, that class is sealed

thorny fern
#

well i didnt try that yet. the stackOverflow answer didnt mention sealed classes as it wasnt about Unity GameObject specific question. guess i'm stuck. or find another way to debug

verbal dome
thorny fern
#

yes

#

this is what i get for working with generics. i had to pretend i'm smarter, didnt i

verbal dome
#

In C#, every object has a ToString method so the generic type T is guaranteed to have that too
You can do this: cs foreach(T item in myArray) { Debug.Log(item.ToString()); }

#

Debug.Log(item) should work too

thorny fern
#

in my case it will print the GameObject's name. but i wanted something else out of the GameObject.

verbal dome
#

Okay, I think you'd need abstract/virtual and override methods then

#

Bit above beginner level but...cs // Base class protected abstract string GetInfo(T item); // Derived class protected override string GetInfo(GameObject item) { return // ... whatever info you want from the gameobject }

verbal dome
thorny fern
#

yeah. makes sense. thx a lot

verbal dome
#

The abstract method could also be a default virtual implementation instead:cs protected virtual string GetInfo(T item) => item.ToString();

#

Np

marble hemlock
#

please tell me nav meshes arent as complicated as to actually need 54 videos explaining how they function

#

im seeing different videos of varying times
one at 8 minutes, one at 10, one at 40

verbal dome
#

That guy has decent videos, but 54 videos sounds like way, way too much

marble hemlock
#

54 videos is just too much 😭
at that point just write a book and i'd rather read that

verbal dome
marble hemlock
#

thank you 🙏
i thought looking nav meshes unity on youtube would just show me the unity account but

nope

#

oh wait this is actually really cool

deft lynx
#

so idk if my issue is with the navmesh but the slime enemy in my game isn't moving but still tracks the player an plays the animation accordingly. Been trying to fix this since yesterday but to no avail, can someone please let me know the problem. I'll past the enemy inspector and the code below so you guys can check it out

mighty compass
#

has anyone done any voxel like projects in unity?

rich adder
#

probably

verbal dome
earnest wind
#

Did i do some mistake?

#

i == itemIndex2 will be true

#

oh my bad my bad it should have been MainItems[i]

#

i really dont know how this worked all this time

polar acorn
#

It works fine when you're activating the object. Not so much when you're trying to disable it

queen adder
#

Is it possible to instantiate something from one scene to another?

rich adder
#

so you can technically do it if you do some additive stuff

queen adder
rich adder
queen adder
rich adder
#

having a singleton ofc is much easier than messing with additive and changing active scene to spawn something

#

you need a way to get the reference though hence easy singletons (cross-scene references)

teal viper
queen adder
#

Im not extreamly experienced I dont know if you remember helping me in the past but you have so learning new ways to do things helps tremendously. I dont know much ways to do things. I think the way I get references is a little jank not sure but it works. Singleton is 100% the right way to do it makes sense now

rich adder
rich adder
#

usually when I have to jank or do something kind of against the normal workflow, something in the design might be wrong

queen adder
queen adder
rich adder
#

well yeah you don't want to overuse singletons, keep it for only specific manager

teal viper
queen adder
rich adder
#

you dont want every script to talk to every separate message IMO thats bad pattern

#

you should only communicate to 1 manager that talks to its own managers it manages

queen adder
#

this is how Im refrencing things normally

 private WaveManager wavemanager;
 void Start()
 {
     WaveManagerGO = GameObject.FindGameObjectWithTag("WaveManager");
     wavemanager = WaveManagerGO.GetComponent<WaveManager>();
 }```
teal viper
queen adder
queen adder
rich adder
queen adder
wheat wadi
#

Sorry, how to add more functionality to the Wiggler script so that the user can specify movement in all directions (not just the Y axis)

true oriole
#

i download everything and still having an issue

wheat wadi
mighty compass
#

How can I get rid of this giant annoying blue block, and also make it, so my UI is always rendered, so it doesnt dissapear behind blocks

#

nvm i figured out the clipping part

mighty compass
#

Now how do I make the GUI not this large so I can edit it lol

#

ability to change it's transforms are locked in overlay mode

rich adder
#

also canvas adapts to the screen resolution / size

mighty compass
#

thats crazsy

#

Thankyou good sir, holy moly, I did not know about focusing elements xD

rich adder
mighty compass
#

That is so helpful

#

thanks

queen adder
#

could someone help look at my unity build profiler with me to figure out why its so laggy despite it running seamlessly within the editor?

thorny basalt
teal viper
thorny basalt
#

🤦

ashen frigate
#

any good 3d hitbox tutorial u recommend ?

umbral bough
#

Hi, I am writing this simple movement script and keep running into a weird issue.
When I am on the ground, it's all good, however, if I am in the air(be it by jumping or simply dragging my player up), I am unable to move.
Direction is fine, acceleration being added to the _rb.linearVelocity in the Move() function is fine(logged both) and I am suspecting the ApplyGravity() function but I am honestly not even sure at this point.
Could somebody help me with this one because I am out of ideas.
https://gdl.space/yiyixanise.cs

umbral bough
ashen frigate
#

im trying to do like a fighting game

umbral bough
#

look into colliders, box casts, overlap box etc.

#

each one serves a slightly different purpose

ashen frigate
#

what would be best for fighter game like smash

umbral bough
#

it depends.
if you need physics interactions etc. then collider components+rigidbody is the way to go.
if you are looking for a way to detect when say a bullet hit a player, then using BoxCast or OverlapBox on the bullet and collider on the player would be a decent choice.
read what they do on unity docs, they have great examples and explanations and pick what works for you.
https://docs.unity3d.com/ScriptReference/Collider.html
https://docs.unity3d.com/ScriptReference/Rigidbody.html
https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
https://docs.unity3d.com/ScriptReference/Physics.BoxCast.html
https://docs.unity3d.com/ScriptReference/Physics.OverlapBox.html

#

you would usually combine these to achieve best results

ashen frigate
#

isee ty

teal viper
umbral bough
#

I think it does, odd, I was positive I didn't take y axis into account when it comes to friction, thanks for pointing it out!

paper mountain
#

guys im new to unity where is the assets folder its normally next to the console but i cant find it

umbral bough
#

you might've closed the project tab

paper mountain
#

nope

#

i think i did

#

where is it

umbral bough
mighty compass
#

I just made a toggle buildmode, and primitive objects get created, im stoked

umbral bough
paper mountain
#

THANKKKKSSS

mighty compass
#

How would you guys think I should go about making a grid system for building in a game

teal viper
umbral bough
vale robin
#

I just discovered IEnumerators as coroutines, and I wanted to try making a camera shake effect, but I can't make it work.
I am new to this, some help pls?

umbral bough
vale robin
umbral bough
vale robin
#

None

umbral bough
#

mind debug logging in the on collision enter?

teal viper
umbral bough
vale robin
#

Like this?

umbral bough
vale robin
#

Yay, it works now. I missed that part of the documentation

#

Thanks

umbral bough
#

nice

autumn beacon
#

i made a script that generates a quad, and now want to make its surface a png, and am going crazy trying to figure out how to make google tell me the answer lol
any advice/links?

autumn beacon
#

did some more searching, found this solution online(?)

ivory bobcat
#

What component are you using to generate the quad? Show your implementation of the quad.

autumn beacon
#
  • i created a default material titled "WallTile"
#

this seems to work good enough for now™️, i'll probably just roll with it

thorny basalt
#

Atm it is making that check every loop iteration

eternal needle
thorny basalt
#

Oh wait. I’m a dumbass 🫠

eternal needle
# autumn beacon

one quick thing i notice is that the Resources.Load is done everytime you want to create a wall. That can be done once in awake/start and be cached then reused here

#

Resources.Load isnt so cheap

ruby python
#

Mornin all.

https://hastebin.com/share/sipefajosu.csharp

I have this script that is spawning objects into the world, checking position, if conditions are met places object on the terrain surface, if not, repositions and checks again.

I know it's pretty inefficient, but I can't really think of another way of doing it. The problem I'm having with this approach though is that I'm causing a stackoverflow because the amount of recursion involved.

Would anyone know of a way to prevent the stackoverflow, or a different method of placing the objects where I need them? 😕

glacial sable
#

What happens if you reach the max xyz coordinates of the scene?

ruby python
rocky canyon
#

the farther you get from the origin the more the game spazzes out

ruby python
#

Single Chunk with visual representation.

ruby python
ruby python
#

Sorry, I think wires got crossed. (I've literally just woken up. lol.)

#

But yeah, anything above 10,000 units from center, floats get screwy

steel stirrup
ruby python
steel stirrup
#

If you're aiming for placing on the surface, why not just sample a bunch of random points from an arbitrary height, and then distribute your rocks among those points

ruby python
#

terrain.SampleHeight sorry.

steel stirrup
#

sounds good

ruby python
#

I've fixed the memory leak I was causing. I was recursing back and forth between two methods which was crapping it all out, so just reworking everything into a single method.

upper thistle
#

Can you pass through a parameter with a coroutine?

languid spire
upper thistle
#

I'm sure it's an obvious solution, just couldn't get it from the wiki/discussion posts

languid spire
#

coroutines are started not called.
see StartCoroutine

upper thistle
#

oh whoops

#

thanks

languid spire
#

also your signature is incorrect, the parameter needs a type

ruby python
#

You also need to define what type HitRenderer is.

#

Bad sign right? lol.

indigo knot
#

Yes

atomic holly
#

Hello
If it's possible to put the sprite a child in front of the parent sprite ?

languid spire
#

not always, depends on what you changed

ruby python
#

Just some order of execution in a for loop

upper thistle
#

did not take into account type errors

languid spire
upper thistle
#

yea, a lot of posts bounce between different ways of doing stuff and I'm still new to types

#

reading about it though

languid spire
#

take my advice, never use var, always use the type correctly

upper thistle
#

makes sense

#

Is it cause the program has to guess?

languid spire
#

no, it's because you have to

upper thistle
#

oh like literally no choice

#

gotcha

languid spire
ruby python
ruby python
languid spire
upper thistle
#

I've managed to make some cool stuff without any videos though, so I'm pretty happy

#

on a private learning project just to experience Raycasting and different ways of using it rn

ruby python
languid spire
upper thistle
#

Is there a good practice for storing lastTarget hit to reset the color when it's no longer being hit?

#

rn I'm just gonna store the variable on hit for lastTarget

ruby python
# languid spire did you get a stack overflow?

Initially I did when I was recursing between a couple of functions, but I've condensed it down to one and seemingly fixed that, but just made some order of operation changes and it crapped out, so I'm assuming it returned. lol.

#

So just taking a few minutes away from looking at it, so I can look at it with 'fresher' eyes. 🙂

languid spire
ruby python
# languid spire sounds like it, with infinite loop the program will hang but not crash, with inf...

Yeah, basically what I'm doing is Instantiating my object at a random position, checking the terrain height underneath it, if it's between a certain height range move the object to the surface, move on to the next. If the height isn't between the given range, move the object to another position and try again.

I know that it's horribly inefficient really (happens on start, so only runs once), but I don't know of another way to do it 😕

languid spire
sand snow
#

I am currently trying to make a movement script and now that i have my walking speed I want my speed to increase when i hold shift (like a sprint), how should I do this?

#

do I use a bool to see if I am holding shift and then an if statement?

ruby python
languid spire
sand snow
#

so something like

if(Input.GetKeyDown(KeyCode.LeftShift))
{
currSpeed * orgSpeed
}else
{
orgSpeed
}
???

languid spire
languid spire
sand snow
#

yes

languid spire
#

well it's not

sand snow
#

how?

ruby python
languid spire
sand snow
#

yeah so if iclick shift my current speed will multiply by my orgspeed, and if i am not clicking shift then it will just be my orgspeed

#

whats wrong about it?

languid spire
#
currSpeed *= orgSpeed;
...
currSpeed = orgSpeed;

is what it should be

mighty compass
#

mb

sand snow
#

ohhh nevermind i get it

#

currspeed is the multipliar correct?

#

I also have a question what does *= mean

modest dust
#

If you do not know what *= is then I suggest taking a quick C# course

sand snow
#

also im not sure why but its not detecting when i hold shift, but the code does work because if i spam shift sometimes the value will change

sand snow
#

wait

#

that is what it means

#

my bad 😭

modest dust
#

Still, it's never a bad idea to take a course

sand snow
#

its in void update if thats what you're trying to see

modest dust
#

Still, show full code

sand snow
#
using UnityEngine;

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

   [SerializeField] private bool isGrounded;

    private bool facingRight;
    [SerializeField] private float rayDistance;
    [SerializeField] private LayerMask groundMask;

    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.LeftShift))
        {
            sprintSpeed *= speed;
        }
        else
        {
            sprintSpeed = speed;
        }


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

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



       
        }

        


    }
modest dust
#

You reset sprintSpeed back to speed on the next frame

sand snow
#

it works it just doesnt detect when im holding shift for some reason