#💻┃code-beginner
1 messages · Page 489 of 1
This one is really hitting home for me
ooh I think its the first one
that would explain why everything still functions as it should
yeah i will pretty heavily use lambdas for callbacks, but for events that you must unsub from just always use a named function directly
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.
you changed the signature so it require a passed arg now
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
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)
so what does the signature of PlayerDash look like?
it is called in start
//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;
}```
no you showed it being in OnEnable
Working on getting my stamina working now
private void PlayerDash(InputAction.CallbackContext ctx = null)
make it that
But that basically works
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
it's in OnDisable which happens via a method in start
other option is just have 1 method that is only for the event, that just calls your regular playerdash
wait i misread OnDisable with OnEnable..nvm
is OnDisable automatically called as soon as the game is run
if the script is off
with = null
error: "A value of type '<null>' cannot be used as a default parameter because there are no standard conversions to type 'InputAction.CallbackContext'"
ok so where do you disable the script ?
must be after scatter gets unassigned
btw CallbackContext is a struct unless nullable you can't pass null
value types are not null types
So this basically makes the data structure empty?
Not sure how the data structure looks but basically it's empty lol
yeah default just creates the "zero" value for a given type
= default did work in the coder. Testing it in the game
if its a reference type that is null, if its a struct thats it just with its stuff zeroed out
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
is there a reason you're not using events?
Yes, you need to pass a CallbackContext
Mostly just don't know what events are
I thought you were already doing that with a => _ function
I was but that was from following a tutorial where they glanced over why we use those.
I'd have to go back and review it. Some C# that I still don't fully understand.
I tried passing default as my CallbackContext but that did not work.
What would be a thing I would pass through?
Presumably, you wouldn't ever be manually constructing a callback context, you'd be adding this function to an event that calls it for you
Like you were doing up here, except using the function instead of a lambda
So OnEnable is an example of an event?
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?
An event is basically a collection of functions that are called when the event is invoked
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
Interesting, could this be used to trigger something like a co-routine?
Depends on the event
You need to subscribe with a function that has the same return types and parameters the event expects
Ok, I hear you but it's still hard for me to imagine such a scenario
A scenario such as what
Of using an event
You literally already are
Yea, but I don't understand why
lol
So that whenever the button is pressed it calls every function subscribed to it
Ahhhh
solved btw
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.
Create -> C# Script
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) {}
It does
That function has nothing in it
what are you expecting to happen?
keyboard usually
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());
}```
add the Debug.Log back inside of the method to see if it displays. also, you don't need to assign ctx = default . . .
If that's not logging, then playerControls.Movement.Dash.triggered is never true
oh, there's the actual method. something with the button is not registering . . .
Sorry, typo didn't have the curly bracket
Maybe the if statement isn't ever true
It used to trigger
I am going to eat your grass cause of that
Better not to guess and just test
If I take out all the Callback Context stuff, the button triggers
I just get an error about Callback in my concel
good my grass has arsonic in it.
also lets not go offtopic lol
An error would cause undefined behavior
That would have been good to know. What error
It tells you the reason
prob because "um" contribuites nothing to a conversation 🤷♂️
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
yeah well um
alr no need to keep spamming. We get it
So "button pressed" isn't logging either? That would lend credence to my statement that playerControls.Movement.Dash.triggered is never true
That was fixed when you added the callback context parameter to the function
Agreed, now the button is no longer wokring at all
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();```
PlayerDash can no longer be called without parameters
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
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?
The Input System handles calling the event. It depends on what your settings are on the input asset, whether it's enabled, and what devices you have the Input System listening for
The input system is correct. I've had it all work before
Only trying to fix the callback concel message broke it
Fixed it
Removing the code in Start(). Changing OnEnable() to playerControls.Enable(); and leaving private void PlayerDash(InputAction.CallbackContext ctx = default) {...}
cus I'm trying to do it like this it doesn't display it in the event thing
Mission successful!
Thank you to @polar acorn @rich adder @ivory bobcat @cosmic dagger @shell sorrel and all the chatgroup for bearing with me (:
yes
Maybe you should lookup a tutorial about the new input system - you shouldn't have to be polling for input or calling the event with the new input system.
Make a custom struct and use the struct as the event parameter. If these are unity events, you'll need to create a custom unity event with the struct as a parameter to use it from the inspector . . .
Can I make instead of "40" some list
I don't know what is struct
Definitely wouldn't hurt. I watch many tutorials daily. I'll throw that one in the mix.
google is your friend in dev struct
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.
You cannot destroy a prefab
That would be akin to deleting a file
Yeah I understand that. I cant figure out how to destroy the active game object
I still got this
What do I need to put in the variable
Are you still calling destroy on a prefab elsewhere
Is the hit bullet script on the bullet?
No, on the target
What do I put in active bullet
Call cs Destroy(collision.gameObject)
On hit bullet script?
What is the purpose of this variable? What should it be referencing?
no clue, i had an idea and it didnt work
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.
Yeah I just came across this
addtorpue or addrelativetorpue?
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?
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
You shouldn't be copying any code for a second player
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
Pretty straightforward - you're trying to use a variable you never declared
in C# you have to declare all variables before using them.
Let me see where I am missing this.
Notice that on line 12 you declared one variable:
public PlayerController respawn;```
You never declared a variable called respawn2
What do you mean don't copy but use the same code? I don't need two player controllers? One for each player?
How would I check to see what the current scene name is?
SceneManager class (hint: its the second static method)
Why not just make one script and put it on two objects
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.
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
I will have to try that.
Use the same script on both of them
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
I get this though
Enemybehavior4502
you should read your error messages
whya re you doing it this way, this is not how you check a scene name
did you not click the second static method that is on the docs
What's the error say
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?
you could instatiate the stump with the correct position and the tree part above it
you do not have to manually place them
what is a stump?
create a script that samples the terrain height and mass place them
oh ok
just learned that word alone.
but if I don't need to manually place them, how do I do it?
I can see that now.
So should on awake should i get the active scene name then store in in a variable then check that variable in my if statme to see if it matchs to what i want?
well you can put them manually 🤷♂️
how else would you do anything substantial without script ?
like using a brush or something
I can use a brush to mass plant trees everywhere but can't interact with them
that could work if thats what you need happening yea
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
So im doing this in the game to check the level name to make sure it plays the right cutscene after they beat the level
okay i got it calling on awake but im confused on how to store the actual name in a variable...
Anyone know a way to make the bullets come from the ship and not from thin air?
you looked at the example page ?
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
How are you spawning them?
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
}
Spawn a prefab bullet that's not colliding with the ship, and add a horizontal velocity so it moves right
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
Where are you spawning them at
Is the "gun" inside the ship ???
you wouldn't use the Scene type , you probably want the Name so a string from its name property
at the middle of the ship according to the scene but as I move they stay in place and just stay there whenever I shoot
yeah
Show code
gimme a sec
Use rb.velocity = new Vector 2(x,0)
Consider rb as the rigid body of the bullet
And x the speed of it
I don't think they're asking anything about moving it
Does anyone know why this script is preventing me from rotating the camera with other scripts (Like a recoil system for example)
wdym why ? because you keep assinging rotation here
Because you're setting the camera's rotation directly every time this function is called
you would need another parent object to apply the recoil too
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
my bad
use Links for large code
Nothing in here appears to be spawning anything
Also, I really hope you're not actually coding like this with no indentation
1-Where's the Shoot() method ???
2-Use switch statements,comments and space out lines so the code is more lisible
So i did this no errors but it didnt go the the cutscene
its indented in VScode so idk why it came out like that
Does the object running the coroutine get destroyed or disabled
this is wrong
No this code is on the gameManager so its always there
Time to use Debug.Log
you need activeSceneName = SceneManager.GetActiveScene().name
yes that fixed it thanks!
Log the value of activeSceneName outside of the if
you're doing ToString on the struct idk if that gives the name of scene
I sent the wrong code lol
https://paste.ofcode.org/Kw4fVzrKEd9PxiqwbezgK5
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
So, you're spawning an object at the position of the object with GunShooter on it. Where is that object?
YES its working now thankyou so much (:
right here
Okay, now move the ship and show the gizmo again
It starts at the correct position at the beginning of the playtest but starts to spawn incorrectly as soon as I move.
So, where is the object after you move
show the transform gizmo, just like you did before
but after you move the ship
changes position to here for some reason
Do you have your tool handle position set to Center, or Pivot?
is your object a child of your ship?
if its not and you are not moving it, it will stay still
Does this object move, or does it simply stay where it is and the ship moves
Pivot
yeah
it stays where it is and the ship moves
Please show the hierarchy of your scene with this object selected
Can anyone help me make a game?
And does Ship move or does Sprite move
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
ship
can you show us your script that moves the 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
Okay, good. That's step 1, now run the game, move the ship somewhere else, and take another picture just like this one
Okay, now show the inspectors for Sprite, Gun, and FirePoint
- Sprite 2. Gun 3. FirePoint
you have a Ship Controller on the ship and the sprite
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
{
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
clearly you need an int for the for loop, so why not round?
so your saying if my DPS is like 1.5 just give the player 2
you need an int for the loop to work, that's a fact. so you have to determine how you want to convert the float to an int. you choose how you round (determine which way to value goes) . . .
you dont need to use an int in a for loop. you could use a string for all it matters
what part of it "obviously wont work"
Sorry why would this not work if CDPS is a float?
Alright after putting it off for months I finally have functioning recoil and ads
Anyone able to help me with rotating the camera around an object on both the worlds and local axis using arrow keys
rotating a camera around an object?
which camera? scene view or game view?
give details
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
how so?
So I need to rotate up and down on the local axis and the other two on the worlds axis
2 secs
"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
im guessing you are trying to pivot around something using arrow keys?
Yup
what is happening when you use the Transform.RotateAround function?
what do you mean by "wonky"?
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
not sure if it does allow local coordinates
someone will probably correct me if im wrong
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
alrighty, come back when you have it 👍
Perfect
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
Simply think of them as another object with a mesh in your scene, possibly animated.
I`m doing just that, i want to change the x, y z pos and y rot with visible gizmos
havent played myself, are you trying to make some sort of object silhouette before its placed? in that case youd really just use another object with the mesh as dlich said
if you're trying to render lines around, there is the line renderer you could probably use. though its not very pretty imo but neither is gizmos as its a tool during editor time
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
Break it down:
- implement the ability to move and rotate the gizmos with mouse input.
- track the change in gizmo position/rotation
- apply the tracked changes to the target object
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
That makes sense
Implement the system with mouse first. Then adapt to VR.
That's the plan
If your implementation is good enough, you'd just need a small wrapper for the vr input.
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
Doesn't unreal have components as well..?🤔
Well
Yes and no?
Most things i'm doing with components in unity i'd do with blueprinting alone in unreal
I know the line between objects and components is less clear in unreal. Like you can parent "components" to the object.
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?
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
stuff like this would probably fall under "level editor" if you wanted to google
Oh, thanks, i think i've found something good
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
https://docs.unity3d.com/ScriptReference/SerializeField.html
just exposes it to the inspector
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
am i allowed to send a part of my assignment in this to help me explain a problem?
doesnt matter if its an assignment to us, as long as you're allowed to share whatever this is. though not many people would take time to read through an assignment so try to share just relevant information. ask according to the guidelines in the #854851968446365696 if you dont know what to ask
perfect thank you
i see you asked about this before in the general channel, ill continue this there since someone replied to you there too
my bad didnt see
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?
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
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
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/
don't think that makes sense for 10s of towers having to throw raycasts in all directions
especially not when I already know the position of all objects and can easily compare them?
Youd probably want to look at what other games do. Even if they're 2d youll still get some decent ideas. Maybe look at bloons tower defence 6. I believe it was made in unity
Yea raycasts arent ideal for this, if you wanted to check if any are within an area then youd probably use an overlap function. Honestly "10s of towers" is not gonna be an issue but you can
then profile it always
is it bad too do this?
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?
Depends. Inheritance on its own is not bad at all.
im trying multiplayer and in the gamehandler script i have a timer and in the playerhandler script i have a function that says if the tiemr = 0 and u still have the potato your out should that be fine?
why does the player need to inherit from GameHandler for that? just get a reference to it from the player component
this is all the gamehandler script is so far but if i were intending to inherit lots of variables from game handler should i just get a reference for each one
Think of your classes like real life objects. Do the 2 have anything in common? You wouldn't categorize a cat as a fruit, would you?
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.
let's say I can have up to 50-100 towers in my game at most and there can be like 100-200 enemies at most
if I have a EnemyTracker script that has a list of those 200 enemies, each of my towers can just compare their location to each of the enemies to get the distance not?
would raycasts really be more efficient?
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?
I use trigger colliders
And/or OverlapSphereAll
Well a raycast alone isnt comparable because it wont achieve the same thing. A overlap check would be a way of getting everything in range. Also if you need to check line of sight, then suddenly you need to raycast anyways
point to remember, it's probably not important for each tower to know the position of each enemy ON EVERY FRAME. So you can stagger the calculations across multiple frames to reduce the overhead
Ah im not sure there, maybe through a modding community? Theres tons of mods for the game.
I just listed it as an example since it's the only one I've played and its decently popular
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?
200 enemies and 100 towers is 20,000 calculations
is that too much? I have no idea lol
per frame? yes, that's a lot
"too much" is relative. If you can afford to spend 16ms on that calculation alone, it's probably not much.
Instead of getting all the enemies at once, get the enemies from a trigger or overlapsphere when in radius
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
something like ontriggerstay?
That would work or ontriggerenter
Could probably get the distance of each monster from one tower and simply check the offset of every other tower from that first tower before evaluating all of their distances from the other towers.
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
Doesnt bloons use a range based detection?
I dont really know what you mean by that. Any form of checking distance would be range based detection
When in radius => find enemies in range and do something
but how would I set up radiuses?
Scroll up, bawsi did talk about a neat system you could incorporate
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, ...
You can use triggers, overlapsphere, etc. Anything that has to do with finding something in a radius, best you look on docs
If you reduce the problem so it's not searching through a ton of objects each time this wont be an issue. You could even go as far as have each segment (the system I described above) store which is the lowest hp or whatever else
but I don't understand what you mean with segments
or at least not how to set it up
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
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?
You'd ideally use some overlap function once to know which segments are in range, and then search accordingly everytime you want to update the targeting.
but then isn't using a collider that has the tower's range exactly the same thing? or is collision checking expensive too?
You could try using colliders or physics queries only, and profile it. The performance most definitely wont be as pretty but 🤷♂️ if it works then that's good
so segments is probably the way to go?
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
I could make small segments and then assign each tower type how many segments far it should search 😮
It's how I'd start honestly, though it was also an idea partly randomly thrown together
This part sounds off though. just upon making the tower, you'd definitely wanna grab every segment in range. If you try to see how far down the line it should search, you might run into weird scenarios like it searching something which is always too far.
wouldn't the same be true for large segments? even more so?
Well you could still make them relatively small, but the point was more about grabbing all the ones in range rather than "how many segments far"
yeah that's pretty much what I meant, but probably a bit better
can u help me find why my 3d model faceplant and not move throw x axis ?
https://paste.ofcode.org/39muPfmreSEBXEmw5kcpFgr
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 ???
use a rigidbody
CharacterController is a 3d collider. do not use it for 2d
Did not know that
i know, but what i meant is should i use like rb.translate(), or rb.velocity, or rb.move() ...
Dont translate it or else it will ignore collisions
rb.Translate does not exist. and which method of moving the rigidbody you choose entirely depends on how you want your game to feel and behave. there is no "best"
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 😦
i want precise movement
and the project isn't based on physics
by physics i mean like angry birds or smth smiliar
Then use the velocity of it or use its add force function
ok thx
Translating the collider will only make it ignore collisions, best not do it that way
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
there are plenty of tutorials for moving a 2d object, you should consider finding one
okay
it's for a kinematic claw that needs to have physics interactions. how would the float method you describe look?
if it needs physics interactions then modifying its transform is definitely not the way to do it. you should be using a joint
ok, wasn't aware joints existed. Where should i start looking 😛

I'm using MoveTowards, seems really nice
.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?
Cause you are accessing the material directly and not an instance of it I guess
Material outlineShader = outlineIMG.material;
I thought .material creates an instance or am I wrong?
Can someone help me fix this issue I have been having with my project?
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.
Whenever I click spacebar my code does not run
!ask 👇 (pay particular attention to those last couple lines)
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
any clue why the material itself is being saved after play testing then?
if (outlineShader != null)
{
LeanTween.value(gameObject, outlineShader.GetFloat("_DisolveValue"), 1f, .5f)
.setOnUpdate((float value) =>
{
outlineShader.SetFloat("_DisolveValue", value);
});
}```
Im quite new and dont realy understand the full extent of my issue I have look across multiple forums and still cannot find an answer. Is there any way of creating a disccusion and there I can show my issue?
just to confirm outlineIMG is an object that inherits from Renderer, right? and isn't something like some other kind of component or scriptable object that just references a material asset?
I am asking in here but cannot send all my code over due to the limit on characters
!code 👇
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
this is also in the posting guidelines in #854851968446365696 that the previous bot message advised you to check
ight can I post the link here?
well its a UI.Image
im guessing the issue may be that images dont inherit from the renderer? not 100% sure tho. potentially might need to just use a sprite?
https://paste.ofcode.org/n3RjudCVEJB7GnvgUSArTs There are no errors on unity but still seems to not work
correct, UI.Image does not inherit from Renderer so that link i sent before does not apply. it probably is just a direct reference to the material asset
be more specific than "seems to not work"
noted, didnt know that
thanks for the help
you could always just instantiate the material yourself then assign the instantiated one to the image
I litteraly loaded up the software for the first time and think the issue is due to the spacebar part not outputing the information
mate i don't even know what isn't working because you've not bothered saying
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
huge brain<33
how can i use the unity cloud
this is a code channel
lol "does not complete the action" that's super specific. i'm not going to even look at your code until you actually describe what your issue is. i don't feel like digging around through the entire file until i find something that might be relevant to whatever it is you are afraid of saying
I litteraly have like minimal experiance with code and currently dont know how to formulate a responce due to lack of knowledge but idrk what is expected from a begginer channel
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.
So are you subscribing the callback to an action?
They are using old input system
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
should I update to the inputsystem and rewrite?
Your issue likely has nothing to do with the input system
does the old one not support callbacks?
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?
Nah, it is based on polling
is there any videos I could look up to wrap my head around these terminologies better?
Vector2 has a magnitude and sqrMagnitude which you can use
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
@hasty tundra so the value with smaller magnitude is closer to 0,0
Will it always be two objects?
yeah
ill have a play around with it, thanks 🙏
https://gdl.space/melewaxuci.cs is thewre a better way to have this code i know the movement and the animation arent right
Make it work first, then see if theres a better way. What issues does it have?
i have the wrong values on the walking tree but i know hot to fiks it
return(vector2.distance(position1, vector2.zero) > vector2.distances(position2, vector2.zero) ? position1 : position2;
Distance is overkill when comparing against zero, might as well use magntude/sqrMagnitude directly
If you haven't started already, you need to go through the !learn series
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
perfect thanks for the help (Been on here 3 times and your the first person to actual teach me something!)
return position1.sqrMagnitude < position2.sqrMagnitude ? position1 : position2;```
That’s also fair enough
how do i make a audio clip play with scripts
reference an audio source then assign a clip to it and use .Play or .PlayOneShot without assigning a clip
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.
how to get the measure texture
What's a measure texture?
It's on the asset store for free
Just search for prototype materials or something
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
use this to format your !code or use one of the sites to paste . . .
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
Thank you
So, there's this code, i was hoping to achieve this
however, what happens is:
it moves to spot X when i click it
it doesn't really follow the cursor, if that makes sense
GetMouseButton instead of GetMouseButtonDown to start with
check the unity docs. it has a description for both of the methods. they are slightly different . . .
Alright, thank you
something else, the way i understand it, my code should only ever affect the z axis of the cube
how can i make a e to interect npc
Input.GetKeyDown(KeyCode.E)
but i mean by a npc
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
Physics.CheckSphere
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
back to this
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
You can use local position or local rotation
can i get help to clean up my code
You're setting the object's Z position to the position of the mouse. This isn't a local/global thing
X and Y are unchanged, Z is going to the world position of the mouse
how would i go about getting the mouse position relative to the object itself?
post it and be judged . . .
!code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
You could use InverseTransformPoint to turn a world position into a position relative to an object, but I'm still not entirely sure that's what you're wanting.
https://docs.unity3d.com/ScriptReference/Transform.InverseTransformPoint.html
post it to the channel, not just to me. i'm working out, so not much time to help . . .
https://gdl.space/yadifepere.cs can anybody look at my code and help me clean it
also, you should clarify which part you want to fix (that is messy) . . .
okay i downloaded the visual studio how do i get the code there
everthing is messy i think but idk that
Follow the rest of the steps
What is the specific problem
It doesn't look that messy to me
what steps
In the guide that I linked
i think my code is really messy
but i am not sure
Then clean it up to your own liking. We aren't the ones who are going to be working with it so code that is formatted how we do it isn't going to be much help
You want your code to be "clean" as defined by the people actually working on it
but i thought it was really messy and i am not really good at this
Other people's coding styles are just going to make it less understandable
i cant find it
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
which of these
The one you're using
ohhh now i understand thanks
i thought maybe there is like a whole thing that could be done 1 line or something like that
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?
How are you moving the object?
im using transform.position and i use Vector3 for changing it
Teleportation does not care about collision
Is "walkingTree" controlling a blend tree in the animator?
yes
If you want your rigidbody to collide with things you need to move it by using the rigidbody
yeah i guessed that it changed the values regardless of collision, what can i do?
Thanks!
Can you show a screenshot of that blend tree
Either MovePosition, AddForce or setting the Velocity
As long as it's the rigidbody doing the movement, not the transform
you mean like this
Click the blend tree and show the inspector
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
oke thx my biggest conceure was it was to diffecult made
why has everybody a ! if i look to the right of my screen
they have a ! so you CAN look at them
its in alphabetical order
oo
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
of course its possible, theres many tutorials on youtube for it if you want
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
}
you need to make a if grounded, jump and if not grounded and air jump == 1, jump and do a -- / -1 when you do the air jump
why isnt it working
do you have a script or something called NPCinteract?
also the class name for this script is NewBehaviourScript which is most likely wrong
What is NPCinteract
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?
you do realize Start is run at the beginning of the game, PlayNextSentence is a custom method that will run whenever you run it?
usually your supposed to make a new one instead of changing Start to your own
https://www.youtube.com/watch?v=33XDR6E5W7g&list=PL6_cpWr0PK5w086Tm_9uyxky63xQWW6jU doesn't he rename it at 6:15?
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...
And then later on in the tutorial do they call it manually somewhere
yeah he does
do you have any errors in the console?
Yes, they do, roughly six seconds after they rename it
he does it under the public void PlayScene
i think?
Yes, and then right after that, you can see where they call PlayScene
No i don't
You should probably watch the whole thing
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
Yes and i also have that, so why wouldn't it work?
Show the inspector of your GameController object
um i need help
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
oh
no way you still did the same question thats not even a question 💀
Is that what you're looking for?
no
I'm sorry this is my first time asking for help 🥲
the actual instance of the component in the scene
this is just a preview window of the script file in your folder.
the one thats on a gameobject is always what counts
it's okay, he's trying to see your gameobject not the script.
I don't see him having a gameobject called GameController in the game
It doesn't have to be named that
it needs to have that component on it
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);
}
}
where's this script attched to
Oh let me look!
what wrong whit this
you should probably attach an actual question to your code..
we already responded to you, which you ignored
what is NPCInteract?
Namespace...
We already replied to this and you just said nothing
script
filename != class name
show it
it should be NPCinteract
how 💀
the code does not work
but it isn't
so you just solved your own issue
then i misspeld
what "doesnt work" mean ?
is there a question here
Ahh thank you i think i was too tired to notice it was missing, but everything works perfectly now!!
Change your class names. to NPCInteract. i saw that in your folder you have NPCInteract script i assume you renaming it.
Show the inspector for this object
give it more speed probably
i reanamed but i thought i would change automaticly
oh
horizontalMove * Time.fixedDeltaTime * runSpeed
also thats my first time seeing CharacterController moved in FixedUpdate 🤔
This should be working. You're moving it at 1 unit per second, assuming CharacterController2D is actually doing anything with the .Move function
making it 9999 wont do anything if the variable isnt used
Shi im confused
It's not a CharacterController, it's a CharacterController2D, a custom script
Ahhh yes I'm blind .
correct me if im wrong but i dont think when you change the script names on unity folder will automaticly change the class name itself. you need to changes both. except if you using jetbrains.
i used jetbrains for other things and that 1 automaticly changed but in unity not
so what should i do 😔
uh can you explain more
#💻┃code-beginner message
you have the answer here
already
You aren't using the variable RunSpeed anywhere
I literally copied everything from Brackeys tut
Show it
Show the tutorial
management wants you to find differences between these two
can i send links?
yes
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
····················································...
bot smacked you down w/ that meme lol
yes you arent using the variable here
omg ads on discord embeds
i dont have many brain cells
look. you have horizontalMove and runSpeed here. and the only variable being used is horizontalMove.
if you cant see you arent using the variable in that line of code, then yes you dont have many brain cells
I'm paying Brackys because OP couldn't copy it correct 😦
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
average brackys shenanigans
The last shot of the script in the tutorial is still wrong, he never fixes it
a+ production quality , d- code
Ah, right
it's not in the movement but in the input for some reason?
Strange choice
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
····················································...
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
from the video i posted earlier- i`m trying to move an object on it's local Z using the blue capsule as a handle
right now i'm only trying to move it along it's local z and use the blue capsule as a handle later on
shi
no memes
@fresh ferry do you know what you have to fix now ?
Then you probably don't want to set the object's position to the mouse, but instead get the mouse's movement and apply a speed on the transform.forward axis
You'll want to add to the object's position, not set it
nope
Go to the most recent link I sent, that's the timestamp in the video you missed
omg. Did you not look at the tutorial fully?
or read anything we said these past minutes
hey guys, i just wanted to ask a question. would charactercontroller work better for a stealth game or rigidbody?
I think that's the way to go, is there any proper way to get the mouse drag or do i just manually calculate a mouse delta?
irrelevant to the game style which controller you use.

i did not, im still at 13:19
like movement wise would character controller feel better for stealth or would rigidbody?
i can't understand shi tbh
There's Input.GetAxis("Mouse X") and Input.GetAxis("Mouse Y") which is the amount the mouse has moved in that direction this frame
i think character controller is used more often, Rigidbody is more for like movement type games
but you can use both and make it work
well copy it exactly and it should work. Or just put the speed variable there
Click on the link I sent. It's literally timestamped. It goes directly to the part of the video you missed
okie
both can feel the same, its just that Character Controller OR rigidbody kinematic is easier to code because you're not fighting the physics
welp, you made me more indecisive than i already i was 😭 but thanks. i'll see what's easier for me
idk but i do think both is same tho...
Character Controller is basically a kinematic rigidbody but with .Move collisions
Do you want to make movement easier or collision detection easier
but if i do that, it'll get the mouse axis on the screen, right? so if i move it 400 pixels to the right it should move the cube 400 units forward, which might not translate to the actual handle position
That's really it. You can do whatever with both
movement
then character controller
alright, thank you for your input
+1 c controller
You can make some sort of multiplier
like when you near NPC a popup will appear?
Canvas, either world space or screen space
if i click E then a text thing and i have the click e and it works
and if you near the click e to interact
add canvas. if you work with addictive scene then make the canvas overlay. if not then just use screen space camera
it means exactly what it says
It means all compiler errors have to be fixed before you can enter playmode
i dont understant like what is a addicitve scenen
why is it so complicated 
this. i seperate a game and ui.
It's not.
- You have errors
- You can't start the game with errors
So, fix them
i have this
Look at the errors and see what they are
lots of different disciplines involved , most of them require critical thinking or common sense
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
you have clear syntax issues in your IDE
line 17 of PlayerMovement has an error
Okay, now look at that line and see what's underlined in red
Then you have not configured your !ide to show errors
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
ight
i have thise
and
in this script, just instantiate/enable a game object that shows your Text
In this tutorial, you will learn: Teach how to put Anchor buttons to sides and adjust their width and height Teach how to put Anchor UI Text to the top-center of the Canvas and adjust the screen width How to use the anchor presets to lock UI elements to corners and sides of the UI menus Teach how to use the Canvas Scaler to automatically adjust...
thats good start, then you need to check does player really detect an NPC there? and also use
keep an object you can use for showing text, carry it /enable disable with player
when you finish that then create a canvas for it, and crreate a logic to make it happen
i'm trying to implement this but Visualstudio is getting transform.forward as a Vector3, and thus i can't add a float
but shouldn't transform.forward be a float in it self, since i'm only getting one item of a vec3?
vector3.forward is the same as Vector3(0, 0, 1)
(transform is just the local version of that)
it's not a float, magnitude is a float
dunno... 
but you can start with this
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
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
...
other thing that i dont want
dont feel discourage about other thing, just try it first step by step.
then don't use that thing and just use the things you do want
idk how to make that
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
...
i am using that turtorial
hey @deft grail can u check ur DM rq?
but i want a other text
Yes I know that's why I linked it again
then use other text
its not complex but it is if you just skip your way through learning anything
wait so the other thing you speak of, it jsut Text?
yes we know
"I want this" but doesnt go and learn it
he does something else
Text? like the FONT? or the UI Design? im confuse 
UI desing
Then don't do that part and do the parts you want instead
where is the "generate dialogue code and UI the way i want it" Button
but de turtorail uses de text bubble
okay?
so if you don't want a bubble
like you are texting
don't use a bubble
i dont know how to do it other wise
apply some creative thought, learn the tools and manipulate to your liking
the shape of the dialogue box is not a major factor in the tutorial
just... use a different shape
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
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
When you say "crashes", do you mean the entire Unity Editor crashes, or the game stops?
the game stops
So, it exits play mode?
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
like debug?
yes
does it actually exit playmode entirely or does it actually pause play mode?
in that case digi is likely 100% correct and something is calling ExitGame. you probably want to double check what your buttons do
uhm yeah but im kinda new into these and I dont really know how to check and fix it 😭
did you put in the log
then look at the button
specifically the play button and make sure it isn't set to call ExitGame
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
Change the text on a UI panel instead
what
Instead of creating an object with that text on it, change the text of an already existing gameobject
you mean the tmp
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
double click, right click, find all references
thanks
on mine I just have to single click on the variable and it highlights other references of that variable
only within that class tho
yes, but that will not find ALL references
oh?
oh ok makes sense
the code from the turtorial doesnt work
That is very rarely the case.
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
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?
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"
not sure.. but i did notice all those LookAt() functions inside the if statements are redundant.. since ur doing at the end of the function anyway.
so there's no need for them?
nope.. not the ones in the conditionals
you can just have moveCamera.y/x logic in there
what is the path from cancas for hide unhide code
yea everything seems to work fine just when i reach the top or bottom of the mars it starts spazzing out
canvas.SetActive(false);
is it a possibility to clamp the rotations before u reach those positions?
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
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?
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. 😕
why is this
you could create ur own shader that just plops a sun on top of ur image skyboxes
it'd be like combining the procedural one w/ a regular one
you are calling SetActive on a Component not a GameObject
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;
}
}
ya, what Steve said
how do i change
SetActive is for gameobjects
Do you get one of the logs?
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!");
}
}
yes the second one Debug.Log(NewPos);
Not entirely sure what you mean tbh. But this is my skybox. Haven't lined up the 'sun' yet, the one on there is part of the HDRI I'm using.
either canvas.gameObject.SetActive(false);
orr.. if u want to disable the component
its canvas.enabled = false;
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 😕
Log the value of Velocity, it might be too low for you to notice any movement
seems to be increasing tho
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
Huh? That ain't mine. lol.
Are you by chance using a CharacterController to move?
ye
lol mb
That's why, you cannot modify transform.position when the CC is active
The position changes and is immediately rolled back by the CC
Yes you do, but you need to streamline it into the part where you move:
Vector3 movement = // get mouse input or something
// other stuff...?
// apply gravity here!
movement += Vector3.down * -gravity;
cc.Move(movement);
never mind
oh i see, i will try this ty
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
how can i add a timer of 10 seconds
Raycast returns a bool so it's normal you don't have any options for that.
If you need to access the collider, use the overload of Raycast that allows you to specify a out RaycastHit parameter.
If you're using 2D, use Physics2D!
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;
}
}
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
its only doing the func once
im in 3d
i see thx
the RaycastHit is inside the out parameter
See https://docs.unity3d.com/ScriptReference/Physics.Raycast.html for more info on how to use the out parameter
(scroll down to the 2nd overload)
still looking for help on this
the main thing in update only runs twice
then stops working
then the raycast is returning false afterwards
Since you're struggling with C# syntax, I think it's better if you first learn it
oh ok ty works now