#💻┃code-beginner

1 messages · Page 489 of 1

rich adder
#

try moving scatter.Enable() on Start

wraith phoenix
#

This one is really hitting home for me

autumn pine
#

ooh I think its the first one

#

that would explain why everything still functions as it should

shell sorrel
#

yeah i will pretty heavily use lambdas for callbacks, but for events that you must unsub from just always use a named function directly

wraith phoenix
#

One more error now:

        if(playerControls.Movement.Dash.triggered){PlayerDash();}
    }```
"There is no argument given that corresponds to the required parameter 'ctx' of 'Dash.PlayerDash(InputAction.CallbackContext)'"

Do I need to pass something through PlayerDash() now? I tried `PlayerDash(ctx)` but that didn't work.
shell sorrel
#

in your PlayerDash do you ever use the context

#

or you just added it because its required for the event?

#

if its not required or used in your function just pass null in

#

or could even defualt it to null in the signature

wraith phoenix
#

I don't believe I ever use the context.
I'm still not 100% clear what information would be in the context.
Would it be something like how hard the button was pressed? (aka a short or long pull on a controller trigger)

shell sorrel
#

so what does the signature of PlayerDash look like?

autumn pine
wraith phoenix
# shell sorrel so what does the signature of PlayerDash look like?
    //private void PlayerDash() {
        Debug.Log(Stamina.Instance.CurrentStamina);

        if(!isDashing && Stamina.Instance.CurrentStamina > 0) {
            Stamina.Instance.UseStamina();
            isDashing = true;
            playerController.moveSpeed *= dashSpeed;
            //myTrailRenderer.emitting = true;
            StartCoroutine(EndDashRoutine());
        }
    }

    private IEnumerator EndDashRoutine() {
        yield return new WaitForSeconds(dashDuration);
        playerController.moveSpeed = coreMoveSpeed;
        //myTrailRenderer.emitting = false;
        yield return new WaitForSeconds(dashCDTimer);
        isDashing = false; 
    }```
rich adder
wraith phoenix
#

Working on getting my stamina working now

shell sorrel
#

make it that

wraith phoenix
#

But that basically works

rich adder
shell sorrel
#

that will let you have the ctx arg the event requires, but also call it without providing a context or having to manually pass null

autumn pine
shell sorrel
#

other option is just have 1 method that is only for the event, that just calls your regular playerdash

rich adder
autumn pine
#

if the script is off

wraith phoenix
rich adder
#

must be after scatter gets unassigned

autumn pine
#

unfinished debug.log ignore that

rich adder
#

value types are not null types

shell sorrel
#

ah my bad can just use default then

#

or make a dedicated method just for the event

wraith phoenix
shell sorrel
#

yeah default just creates the "zero" value for a given type

wraith phoenix
#

= default did work in the coder. Testing it in the game

shell sorrel
#

if its a reference type that is null, if its a struct thats it just with its stuff zeroed out

wraith phoenix
#

Testing in game did not work.
Now my PlayerDash() doesn't fire when I press the associated input to trigger it.

#
        if(playerControls.Movement.Dash.triggered){PlayerDash();}
    }```
#

Do I need to pass through something in PlayerDash() now

rich adder
polar acorn
#

Yes, you need to pass a CallbackContext

wraith phoenix
rich adder
wraith phoenix
wraith phoenix
polar acorn
#

Like you were doing up here, except using the function instead of a lambda

wraith phoenix
#

So OnEnable is an example of an event?

polar acorn
#

In what context

wraith phoenix
# polar acorn In what context

Only example I have is that I find it in all scripts that are linked to an input action map.
Maybe the event is the button being pressed?

polar acorn
#

playerControls.Movement.Dash.started is an event

#

and you can add a callback to it

#

So that whenever playerControls.Movement.Dash.started is invoked (in this case, by the input system), it will call every callback subscribed to it

wraith phoenix
polar acorn
#

Depends on the event

#

You need to subscribe with a function that has the same return types and parameters the event expects

wraith phoenix
polar acorn
#

A scenario such as what

wraith phoenix
#

Of using an event

polar acorn
#

You literally already are

wraith phoenix
#

Yea, but I don't understand why

polar acorn
wraith phoenix
#

lol

polar acorn
wraith phoenix
#

Ahhhh

autumn pine
#

solved btw

wraith phoenix
#

So there could be multiple functions triggered at one time from one button being pressed.
And one wouldn't have to snake each function from one another but rather it would act as a spider web from a central point.

#

I don't know what I would use that for just yet but it sounds quite useful.
Probably could optimize a bit of my code once I get better at using this.
But obviously it's the first I'm learning about it

#

So for my current scenario,
I don't really think I need an event... Only one function needs to be called when I press the associated button.

sly canopy
#

hello

#

How do I script

polar acorn
#

Create -> C# Script

wraith phoenix
#

Back to the heart of the problem, why doesn't this:
private void Update() {if(playerControls.Movement.Dash.triggered){PlayerDash(default);}}
trigger this:
private void PlayerDash(InputAction.CallbackContext ctx = default) {}

polar acorn
#

That function has nothing in it

#

what are you expecting to happen?

rich adder
wraith phoenix
#

At the very least I'm expecting my concel to say "dash fired"

        Debug.Log("dash fired");

        if(!isDashing ) {
            isDashing = true;
            playerController.moveSpeed *= dashSpeed;
            StartCoroutine(EndDashRoutine());
        }```
cosmic dagger
polar acorn
cosmic dagger
#

oh, there's the actual method. something with the button is not registering . . .

wraith phoenix
ivory bobcat
wraith phoenix
#

It used to trigger

sly canopy
ivory bobcat
#

Better not to guess and just test

wraith phoenix
#

If I take out all the Callback Context stuff, the button triggers

#

I just get an error about Callback in my concel

rich adder
ivory bobcat
#

An error would cause undefined behavior

sly canopy
#

what

#

why is um

#

why is um blocked message

polar acorn
polar acorn
rich adder
wraith phoenix
#

Oh, the button is no longer working anymore

        if(playerControls.Movement.Dash.triggered){Debug.Log("button pressed"); PlayerDash(default);}
    }```
Through in the Debug log before the PlayerDash(). Concel never reported anything
sly canopy
#

yeah well um

rich adder
polar acorn
polar acorn
wraith phoenix
#

I think the Start() is now no longer working.

        playerControls = new PlayerControls();
    }

    void Start()
    {
        playerController = GetComponent<PlayerController>();
        playerControls.Movement.Dash.started += PlayerDash;
    }

    private void Update() {
        if(playerControls.Movement.Dash.triggered){Debug.Log("button pressed"); PlayerDash(default);}
    }```

Is this when I would create an instance of PlayerDash() the way I used to?
```playerControls.Movement.Dash.started += _ => PlayerDash();```
polar acorn
#

it takes a parameter now

#

you cannot call it without one

#

playerControls.Movement.Dash.started is an event that takes functions which have a CallbackContext as a parameter and return void.

#

You add the function to the event

#

so that when it is invoked, the functions subscribed to it are executed

wraith phoenix
# polar acorn You add the function to the event

Ok. The event is the button press. But the event is never being registered when it happens (aka the button is pressed). Why has the event stopped registering when I press the button.
PlayerControls is instantiated during Awake().
The path to the button is correct and the input controller is configured correctly.

Is the playerControls.Movement.Dash.started += PlayerDash; event needed at all anymore?

polar acorn
wraith phoenix
#

The input system is correct. I've had it all work before

#

Only trying to fix the callback concel message broke it

#

Fixed it

frank flare
#

events can only contain functions with one argument?

#

unityevent

wraith phoenix
#

Removing the code in Start(). Changing OnEnable() to playerControls.Enable(); and leaving private void PlayerDash(InputAction.CallbackContext ctx = default) {...}

frank flare
wraith phoenix
#

Mission successful!
Thank you to @polar acorn @rich adder @ivory bobcat @cosmic dagger @shell sorrel and all the chatgroup for bearing with me (:

ivory bobcat
cosmic dagger
frank flare
wraith phoenix
rich adder
queen adder
#

Hey, Im trying to make my bullet destroy when It hits the target but I cant figure out how. When it hits It it doesn't delete and I just get this error.

polar acorn
#

That would be akin to deleting a file

queen adder
#

Yeah I understand that. I cant figure out how to destroy the active game object

polar acorn
#

Destroy(this.gameObject)

#

on the object you want to destroy

queen adder
#

What do I need to put in the variable

polar acorn
#

Are you still calling destroy on a prefab elsewhere

ivory bobcat
queen adder
#

What do I put in active bullet

ivory bobcat
#

Call cs Destroy(collision.gameObject)

queen adder
#

On hit bullet script?

polar acorn
queen adder
#

oh it worked

#

I tried this before and it didnt

queen adder
ivory bobcat
#

A concern would be that anything other than the bullet hitting the target would also be destroyed. When/if your game gets more complicated, consider having an if statement prior to differentiate or set the collision matrix to only allow interaction between the specific types.

frank flare
#

addtorpue or addrelativetorpue?

low wasp
#

Hey yo! I am having some issues with getting my second player to respawn after scoring. I have it working for player one. I copied all the code from player one but chnaged bits to reference player two. It is just not working. In fact, I cannot get it to save without an error when I add the player two stuff. In the paste below, I have commented out the part the gives the error. I don't understand how it is not working as I copied it from the player one stuff. Would anyone be able to tell me the error of my ways?

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

wintry quarry
#

They should reuse the same code generally

#

Also if you're getting some kind of error it would help greatly if you shared the error

wintry quarry
# low wasp

Pretty straightforward - you're trying to use a variable you never declared

#

in C# you have to declare all variables before using them.

low wasp
wintry quarry
#

Notice that on line 12 you declared one variable:

public PlayerController respawn;```
#

You never declared a variable called respawn2

low wasp
#

I see it now

#

I am an 10DIT.

low wasp
upper forge
#

How would I check to see what the current scene name is?

rich adder
polar acorn
low wasp
#

I don't know. In my limited experience, I thought each needed its own controller. I see what you are saying now though. Even though it is the same script. It will only control the one it is attached to.

#

That would have made things a bit easier.

polar acorn
#

You can make public or serialized variables that change which input device it reads from or what objects it interacts with by changing them in the inspector

low wasp
#

I will have to try that.

wintry quarry
#

We don't write new code for every object in a scene. Objects that are similar use the same code.

#

otherwise it's a nightmare to maintain everything

rich adder
#

Enemybehavior4502

wintry quarry
rich adder
#

did you not click the second static method that is on the docs

polar acorn
coral ivy
#

I am following a tutorial on creating a 3D terrain with grass and trees. In the tutorial he said if I want to interact with trees later on like cutting them, I will need to place them directly on the terrain. But doing that will take a while if I want to create thousands of trees. Is it possible to place large amount of trees and be able to create a script to interact with them all?

steep rose
#

you do not have to manually place them

coral ivy
#

what is a stump?

rich adder
#

create a script that samples the terrain height and mass place them

steep rose
#

a stump?

#

a tree stump?

coral ivy
#

oh ok

#

just learned that word alone.

#

but if I don't need to manually place them, how do I do it?

low wasp
coral ivy
#

I need to create a script to place trees automatically?

#

sounds complicated

upper forge
steep rose
#

well you can put them manually 🤷‍♂️

rich adder
coral ivy
#

like using a brush or something

#

I can use a brush to mass plant trees everywhere but can't interact with them

rich adder
#

you can probably just call it directly if you only do it once or so

#

make a field sure, if you need it more than once / other method same script

upper forge
stable narwhal
#

Anyone know a way to make the bullets come from the ship and not from thin air?

rich adder
#

it has code how to store it inside a variable, except make it a field so its stored in the entire class not just within the method

#

or just store it as string the name itself

#

up to you

upper forge
#

omg i feel stupid
So in this example when i go to check the scene name i would just do

if (scene == ("Level_1")
{
DO this
}

unkempt zenith
stable narwhal
# polar acorn How are you spawning them?

im using a gameobject called "gun" to spawn the bullet prefab whenever I press the button but it just spawns from thin air and doesnt follow the ship whenever I move around

unkempt zenith
rich adder
stable narwhal
stable narwhal
stable narwhal
#

gimme a sec

unkempt zenith
#

Consider rb as the rigid body of the bullet

#

And x the speed of it

polar acorn
#

I don't think they're asking anything about moving it

unkempt zenith
#

That's what I thought

#

🙃

leaden crow
#

Does anyone know why this script is preventing me from rotating the camera with other scripts (Like a recoil system for example)

rich adder
polar acorn
leaden crow
#

ah

#

that tracks

rich adder
#

you would need another parent object to apply the recoil too

polar acorn
#

!code

eternal falconBOT
stable narwhal
#

my bad

rich adder
#

use Links for large code

stable narwhal
polar acorn
#

Nothing in here appears to be spawning anything

#

Also, I really hope you're not actually coding like this with no indentation

unkempt zenith
upper forge
#

So i did this no errors but it didnt go the the cutscene

stable narwhal
polar acorn
rich adder
upper forge
#

No this code is on the gameManager so its always there

wintry quarry
rich adder
#

you need activeSceneName = SceneManager.GetActiveScene().name

leaden crow
polar acorn
rich adder
#

you're doing ToString on the struct idk if that gives the name of scene

leaden crow
#

All camera movement tutorials just tell you to use the camera GO so thats what I was doing

#

created a parent and now everything is working proper

polar acorn
upper forge
polar acorn
stable narwhal
polar acorn
#

show the transform gizmo, just like you did before

#

but after you move the ship

stable narwhal
wintry quarry
steep rose
#

if its not and you are not moving it, it will stay still

polar acorn
stable narwhal
stable narwhal
polar acorn
viral mural
#

Can anyone help me make a game?

polar acorn
rich adder
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

stable narwhal
steep rose
#

can you show us your script that moves the ship?

polar acorn
# stable narwhal ship

Show a full screenshot of your entire unity window with Ship selected, the inspector visible, and the transform gizmo in scene view, while the game is running. Then, move the ship, and send another

polar acorn
# stable narwhal

Okay, good. That's step 1, now run the game, move the ship somewhere else, and take another picture just like this one

polar acorn
stable narwhal
#
  1. Sprite 2. Gun 3. FirePoint
polar acorn
#

So yes, you are moving the Sprite and not the Ship.

#

Every time the ship moves, the sprite moves double that

#

Also you have two gun scripts, that's probably not intentional

stable narwhal
#

ah

#

ok let me go ahead and delete that

#

Yeah now it's working perfectly

#

thanks

faint osprey
#
        {
            var emitParams = new ParticleSystem.EmitParams();
            for (int i = 0; i < CDPS; i++)
            {
                dustCount += 1;
                massCount.text = ((double)dustCount / SolarMassConversion).ToString() + " Solar Masses";
                float time = 1 / CDPS;
                yield return new WaitForSeconds(time);
            }
            yield return null;
        }```
this is my script for handling my Dust per second and it works great when the DPS stays a whole integer however if it becomes a float it obviously wont work because of how the for loop is set up so how would I change it to work with floats as too
cosmic dagger
#

clearly you need an int for the for loop, so why not round?

faint osprey
cosmic dagger
eternal needle
eternal needle
wintry quarry
leaden crow
#

Alright after putting it off for months I finally have functioning recoil and ads

tender cloak
#

Anyone able to help me with rotating the camera around an object on both the worlds and local axis using arrow keys

steep rose
#

which camera? scene view or game view?

#

give details

tender cloak
#

I'm pretty sure it's game view my bad I'm off my laptop now but I have an object and I used the rotateAround method for left, right, up and down

#

But it gets a bit wonky

steep rose
#

how so?

tender cloak
#

So I need to rotate up and down on the local axis and the other two on the worlds axis

tender cloak
#

"Does it work when you rotate around the x axis a bit (up/down arrows) and then around the y axis a bit (left/right arrows)? What I'd expect is the latter will feel wrong as it's the world's y axis and not the camera's y axis you're rotating around - and they're no longer the same as each other."

#

My bad if this isn't making much sense

steep rose
#

it isnt

#

and it doesnt

tender cloak
#

I will text again in the morning when I'm on my laptop

#

Again

#

Thank you anyways

steep rose
#

im guessing you are trying to pivot around something using arrow keys?

tender cloak
#

Yup

steep rose
#

what is happening when you use the Transform.RotateAround function?

steep rose
tender cloak
#

It's what my lecturer is saying cause when you use rotateAround for both the x and y axis then then it starts rotating around the world's axis and not the local axis so I need to implement space.self onto the y axis but I can't use rotateAround and space.self together

#

So I think I have to use the rotate method along with space.self

#

But trying it I can only get it to look up and down not actually rotate around

steep rose
#

not sure if it does allow local coordinates

#

someone will probably correct me if im wrong

tender cloak
#

I appreciate you trying to help but I feel like it'd be easier to explain with the code but I don't have that right now

#

So thanks again

steep rose
#

alrighty, come back when you have it 👍

tender cloak
#

Perfect

nocturne kayak
#

I'm guessing this goes in this channel

#

Does anyone know of a way to implement gizmos ingame?

#

i want to make a sims-ish building game, and for that i'd want to move, rotate and scale some furniture around

teal viper
nocturne kayak
eternal needle
nocturne kayak
#

I`d be modelling the gizmos myself, as to prettify it a tad

#

and that provides another problem

#

how would i implement the gizmos?

#

my first guess was to apply a move constaint and do an onclick > slide parent along that axis

#

but i don't know if there's a better way to do that

teal viper
nocturne kayak
#

it doesn't make it easier that i'm doing it in VR, but i'm counting on the meta XR SDK to handle most of the distance grab problem for me, overall, crossing that bridge when i get there

teal viper
#

Implement the system with mouse first. Then adapt to VR.

nocturne kayak
#

That's the plan

teal viper
#

If your implementation is good enough, you'd just need a small wrapper for the vr input.

nocturne kayak
#

I'm coming in from Unreal, so it's a bit harder getting used to the component workflow

#

prefabs seem similar to blueprint actors, but there's still some weirdness

teal viper
#

Doesn't unreal have components as well..?🤔

nocturne kayak
#

Yes and no?

#

Most things i'm doing with components in unity i'd do with blueprinting alone in unreal

teal viper
#

I know the line between objects and components is less clear in unreal. Like you can parent "components" to the object.

nocturne kayak
#

sure i can use components in UE to speed things up if i had, let's say, a specific movement script i want to reuse and don't want to ctrl v it about a lot of blueprints

#

but for instance, to make a grabbable object i'd spend most of my time doing busywork with BPs than just adding, idk, 4 components and calling it game

#

Back to the task at hand

#

How i'd approach this is

#

make each axis gizmo a child of the mesh

#

and when click\drag relative to where it was first clicked, slide it around that axis

#

slide parent along that axis*

#

i guess that'd involve doing a camera raycast to convert screenspace to world space? maybe not? who knows

#

That's the main problem here, i'm not entirely sure where to begin

#

and not in a plan-it-out way kind of begin, moreso hands on

#

having come from visual scripting i'd say my logic is ok but C# is trash, so

#

I'm not exactly asking to be spoonfed here, but would you happen to know of a tutorial or two that would roughly point me in the right direction so i could take it from there?

eternal needle
# nocturne kayak and when click\drag relative to where it was first clicked, slide it around that...

you dont have to make it exactly like the unity gizmos. also not sure about your game but doing it this way would imply they can move it freely along the axis in any rotation, which im not sure is what you want.
Id start simple, realistically the code is very straightforward of literally just having a method for moving, rotating, and scaling the object. Then its just a matter of setting up the UI or objects that can be dragged/clicked

eternal needle
nocturne kayak
#

The man in the tutorial's got a thick accent and 40k views so i'm pretty sure i'm finishing this one as a pro

#

While i have you guys here- something i'm finding hard to understand

#

What exactly does serialize field do?

#

i read it has something to do with making variable accessible at runtime but i don't feel super secure on that definition

eternal needle
#

a private variable with [SerializeField] can be changed through the inspector, but not through other code (normally) as its private. that "at runtime" part doesnt make sense

tender cloak
#

am i allowed to send a part of my assignment in this to help me explain a problem?

eternal needle
tender cloak
#

perfect thank you

eternal needle
#

i see you asked about this before in the general channel, ill continue this there since someone replied to you there too

tender cloak
#

my bad didnt see

topaz mortar
#

I'm making a 3d tower defense game. What's a good way to have turrets find a target?
The tutorial I'm using uses FindGameObjectsWithTag, but it seems pretty bad to run that on each turret?
Would it make sense to have something like an EnemyManager script, that just has a list of all enemies? Turrets can then just each go through the list to find their target?
On spawning an enemy I add it to the EnemyManager and when it is destroyed I remove it again?

wraith grotto
#

I made a prefab for a cleaver throw to rotate and go straight when thrown but for some reason the gravity is still impacting the projectile and it's not rotating. i left a screenshot of the prefab and the script connected to it.

Please, pretty please, help a colleague out

wraith grotto
# topaz mortar I'm making a 3d tower defense game. What's a good way to have turrets find a tar...

From personal experience, i use raycast to find a target in certain range. don't have a good example but that should get you started.

This seems ok

https://www.youtube.com/watch?v=iFTKwvpeY08

In this video, I will show you how you can detect gameobject by raycast in Unity3D through C# scripting.

Our Social Media below
Facebook Group : - https://www.facebook.com/groups/271533838295015/
LinkedIn Group : - https://www.linkedin.com/groups/12623148/

▶ Play video
topaz mortar
eternal needle
stiff fjord
#

is it bad too do this?

elfin hatch
#

I have three objects I want to rotate on their local X axis. Their Y rotations are 0, 120 and 240.
myObject.transform.Rotate(myObject.transform.right, 20 * Time.deltaTime);
that works for the one with a y rotation of 0, but rotates the others badly.
What should I do to get the rotations working correctly?

teal viper
stiff fjord
slender nymph
stiff fjord
teal viper
#

Can you categorize your player handler as a game handler? Depends on what their purpose in the project. Then the next important point is naming your scripts correctly. If all it does is increment a timer, it's probably a TimerHandler, not a GameHandler.

#

The 3d point is that you probably shouldn't be doing multiplayer if you're asking these questions.

topaz mortar
#

how would I figure out how bloons does this?

#

I'm never gonna have 1000s of enemies or towers, so I doubt it really matters how I do it either way?

wintry quarry
#

And/or OverlapSphereAll

eternal needle
languid spire
eternal needle
topaz mortar
#

but comparing two transforms to get the distance is not expensive is it? why does it matter that each tower is doing it for every monsters?

languid spire
topaz mortar
#

is that too much? I have no idea lol

languid spire
#

per frame? yes, that's a lot

teal viper
steep rose
#

Instead of getting all the enemies at once, get the enemies from a trigger or overlapsphere when in radius

eternal needle
# topaz mortar but comparing two transforms to get the distance is not expensive is it? why doe...

Honestly it could be valid to do. You could probably HEAVILY reduce that if you have some sort of area system (if towers arent global range). Like simple example, divide the area in however many segments you want. Have towers check which segments are visible. Put all the objects in a segment in it's own list.
Also you can break after it finds the first valid result. So suddenly instead of searching through 200, itd be more like 10 objects

topaz mortar
#

something like ontriggerstay?

steep rose
#

That would work or ontriggerenter

ivory bobcat
eternal needle
# topaz mortar something like ontriggerstay?

If that's how you want to detect when an object moves between these segments, sure. Not exactly sure how you're game would work but the 2d games at least follow a set path so youd know exactly when its in a new segment

#

I did mention looking at bloons for this because they did optimize it a ton, and I believe they have such a system similar to what I described. But my knowledge of it is very limited

steep rose
#

Doesnt bloons use a range based detection?

eternal needle
#

I dont really know what you mean by that. Any form of checking distance would be range based detection

steep rose
#

When in radius => find enemies in range and do something

topaz mortar
#

but how would I set up radiuses?

steep rose
#

Scroll up, bawsi did talk about a neat system you could incorporate

topaz mortar
#

I was thinking of adding a collider around each tower and only check enemies for distance inside that collider
also towers don't just shoot the first enemy, they will have settings, like first, lowest health, most armor, ...

steep rose
#

You can use triggers, overlapsphere, etc. Anything that has to do with finding something in a radius, best you look on docs

eternal needle
topaz mortar
#

but I don't understand what you mean with segments

#

or at least not how to set it up

steep rose
#

Segments, tiles of the map

#

To search in

#

I wouldn't even have come up with something like that, seems pretty neat burrito too 😅
So great job bawsi

topaz mortar
#

so then a tower would have to search the segment it's in and all the surrounding ones too?
cuz it could be on the edge of 2 or even 4 segments?

#

but why not just use a collider to check which enemies are in range? is that bad?

eternal needle
topaz mortar
eternal needle
topaz mortar
#

so segments is probably the way to go?

steep rose
#

It's easier for the computer to check 2 or 3 segments for each tower than for it to always check for 100 to 200 enemies continuously

topaz mortar
#

I could make small segments and then assign each tower type how many segments far it should search 😮

eternal needle
eternal needle
topaz mortar
eternal needle
topaz mortar
#

yeah that's pretty much what I meant, but probably a bit better

ashen frigate
unkempt zenith
#

hi, i'm working on a 2d topdown project, and i'm searching for a way to move my player, but i saw multiple ways, so i wondered, what's the best way to move a 2d player ???

slender nymph
#

use a rigidbody

steep rose
#

Or a CharacterController

#

But do not translate it

slender nymph
#

CharacterController is a 3d collider. do not use it for 2d

steep rose
#

Did not know that

unkempt zenith
steep rose
#

Dont translate it or else it will ignore collisions

slender nymph
elfin hatch
#

So... my bool "clawOpen" starts true and the angle starts 0, so the first condition starts being met.

    {
        foreach (GameObject claw in _claws)
        {
            if (clawOpen && claw.transform.eulerAngles.x < 60)
            {
                claw.transform.Rotate(claw.transform.right, 20 * Time.deltaTime, Space.World);
            }
            else if (!clawOpen && claw.transform.eulerAngles.x > 0)
            {
                claw.transform.Rotate(claw.transform.right, -20 * Time.deltaTime, Space.World);
            }
        }
    }```
I use spacebar to toggle the bool clawOpen.
it opens automatically to 60 degrees then stops. perfect.
I then press spacebar and it closes past 0, doing another full 360 before finally stopping at 0. PROBLEM....
but then any opening and closing after that 1 problem, everything works fine. its just that initial toggle to closing will do 360 degrees more than it should.
help me understand why/how to fix 😦
unkempt zenith
#

and the project isn't based on physics

#

by physics i mean like angry birds or smth smiliar

steep rose
#

Then use the velocity of it or use its add force function

steep rose
#

Translating the collider will only make it ignore collisions, best not do it that way

slender nymph
# elfin hatch So... my bool "clawOpen" starts true and the angle starts 0, so the first condit...

you are basing your logic on the transform.eulerAngles which is going to lead to issues (like what you are experiencing). euler angles are interpreted from the quaternion that is used for the rotation at the time you access it, and rotations can be expressed in a large number of ways in euler angles. you would be much better off either using something like a hinge joint if you want to do it the really easy way, or use a float that you modify as the rotation about that one axis and use that for your logic and assigning the rotation

slender nymph
elfin hatch
slender nymph
#

if it needs physics interactions then modifying its transform is definitely not the way to do it. you should be using a joint

elfin hatch
#

ok, wasn't aware joints existed. Where should i start looking 😛

slender nymph
topaz mortar
#

I'm using MoveTowards, seems really nice

naive lion
#
                                 .setOnUpdate((float value) =>
                                 {
                                     outlineShader.SetFloat("_DisolveValue", value);
                                 });```

Hey guys does anyone know why when I changed the disolve value of a material, after playtesting in the editor, when i stop playing, the value is still at 1?
astral falcon
naive lion
agile trail
#

Can someone help me fix this issue I have been having with my project?

slender nymph
# naive lion ```Material outlineShader = outlineIMG.material;``` I thought .material creates ...

no, you're correct. that will instantiate the material
https://docs.unity3d.com/ScriptReference/Renderer-material.html

This function automatically instantiates the materials and makes them unique to this renderer. It is your responsibility to destroy the materials when the game object is being destroyed. Resources.UnloadUnusedAssets also destroys the materials but it is usually only called when loading a new level.

agile trail
#

Whenever I click spacebar my code does not run

slender nymph
eternal falconBOT
naive lion
agile trail
slender nymph
agile trail
slender nymph
#

!code 👇

eternal falconBOT
slender nymph
#

this is also in the posting guidelines in #854851968446365696 that the previous bot message advised you to check

agile trail
#

ight can I post the link here?

naive lion
agile trail
slender nymph
slender nymph
naive lion
slender nymph
#

you could always just instantiate the material yourself then assign the instantiated one to the image

agile trail
slender nymph
#

mate i don't even know what isn't working because you've not bothered saying

agile trail
#

Ight bro, I have not used Keycodes before and want to know if the way I used them is right as whenever I use spacebar (which is referenced) It does not complete the action

pulsar meteor
#

how can i use the unity cloud

slender nymph
slender nymph
agile trail
slender nymph
#

this has nothing to do with your "experience with code". you are literally not describing anything at all about what you are expecting to happen. as for what is expected from you, you are expected to at least have some idea of what it is you are having trouble with.

thorny basalt
verbal dome
#

They are using old input system

frosty hound
#

It's just the classic beginner mistake thinking it's the input that's not working, when it's just grouped with other conditions they're not verifying working.

#

Space = jump = isGrounded = classicisgroundedisnotworking

agile trail
frosty hound
#

Your issue likely has nothing to do with the input system

thorny basalt
hasty tundra
#

Im using unity 2d, and trying to find a function / way to calculate which of 2 objects is closer to 0,0, how would i do this?

verbal dome
agile trail
#

is there any videos I could look up to wrap my head around these terminologies better?

verbal dome
pulsar meteor
#

!code

eternal falconBOT
verbal dome
#

@hasty tundra so the value with smaller magnitude is closer to 0,0

thorny basalt
hasty tundra
hasty tundra
pulsar meteor
verbal dome
pulsar meteor
thorny basalt
# hasty tundra yeah

return(vector2.distance(position1, vector2.zero) > vector2.distances(position2, vector2.zero) ? position1 : position2;

verbal dome
#

Distance is overkill when comparing against zero, might as well use magntude/sqrMagnitude directly

frosty hound
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

agile trail
verbal dome
brittle kelp
#

how do i make a audio clip play with scripts

deft grail
sick ether
#

is Assets/Plugins still advisable? Im getting some conflicting googles and I dont see it as a special folder in the current docs--but it is specified in the older docs.

pulsar meteor
#

how to get the measure texture

wintry quarry
#

What's a measure texture?

pulsar meteor
#

this 1

#

found it

wintry quarry
#

Just search for prototype materials or something

nocturne kayak
#

Hey

#

I have a tad of a problem here, and may god forgive me for my ifelsing but, i have this code

#

and what i'm expecting to happen here it, when i click down on an object, i drag it, when i let go, it stops dragging

cosmic dagger
#

use this to format your !code or use one of the sites to paste . . .

eternal falconBOT
nocturne kayak
#

however, what happens is:

#

it moves to spot X when i click it

#

it doesn't really follow the cursor, if that makes sense

keen dew
#

GetMouseButton instead of GetMouseButtonDown to start with

nocturne kayak
#

That seems to work

#

but i don't quite understand the difference

cosmic dagger
#

check the unity docs. it has a description for both of the methods. they are slightly different . . .

nocturne kayak
#

Alright, thank you

#

something else, the way i understand it, my code should only ever affect the z axis of the cube

pulsar meteor
#

how can i make a e to interect npc

nocturne kayak
#

actually, no it shouldn't because i'm never setting the originalPosition.

#

coolio

polar acorn
pulsar meteor
native basin
#

Hey. Im trying to edit my script for a game im making and ran in to this issue where the c# is opened in memorandum. is it supposed to open there or do i need to download something

polar acorn
eternal falconBOT
nocturne kayak
#

using GetMouseButton seems to work for what i'm aiming for, and it works great for moving it around world Z

#

however, if i rotate it....

#

still drags around world Z

#

when i'd like for it to be localZ,

#

I'm kind of at a loss here

queen adder
#

You can use local position or local rotation

nocturne kayak
#

i tried just that

#

and it still drags around world Z

pulsar meteor
#

can i get help to clean up my code

polar acorn
#

X and Y are unchanged, Z is going to the world position of the mouse

nocturne kayak
#

how would i go about getting the mouse position relative to the object itself?

cosmic dagger
pulsar meteor
#

!code

eternal falconBOT
polar acorn
cosmic dagger
pulsar meteor
cosmic dagger
native basin
pulsar meteor
polar acorn
verbal dome
#

It doesn't look that messy to me

native basin
polar acorn
pulsar meteor
#

but i am not sure

polar acorn
#

You want your code to be "clean" as defined by the people actually working on it

pulsar meteor
polar acorn
#

Other people's coding styles are just going to make it less understandable

native basin
polar acorn
eternal falconBOT
native basin
#

which of these

polar acorn
#

The one you're using

native basin
pulsar meteor
#

i thought maybe there is like a whole thing that could be done 1 line or something like that

tulip nimbus
#

Hello! When using ridigBody my character collision works just finde. However once i put it in Dynamic mode and use Vector3 for transform my character just glides trough the collision that worked before. What can i do?

polar acorn
tulip nimbus
polar acorn
verbal dome
polar acorn
#

If you want your rigidbody to collide with things you need to move it by using the rigidbody

tulip nimbus
#

yeah i guessed that it changed the values regardless of collision, what can i do?

verbal dome
polar acorn
#

Either MovePosition, AddForce or setting the Velocity

#

As long as it's the rigidbody doing the movement, not the transform

pulsar meteor
verbal dome
pulsar meteor
#

this is the blend tree

#

or this

verbal dome
#

I'm just thinking you could have the blend tree be controlled by two floats and then from code just call .SetFloat("MoveX", moveX) and .SetFloat("MoveZ", moveZ)

#

But meh, the code already looks readable to me

pulsar meteor
#

why has everybody a ! if i look to the right of my screen

deft grail
#

its in alphabetical order

pulsar meteor
cosmic dagger
#

!ask

eternal falconBOT
deft grail
#

of course its possible, theres many tutorials on youtube for it if you want

ashen frigate
#

can u help me with my code ?

#

idont know why my double jump wont work

#

ive change my code to simple one

#

to check it

#

i get infinity jumps but not double jump

#

void handleJump()
{
if (isJumpPressed)
{
if (grounded == true || air_jump == 1)
{
rb.AddRelativeForce(Vector3.up * 10);
//ChangeAnimationState(PLAYER_JUMP);
air_jump = 0; <--------------------------- even with this
}

deft grail
pulsar meteor
#

why isnt it working

deft grail
#

also the class name for this script is NewBehaviourScript which is most likely wrong

polar acorn
ornate vector
#

Hello, i'm trying to make a visual novel game and i'm struggling playing the next sentence. This is my BottomBarController code -> https://hastebin.com/share/pocibetepa.csharp and my GameController code -> https://hastebin.com/share/axuxajeyun.csharp when i changed the void Start() to public void PlayNextSentence() it doesn't even show the type writer effect or color anymore.

#

in the video tutorial he changes the name of void Start() and it works for him?

deft grail
ornate vector
# deft grail you do realize `Start` is run at the beginning of the game, `PlayNextSentence` i...

In this video you will learn how to create text writing effect and change scenes in visual novel style using Unity!

Discord server: https://discord.gg/gRMkcyNhwa

Google drive project: https://bit.ly/3zBAyXY - for educational purposes only

Music credits:

  • You’re Thinking About That Person Again and La Lluvia En Persona by Barradeen -
  • Fl...
▶ Play video
polar acorn
deft grail
#

do you have any errors in the console?

polar acorn
ornate vector
#

i think?

polar acorn
ornate vector
polar acorn
#

You should probably watch the whole thing

ornate vector
#

I watched till the part that the next ssentence played for him and i'm just rewatching it

#

i also looked at his script and i don't know what could be wrong

polar acorn
#

Notice how this is in Start

ornate vector
#

Yes and i also have that, so why wouldn't it work?

polar acorn
#

Show the inspector of your GameController object

fresh ferry
#

um i need help

polar acorn
#

!ask

eternal falconBOT
fresh ferry
#

oh

deft grail
ornate vector
#

Is that what you're looking for?

polar acorn
#

no

ornate vector
#

I'm sorry this is my first time asking for help 🥲

polar acorn
#

the actual instance of the component in the scene

rich adder
#

the one thats on a gameobject is always what counts

finite dove
ornate vector
#

I don't see him having a gameobject called GameController in the game

polar acorn
#

it needs to have that component on it

fresh ferry
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{

    public CharacterController2D controller;

    public float runSpeed = 40f;

    float horizontalMove = 0f;

    void Update () {

        horizontalMove = Input.GetAxisRaw("Horizontal");

    }

    void FixedUpdate ()
    {

        controller.Move(horizontalMove * Time.fixedDeltaTime, false, false);
    }
}
finite dove
ornate vector
pulsar meteor
#

what wrong whit this

rich adder
deft grail
rich adder
pulsar meteor
finite dove
polar acorn
pulsar meteor
rich adder
polar acorn
pulsar meteor
#

i never saw that sorry

rich adder
#

NPCInte

#

very nice

polar acorn
#

show that

pulsar meteor
#

it should be NPCinteract

fresh ferry
polar acorn
rich adder
pulsar meteor
#

then i misspeld

rich adder
fresh ferry
#

the player cannot move

#

it's only changing directions

ornate vector
finite dove
polar acorn
rich adder
pulsar meteor
fresh ferry
fresh ferry
rich adder
#

also thats my first time seeing CharacterController moved in FixedUpdate 🤔

polar acorn
# fresh ferry

This should be working. You're moving it at 1 unit per second, assuming CharacterController2D is actually doing anything with the .Move function

deft grail
# fresh ferry

making it 9999 wont do anything if the variable isnt used

fresh ferry
#

Shi im confused

polar acorn
rich adder
#

Ahhh yes I'm blind .

finite dove
pulsar meteor
fresh ferry
deft grail
#

already

polar acorn
fresh ferry
polar acorn
#

Show it

polar acorn
rich adder
# fresh ferry

management wants you to find differences between these two

fresh ferry
polar acorn
#

yes

fresh ferry
#

Let’s give our player some moves!

● Check out Skillshare: https://skl.sh/brackeys7

● Character Controller: https://bit.ly/2MQAkmu
● Download the Project: https://bit.ly/2KPx7pX
● Get the Assets: https://bit.ly/2KOkwjt

❤️ Donate: https://www.paypal.com/donate/?hosted_button_id=VCMM2PLRRX8GU

····················································...

▶ Play video
rich adder
#

bot smacked you down w/ that meme lol

deft grail
fresh ferry
rich adder
#

omg ads on discord embeds

fresh ferry
#

i dont have many brain cells

finite dove
deft grail
rich adder
#

I'm paying Brackys because OP couldn't copy it correct 😦

polar acorn
#

Oh hey look at that, Brackeys didn't use it either. Congratulations, you're one of the 6 people who actually found a problem in the tutorial

"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 177
Number of times it was exactly like the tutorial: 6
Number of times the code literally did not exist: 1
2022-07-19 to 2024-09-19
rich adder
#

average brackys shenanigans

polar acorn
#

The last shot of the script in the tutorial is still wrong, he never fixes it

rich adder
#

a+ production quality , d- code

deft grail
#

because he does it with the input

#

the multiplication

polar acorn
#

Ah, right

#

it's not in the movement but in the input for some reason?

#

Strange choice

rich adder
#

yeah you can't ever check horizontalMove < or > 0 for other logic

#

silly

polar acorn
#

Let’s give our player some moves!

● Check out Skillshare: https://skl.sh/brackeys7

● Character Controller: https://bit.ly/2MQAkmu
● Download the Project: https://bit.ly/2KPx7pX
● Get the Assets: https://bit.ly/2KOkwjt

❤️ Donate: https://www.paypal.com/donate/?hosted_button_id=VCMM2PLRRX8GU

····················································...

▶ Play video
#

Yep, he adds it in at about 12:15

#

Well, since I missed it as well, it'd be unfair to add it to the first counter, but I'm afraid I have to revoke that point for the second:

"I did it exactly like the tutorial so why does theirs work and mine doesn't" counter:
Number of times it wasn't exactly like the tutorial: 177
Number of times it was exactly like the tutorial: 5
Number of times the code literally did not exist: 1
2022-07-19 to 2024-09-19
nocturne kayak
#

right now i'm only trying to move it along it's local z and use the blue capsule as a handle later on

fresh ferry
#

shi

rich adder
#

no memes

fresh ferry
#

oh

#

mb

rich adder
#

@fresh ferry do you know what you have to fix now ?

polar acorn
#

You'll want to add to the object's position, not set it

polar acorn
# fresh ferry nope

Go to the most recent link I sent, that's the timestamp in the video you missed

rich adder
#

or read anything we said these past minutes

snow girder
#

hey guys, i just wanted to ask a question. would charactercontroller work better for a stealth game or rigidbody?

nocturne kayak
rich adder
fresh ferry
snow girder
#

like movement wise would character controller feel better for stealth or would rigidbody?

fresh ferry
polar acorn
deft grail
rich adder
polar acorn
rich adder
snow girder
finite dove
rich adder
#

Character Controller is basically a kinematic rigidbody but with .Move collisions

polar acorn
nocturne kayak
polar acorn
#

That's really it. You can do whatever with both

polar acorn
snow girder
#

alright, thank you for your input

rich adder
#

+1 c controller

polar acorn
pulsar meteor
#

how can i make a widget with text

#

for npc talking

finite dove
rich adder
pulsar meteor
#

and if you near the click e to interact

finite dove
fresh ferry
#

uh what does that mean

rich adder
polar acorn
#

It means all compiler errors have to be fixed before you can enter playmode

pulsar meteor
fresh ferry
#

why is it so complicated pepesob

finite dove
polar acorn
#

So, fix them

pulsar meteor
polar acorn
#

Look at the errors and see what they are

rich adder
fresh ferry
finite dove
# pulsar meteor i have this

it's okay you also can start like that, add canvas > set to camera scale
and all you have to do was.

  • check if the player near npc
  • if so then send trigger to canvas
  • show popup
rich adder
deft grail
polar acorn
# fresh ferry

Okay, now look at that line and see what's underlined in red

fresh ferry
polar acorn
eternal falconBOT
polar acorn
#

do that

#

then fix the underlined problem

#

Compare your line with the tutorial's

fresh ferry
#

ight

deft grail
polar acorn
finite dove
rich adder
# pulsar meteor and

keep an object you can use for showing text, carry it /enable disable with player

finite dove
nocturne kayak
#

but shouldn't transform.forward be a float in it self, since i'm only getting one item of a vec3?

pulsar meteor
#

is there any video turtorial

#

that is good

rich adder
#

it's not a float, magnitude is a float

finite dove
finite dove
rich adder
# pulsar meteor and

NPCInteractable can store the "string" for each text or make a component for it which is better

#

then grab it on the E interact method to display it on the text object you carry about enabling /disabling it

pulsar meteor
#

to amke this thing i use this tt https://www.youtube.com/watch?v=LdoImzaY6M4 but he uses a

✅ Get the Project files https://unitycodemonkey.com/video.php?v=LdoImzaY6M4
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
👇 Click on Show More
🎮 Get my Steam Games https://unitycodemonkey.com/gamebundle

POLYGON - City Pack https://cmonkey.co/synty_city_talknpcs
...

▶ Play video
#

other thing that i dont want

rich adder
#

a "other thing"

#

speaking in vagaries

fresh ferry
#

IT WORKS

#

YES

#

FINALLY

finite dove
polar acorn
pulsar meteor
polar acorn
#

Hang on I have a video tutorial you could use.

#

✅ Get the Project files https://unitycodemonkey.com/video.php?v=LdoImzaY6M4
🌍 Get my Complete Courses! ✅ https://unitycodemonkey.com/courses
👍 Learn to make awesome games step-by-step from start to finish.
👇 Click on Show More
🎮 Get my Steam Games https://unitycodemonkey.com/gamebundle

POLYGON - City Pack https://cmonkey.co/synty_city_talknpcs
...

▶ Play video
pulsar meteor
#

just want someyhing like this

pulsar meteor
inner bane
pulsar meteor
#

but i want a other text

polar acorn
#

Yes I know that's why I linked it again

polar acorn
rich adder
# pulsar meteor

its not complex but it is if you just skip your way through learning anything

finite dove
pulsar meteor
#

just text i want this text thingy

#

anf i dont know how

polar acorn
#

yes we know

rich adder
#

"I want this" but doesnt go and learn it

polar acorn
#

and the tutorial you linked seems to tell you how to do that

#

so go do that

pulsar meteor
#

he does something else

finite dove
#

Text? like the FONT? or the UI Design? im confuse UnityChanHuh

pulsar meteor
#

UI desing

polar acorn
rich adder
#

where is the "generate dialogue code and UI the way i want it" Button

pulsar meteor
#

but de turtorail uses de text bubble

polar acorn
#

so if you don't want a bubble

pulsar meteor
#

like you are texting

polar acorn
#

don't use a bubble

pulsar meteor
#

i dont know how to do it other wise

rich adder
#

apply some creative thought, learn the tools and manipulate to your liking

polar acorn
#

the shape of the dialogue box is not a major factor in the tutorial

#

just... use a different shape

inner bane
#

Hello
I have a problem with my main menu script,when I click play in the main menu's scene it is supposed to teleport me to the game scene but instead it does a quick flash like it loads something and then it crashes.
Here is the main menu's script:
https://hastebin.com/share/ofohocivic.csharp

polar acorn
inner bane
#

the game stops

polar acorn
#

So, it exits play mode?

inner bane
#

like its just like I click stop play mode

#

yeah

polar acorn
#

Then it would seem like something is calling ExitGame

#

Try putting a log in that function and see if it prints

#

if it does, it should tell you what's calling it

inner bane
#

like debug?

polar acorn
#

yes

inner bane
#

alr

#

ima test rq

slender nymph
#

does it actually exit playmode entirely or does it actually pause play mode?

inner bane
#

entirely exit playmode

#

I also tried on the build version and it closed the game

pulsar meteor
#

what is the sprite 3d version

#

never mind

slender nymph
inner bane
#

uhm yeah but im kinda new into these and I dont really know how to check and fix it 😭

polar acorn
#

did you put in the log

inner bane
#

Ima run it rn

#

yeah... pressing play and it says exit button clicked,quitting game

slender nymph
#

then look at the button

#

specifically the play button and make sure it isn't set to call ExitGame

inner bane
#

yoo... im dumb,they were colliding between themselves and the exit button had a chunk of it over the play button 🤦🏿‍♂️

#

lol

#

ty for the help

pulsar meteor
#

how do i make this

#

wit this

polar acorn
#

Change the text on a UI panel instead

pulsar meteor
#

what

polar acorn
#

Instead of creating an object with that text on it, change the text of an already existing gameobject

pulsar meteor
#

you mean the tmp

faint osprey
#

in visual studio how do you do the thing where you search for a variable and it shows u every point in your code where its refrenced

languid spire
faint osprey
#

thanks

vocal wharf
rocky canyon
#

only within that class tho

languid spire
vocal wharf
#

oh?

vocal wharf
pulsar meteor
#

the code from the turtorial doesnt work

frosty hound
#

That is very rarely the case.

rocky canyon
#

he's got a point.. people rarely script, record, and then edit for hours to publish a video containing code that doesn't work..
its not a viable strategy

tender cloak
#

Why does this cause a gimbol lock when i reach the top using the up and down arrow keys and how would i go about fixing it?

rocky canyon
#

it would
a. be removed by now
b. have a comment section filled to the brim with "don't waste your time it doesn't work"

rocky canyon
tender cloak
#

so there's no need for them?

rocky canyon
#

nope.. not the ones in the conditionals

#

you can just have moveCamera.y/x logic in there

pulsar meteor
#

what is the path from cancas for hide unhide code

tender cloak
#

yea everything seems to work fine just when i reach the top or bottom of the mars it starts spazzing out

rocky canyon
rocky canyon
#

you may want to use a different function than LookAt.. i know its simple.. but when using quaternions and rotations and stuff theres better ways that prevent gimbal lock

tender cloak
#

We haven't done quaternions and clamping yet but maybe i need to somehow find the distance between the camera and the mars position and use that?

ruby python
#

Not sure if in the right place for this one, but would anyone know if it were possible to create a day night cycle while using an image based skybox in URP? Everything I've found is all based on the default skybox, but I want it to rotate with the 'sun' (terrain based game, same skybox for day and night, just want to rotate it. 😕

pulsar meteor
rocky canyon
#

it'd be like combining the procedural one w/ a regular one

languid spire
echo sand
#

any idea why this doesnt work? my character is standing still

    void UpdateGravity()
    {
        Velocity += Gravity * Time.deltaTime;
        Vector3 NewPos = transform.position + new Vector3(0, -Velocity, 0);
        Vector3 Dir = NewPos - transform.position;
        float Dist = (NewPos - transform.position).magnitude;
        RaycastHit Hit;

        bool RayCast = Physics.Raycast(transform.position,Dir, out Hit,Dist, Layer);
        if (RayCast)
        {
            transform.position = Hit.point;
            Velocity = 0f;
        }
        else
        {
            Debug.Log(NewPos    );
            transform.position = NewPos;

        }
        
    }
rocky canyon
pulsar meteor
rocky canyon
#

SetActive is for gameobjects

short hazel
pulsar meteor
#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NPCInteractable : MonoBehaviour
{
// Referentie naar het Canvas GameObject
public GameObject menuCanvas;

private void Start()
{
    // Zorg ervoor dat het canvas verborgen is bij het begin
    Canvas.SetActive(false);
    Debug.Log("Canvas is uitgeschakeld");
}

// Methode om te interacten
public void Interact()
{
    // Activeer het canvas bij interactie
    Canvas.SetActive(false);
    Debug.Log("Interact!");
}

}

echo sand
ruby python
rocky canyon
ruby python
#

I'd like to be able to rotate the sun (direction light) and the skybox, I know it's possible in HDRP cause I've done it, but it's all Volume based, and no options for it in URP 😕

short hazel
short hazel
#

Also prefer naming local variables using camelCase, so they're differentiated from class-level ones: Vector3 newPos, Vector3 dir, etc.

#

Replied to the wrong user

ruby python
short hazel
#

Are you by chance using a CharacterController to move?

echo sand
#

ye

echo sand
short hazel
#

That's why, you cannot modify transform.position when the CC is active

echo sand
#

oh

#

i read i have to make my own gravity behavior if i use CC

short hazel
#

The position changes and is immediately rolled back by the CC

pulsar meteor
#

Canvas.gameObject.SetActive(false);

short hazel
pulsar meteor
#

never mind

hallow acorn
#

hey im trying to compare the tag of an object hit by my raycast, but for some reason i only have these options and ive seen a lot of people on yt having the method compareTag there

pulsar meteor
#

how can i add a timer of 10 seconds

hallow acorn
#

look it up

short hazel
#

If you're using 2D, use Physics2D!

lethal meadow
#
using UnityEngine;

public class EnemyLunge : MonoBehaviour
{
    public Transform player, characterHead;
    public float force = 1;
    private bool ready = true;

    void Update()
    {
        Vector3 aimPos = player.position - gameObject.transform.position;
        RaycastHit hit;
        if (Physics.Raycast(gameObject.transform.position, aimPos, out hit, 5) && ready)
        {
            gameObject.transform.GetChild(2).GetComponent<Rigidbody>().AddForce(aimPos * force, ForceMode.VelocityChange);
            ready = false;
            Debug.Log("gotcha");
            Invoke("applyDrag", 1f);
            Invoke("resetReady", 1f);
        }

        characterHead.LookAt(player);
    }

    void applyDrag()
    {
        Vector3 dragPos = gameObject.transform.position - player.position;
        gameObject.transform.GetChild(2).GetComponent<Rigidbody>().AddForce(dragPos * (force * 10), ForceMode.Force);
    }

    void resetReady()
    {
        ready = true;
    }
}
rocky canyon
#

In Unity, the difference between impulse and velocity change is how they affect the velocity of rigidbodies:
Impulse: Applies force instantly, taking the object's mass into account.
Velocity Change: Changes the velocity of every rigidbody in the same way, regardless of mass. This is useful when controlling a group of objects with different sizes, like a fleet of spaceships. @lethal meadow

lethal meadow
#

its only doing the func once

hallow acorn
lethal meadow
#

sometimes twice

#

idk why

rich adder
short hazel
#

(scroll down to the 2nd overload)

lethal meadow
#

the main thing in update only runs twice

#

then stops working

rocky canyon
#

then the raycast is returning false afterwards

lethal meadow
#

it is

#

but i dont see why it stops working consistently after 2 turns

willow scroll
# hallow acorn

Since you're struggling with C# syntax, I think it's better if you first learn it

hallow acorn