#💻┃code-beginner
1 messages · Page 37 of 1
ohh the public Rigidbody rb;
Rigidbody is the component, rbis the name you given it
So I want to drag gregg into that?
yes if it has a rigidbody
also, I tried this but it doesn't work
first check your Trigger is working. Put Debug.Log in there
I moved dragged Gregg from object into vs code and saved and it didnt do anything
The trigger is working because it's doing what it supposed to, except for the particle part
The Three Commandments of OnTriggerEnter:
- Thou Shalt have a 3D Collider on each object
- Thou Shalt tick
isTriggeron at least one of them - Thou Shalt have a 3D Rigidbody on at least one of them
...what?
any errors in the console ?
in the INSPECTOR
field in the inspector
YEAHHHH
we've said it like 5 times
probably because you have compiler errors
Hello, im programing in unity and I dont know if its possible to make by code that when a missile hits an object, the object break into pieces, I mean, the block is still there but it has less space
yeah but it is assigned??
An easy example are the bunkers from space invaders
it still says rb is not assigned but now my gregg is just randomly moving diagonal
when I start the code
Whatever Blixtrar was, it no longer exists
Swedish lol
If it still says it is not assigned, then there exists at least one script where it is not assigned
ofc its possible. make different sprite states per damage amount
yeah for some reason it just unassigns itself when I hit play
Because that script is for moving the character the collision needs its own script?
What did you drag into the slot? Is that object ever destroyed?
no?
what
why don't you start showing the current code
don't use screenshots and paste the link
It was group and not a single particle system. That's probably the issue right? Because now when I dragged in one of the particle systems it works
No idea what you were actually doing with Blixtrar so I can't answer that for sure
but if whatever you did fixed it that was probably the case
you copied the code from example 10, 0, 10);
this moves it diagonal
yeah
thanls
thanks
ohhhhhh
you have to put back your old direction you had @chrome wasp
with the variables?
Well, every frame you're setting the velocity to up-right, that would be why your character is moving up-right
just replace transform.translate to rb.velocity
all you had to do
direction stayed the same
ohhhhhhh
"The variable rb of Mover has not been assigned.
You probably need to assign the rb variable of the Mover script in the inspector"
So I assumer
I probably need to assign the rb variable of mover script
bruh
You have a Mover that has no rb assigned
in the inspector?
search inside the hierarchy t:Mover
And i only need to program that by Code i Guess, but
gregg came up
if thats the only one, then greg has Mover with no rb assigned
If i need that the barrier breaks in a specific point, because the bullets wont hit always at the same place
guys i could really use help, struggling with dictionary since morning and it doesnt work somehow
you probably use masks ontop of the hitpoint of bullet and lay that over the sprite
My boy Gregg has the component
i created dictionary in scriptable object.
in game manager script i want to generate new dictionary with data in it
and when i want to print in textmeshpro data from that dictionary it doesnt work
could somebody help me out?
is this the same object as Greg?
clear the console and hit play
are you sure that error is still there
yeah Gregg is the object I am trying to rb
if you're talking to me everytime I start the game I am flooded with more of that error
"doesn't work"
this doesn't help.
Start Debugging and giving more info wht that even means
Then you have a Mover script that does not have an rb assigned
so do I need to assign the script rb?
cause Gregg has it
and I'm trying to rb Gregg
For this Mover script, rb is Gregg's rigidbody
Its bad written , is it hammerSlag not hammreSlag?
You have another Mover script that has no rb assigned
That's the scene
How would i play a sound everytime the time changes, kind of like a clock tick?https://i.imgur.com/RnlYtTV.png
cause it doesnt have an inspector or anything
Can you screenshot Gregg's entire inspector
yeah just realized
(we don't need them expanded for what I'm pretty sure we're both expecting but there could be a different problem)
This will be several ss
make sure we see all the components there
thats fine
what exactly you need because right now you're not extracting info , you're just printing the text
its in backwards order but yeah
You have two Movers
and one of them has no rigidbody
You probably don't want two
computer never lies 😦
right click delete ?
iyeyee
delete it
got ti
ok the errors are gone
and the posistions are changing on the inspector
but i am not moving
and did you change the variables to direction
direection?
yeas
like do I get rid of movespeed and replace w3ith direction??
Show your current code
Direction was passed into velocity if I read that rollercoaster correctly
Direction would be the vector giving you the direction of movement. MoveSpeed should be a float you multiply the vector by to modify speed
ur move speed is 1
in the inspector
might wanna crank that up
show the gameobject selected, inside the scene
I screenshot gregg in scene?
ya
Might wanna remove the deltaTime from your velocity movement
Do
float xValue = Input.GetAxis("Horizontal") * moveSpeed;
Same with zValue
k
I think Time.deltaTime is fine for consistent move speed
o
no?
Velocity is meters per second, so it's already scaled by time. I thought you shouldn't do deltaTime with it
I dunno though
could be
should I try changing it?
ok i tried changing it
got this "Literal of type double cannot be implicitly converted to type 'float'; use an 'F' suffix to create a literal of this type"
changed it back
annd that is still there
decimal numbers need an f at the end to be floats
you can't write 0.3 you need 0.3f for example in a float field
fixed it
ye
OK SO GOOD NEWS
he moves
only diagonally
i am stupid
i fixed it
IT WORKS
OMG THANK YOU SO MUCH GUYS
EEEEEEE

I am very sorry I put you through that lol
🥳
BUT YES IT WORKS SO WELL!!!!
hmmweird iirc time.delta time is fine on inputs but it was just to low of a value, I have to use * 10 when I do it on inputs to get consistent speed.
But I don't do it on the rigidbody itself
23 * 0.05 (how much is time.delta time again?) s about 1.15
@summer stump
One thing to keep in mind that people sometimes dislike:
GetAxis has smoothing.
It will go from 1 to 0 to -1 smoothly, with the decimals between. This can make the player feel "floaty"
If you don't want that "on ice" feeling, use GetAxisRaw, which ONLY return -1, 0, 1 for the values. It snaps to them immediately
But that is for you to test and feel
ah yes I was just testing it and noticed that
hmmmm I think I like the smoothing a bit more
but one more thing
Whenever I manage to flip myself I like float back down
its like there is gravity but it is SO SLOW
you're overriding gravity
because of .velocity
you need to add .y to the direction
this is a code question how?
what where do i put .y
inside the velocity
Where you currently have a 0
ohhhh
Change that to rb.velocity.y
!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.
working much better is there any way to increase gravity
its in Edit somewhere
Okay, please don't shout at me but I'm very confused as to what's happening with this little script.
[SerializeField] Transform referenceObject;
[SerializeField] Transform solarPanels;
// Update is called once per frame
void Update()
{
transform.rotation = Quaternion.Euler(0, referenceObject.rotation.y, 0);
solarPanels.rotation = Quaternion.Euler(referenceObject.rotation.x, 0, 0);
}
I have an empty which is always pointing at the sun. I'm using that to grab the rotation values and applying them to my solar panel 'post' and the actual panels. I'm very confused, because the rotation on the post works great, but on the panels they don't move.
Does anyone know why when it's pretty much the exact same code please?
ty
how do i increase the radius of the character controller
transform.rotation is a Quaternion, these x and y values aren't euler angles
.rotation does not contain angles in degrees. Use .eulerAngles
^
Quaternions store a rotation on 4 axes (x, y, z, w) with each value ranging from -1 to 1
the prop that says radius
i tried this
characterController.radius += radiusIncreaseAmount;
uhuh
Yeah tbh I knew that about Quaternians. Was just very very confused as to why it worked for one, but not the other. lol.
public float radiusIncreaseAmount = 0.1f;
private CharacterController characterController;
and this for the variables
so whats the problem?
it doesnt work
where do you assign character controller @amber spruce
and how you know it doesn't work
You're lucky it even works for one of the two here
would it show the value changing in the inspector
Well just trying changing to EulerAngles, but VS started shouting at me to use Euler. lol.
it would if you referenced the correct cc
I mean referenceObject.eulerAngles.y
i dont think i was assinging the right one lol since i made it private i never dragged in my character controller
Whats best way to learn basic scripts? Is it official Documentation? For example PauseGame standart scripts like stop time exit game or load level?
how do i get this to work
radiusIncreaseAmount = Vector3.one * 0.1f;
Error CS0029 Cannot implicitly convert type 'UnityEngine.Vector3' to 'float' Assembly-CSharp C:\Users\vinny\My first game\Assets\movement\CrushObjects.cs 84 Active```
thats what i get
A radius is a single number
radiusIncreaseAmount is a float btw
Multiplying a vector by a number gives you a vector, scaled by that number.
yes thats why its giving u error
how do i set my players radius to Vector3.one * 0.1
cause thats what i set the players scale to
and right now the scale and radius arent the same
why Vector3.one ?
because thats how i get my scale to work how i want it
i dont really remember why i did Vector3.one lol
you're trying to squeeze 3 numbers in 1
did that over a week ago and i ahve a terrible memory
it works for the scale
transform.localScale += Vector3.one * 0.1f;
so how would i increase my radius by the same amount
because just increasing it by .1 doesnt work
thats the same as doing 1 * 0.1 3 times (0.1, 0.1, 0.1)
why not
idk the collider is way to big
so make the value smaller?
so can i just set it to .001
ik but to get it to the exact right number is gonna be hard
i want the collider to be the same size as the model thing
so use the scale magnitude of the object or something
hard to say idk what ur situation looks like
well if i set it to the exact scale then its wrong
scale.magnitude * sumnumber
hard to do it by scale alone but you're not giving much to on 🤷♂️ lol
oh you wanted it bigger
yeah my game is about eating all the objects to get bigger
you eat them by colliding with them
although it seems to already increase it with the size so not sure why its not working right
i wonder if its because its a circle
should i be using like a box collider or smth
because when you get big enough it gets really hard to eat small objects
Does anyone mind helping me getting a button on my scene to work? I have read a lot of tutorial articles and watched a lot of videos and I'm not sure why it's not working. I'm working in a 2D setting
#📲┃ui-ux if you mean a UI button
Do you have
- EventSystem in your scene?
- Graphic Raycaster on your canvas?
eventSystem yes graphic raycaster no. What does the graphic raycaster do?
makes elements on the canvas clickable
how do i have the character controller use a box collider
!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 don't, character controllers are capsule-shaped
dang
Okay, well I'm losing the will to live. lol.
Sorry, I know this should be really simple stuff but I just seriously don't understand what's going on.
[SerializeField] Transform referenceObject;
[SerializeField] Transform solarPanels;
// Update is called once per frame
void Update()
{
transform.localRotation = Quaternion.Euler(0, referenceObject.eulerAngles.y, 0);
solarPanels.rotation = Quaternion.Euler(referenceObject.eulerAngles.x + 90f, 0, 0);
}
Everything is pretty much working as it should be except for the Z axis on the Solar Panel Rotation, it should stay at its local 0, but it just doesn't. I've tried setting the solarPanels to localrotation, but if I do that, then nothing works. The 'pole' object works perfectly though.
Actually, scratch that, sorry, the pole item isn't working, it doesn't rotate on the y as it should when set to local
try the LookAt function
you want the items to look at a reference object or have the same rotation as the reference?
what is this code supposed to be doing?
Same rotation as the reference. The reference is using LookAt to look at the sun, the solar panels are split into two object, one that 'spins' around it's Y axis, and the actual panels that spin around their X axis.
Also using isolated euler angles from a transform like that is usually not going to work well
Trying to get these panels to always point at the sun object I have in the scene.
OH!!! I just figured it out. lol.
[SerializeField] Transform referenceObject;
[SerializeField] Transform solarPanels;
// Update is called once per frame
void Update()
{
transform.localRotation = Quaternion.Euler(0f, referenceObject.localEulerAngles.y, 0f);
solarPanels.localRotation = Quaternion.Euler(referenceObject.localEulerAngles.x + 90f, 0f, 0f);
}
Needed to grab the localEulerAngles from the reference object.
so how would i fix collisions being messed up
when you get big enough the only way to colide with stuff is by the very bottom touching it which isnt very big of a area
while you increase radius you have to increase height
that doesnt work because now i just fall through the map
nvm then...probably because center needs to be moved when you mess with height..
and its still only that little bit that hits the ground
oh so you don't want the capsule shape ?
no because it messes with collisions
then don't use CC
dont i have to make a custom one for movement then
or no
does that deal with movement?
ok thanks
what does "mess with collision" mean just curious
like its hard to actually collide with smaller objects
if your big enough it becomes impossible
you could potentially have two colliders
a box at the bottom or something
it wont sync up with cc tho
if you have the possiblity, make all objects you want to eat collider very high so it is easyily touched by the cylinder part
for your game you could even use 2d collision and just make the visuals 3d
Hello guys, anyone can help me with a question, i have a UI Image in my game and i want to make a glow effect behind it from a color that variate depending on the rarity.
What is the best practice to replicate that in unity?
Image as example attached.
yeah but then wont it mess with the position wont the player be on top of them
not if you destroy them on touch
Look for (2d) outline shaders
Is there a way to explode a throwable when it lands on the floor?
I am supposed to do it in a method with no parameters allowed
Destroy it on collision enter and play a particle effect
rn im using a mesh collider should i use smth else
Depending on the shape of the object box collider is the easiest
is there a way to have the box collider auto size to it
because i have tons of objects
depending on how detailed it needs to be just roughly estimate the shapes with cylinders, box colliders and so on
Like this u mean?
i think box colliders auto size to a mesh if you put it on them
I think theres some with better functionality online
That is what I wanted to do but I am supposed to do it in a method they have given me with no parameters so... Idk
yeah but now i cant change the size for them all at once sad
I dont get what you mean
If you change the object directly the colliders will scale with it
Is it possible to pass in a script to another script without using the scripts name as its variable type?
Instead of doing "public jumpController playerJumpController" is it possible to have a generic script type or something like that?
I'm trying to build a framework for the generation of magic spells modeled after D&D 5e's spells via scriptable objects where you can simply drag in a
procreated spell functionality in a provided script or create your own script to use for its mechanics.
Create a parent interface for all scripts you want to assign
You should have a shared type that all the spells have in common and make the variable of that type
Hi im having a problem with null reference exceptions for some gameobjects that are reference in a list that are assigned in the inspector and it is only these object sand even if they arent in a list the same issue is happening the relevent code is ```cs private void RPMLightsMovement() //controlls which light should be on
{
rpm = controller.RPM;
float closest = GetRPMClosest(rpm);
RPMLightsDict[closest].On();
List<float> ramaingVals = new List<float>();
foreach (float val in RPMLightsVals)
{
if (val > closest)
{
ramaingVals.Add(val);
}
}
foreach (float val in ramaingVals)
{
RPMLightsDict[val].Off();
}
}
private void PopSliderVals(float mRPM) //uses maths to work out a value at which each light should be used and then adds that as a key and the game object as a value in a dictionary
{
float interval = (0 - mRPM) / (RPMLights.Count - 1);
for (int i = 0; i < RPMLights.Count; i++)
{
RPMLightsVals.Add(mRPM + (i * interval));
}
RPMLightsVals.Reverse();
for (int i = 0; i < RPMLights.Count; i++)
{
RPMLightsDict.Add(RPMLightsVals[i], RPMLights[i]);
}
}
Any help is apreciated
What line is the error
line 5 RPMLightsDict[closest].On() and line 29 RPMLightsDict.Add(RPMLightsVals[i], RPMLights[i]) its whenever i access the gameobject or the script i have attatch to said gameobject to try and fix this error
RPMLightsDict not initialised?
For the first: Either RPMLightsDict is null, or RPMLightsDict[closest] is null
Second: Either RPMLightsDict, RPMLightsVals, RPMLights, RPMLightsVals[i], or RPMLights[i] is null
Try logging some values to see which one it is
so the error is first triggered with line 29 and then the line 5 error is triggered every frame after start as it is called every frame so it is not reading the objects even though they are assigned
So, if the line 29 one is first, let me ammend:
For the first: Either RPMLightsDict, RPMLightsVals, RPMLights, RPMLightsVals[i], or RPMLights[i] is null
Second: Either RPMLightsDict is null, or RPMLightsDict[closest] is null
Did you verify if they are null?
so i know that the RPMLightsVals is not null as that work when i was using a slider and the RPMLights reading null causes the dict to be null
Instead of guessing, check
Log some values, find out which is null
Hello I am having a bit of trouble with my coroutine so, when I have choices canContinue is false I want to be able to select my choices then continue with the first bit of code
while(story.canContinue)
{
var currentLine = story.Continue();
AudioManager.i.PlaySfx(AudioId.UISelect);
yield return TypeDialog(currentLine);
yield return new WaitUntil(() => Input.GetKeyDown(KeyCode.Z) || Input.touchCount > 0);
}
if (story.currentChoices.Count != 0)
{
yield return choiceBox.ShowDialogChoices(story, onChoiceSelected);
}
no i havent got verification currently as even if they are i have tried assigning them through code and it still doesnt work so i have no way to rectifiy it even if it does chatch it
Then you would probably need to start a new coroutine. Once canContinue is false, the while loop ends
You'd verify it at runtime. And if they are null, determine why or how to make them not null.
Before you attempt any sort of debugging or problem solving, find out what the problem is
I can't really debug for you because the project is in front of you and not me.
Either log the values or step through with the debugger to find out what is null
Ah thats frustrating I know the purpose of the coroutine is that it executes in order but is there no way for me to say oop go back?
Start another one
Ok thanks for your help ill do it like this then
Hey I've made a grappling hook in my game. So I can shoot it and it enables a SpringJoint2D between my player and the grapple head.
As you can see in the video it does really unnatural movements. It looks like the Spring tries to pull the player towards the right or the left of itself and not in the direction of the player.
so i have added this statement to debug Debug.Log(string.Concat("Light ", i, " reading ", RPMLights[i].gameObject.name)); which when i run it it shows that the light is there and the name is correct however after the first ittereation in the for loop the null reference error is thrown maybe the update function is called while the dict is getting populated so it cant find the light but if that is the case i didnt think update got called before start had finished
Doesn't look related to code. Try #💻┃unity-talk
@rich adder u have nice tutorials
These are the things that can be null on your lines.
#💻┃code-beginner message
Log them, in that order, in separate logs, before the lines that throw the errors.
Find the one that is blank, or the last one before an error occurs
and see which variable is null
Just log before the error line to see what's null - simple as that. If there's some confusion about how to properly log, you may want to ask.
okay will do
guys for some reason i cant fill my dictionary from loop. i tried lots of stuff. only if i add pair manually it worked. can somebody help me out why code above doesnt work? the line that i highlited code somehow doesnt reach it otherwise i would get pairs created in dictionary
Log to see if it has reached it.
how to do that 🙂
use Debug.Log
Debug log should literally have been the first line of code you ever wrote
oh right i forgot about that
ty guys
ill test it now
since morning trying to figure out why it doesnt work 
The assumption was that it doesn't reach that line of code. Verify it.
So maybe tile game object is always null
Or none of these statements are ever processed.
So i figured out what it was so the lights werent null nore were the vals it was the dict as i had no instantiation only just decleration of the veriable so it was adding to a dict that didnt exist thanks for your help
no some are bcs i used log thingy above to check if loops is running and it did
Well then https://docs.unity3d.com/ScriptReference/Tilemaps.Tilemap.GetInstantiatedObject.html we're to assume that there aren't any objects at said position.
yeah but tilemap is filled with tiles 
That wasn't what the line of code saw/thought/said.
yep
hmmm good point
but i tried for 0 0 0 and tile on that spot still didnt get result i wanted (when i open it some stuff should happen confirming that tile has data assigned to it via dictionary)
wdym?
i have a tile on map with coordinates 0 0 0 and even on that one dictionary hasnt created pair (data for it for that position)
i think that no mater what cell position i am passing at least that one should work since world position and cell position match there or i am thinking wrong

what you see in the inspector is not neceserraily the 00 for tilemap
tilemap i think starts from bottom left of the screen
grid has its own system
hmm idk i used TMP in canvas to display coordinates on clicked tile and 0 0 0 is in center of my tilemap
how do you know u hit the tilemap ?
If I have multiple weapons how do I keep track of which kind I have equipped so I know which animations to play?
with a variable
currentlyEquippedWeapon
right but should I just be like constantly checking for what object I have equipped or is there a more efficient way to do that?
are you using world to cell ?
Yellow is mouse click, Pink is WorldToCell yellow pos
Gizmos.color = Color.yellow;
Gizmos.DrawSphere(mouseClick, 0.23f);
Gizmos.color = Color.magenta;
Gizmos.DrawSphere(grid.WorldToCell(mouseClick), 0.13f);```
i see what you mean and its possible solution but i dont know how to rewrite that line so i get gameobjects back instead of null
this is returning null somehow
tested with debug.log and that is the problem that line. just dont know how to fix it
I think this only gets the GameObject that a tile might have spawned
ok go on
not 100% never used that function
ok how to get game object from that position?
I think its because tiles , technically arent gameobject
just a data representation of something there with a sprite
hmm but when u make them on map they show as separate game objects
i thought it was for this
i see
doc mentions only Scriptable Tiles 🤷♂️ i guess it has to do with that
aight ty bud. trying different aproach now if that doesnt work then i have to think of something else.
good thing is we know what line is issue
maybe try getting the tile and do .gameObject ?
or I think this is the same thing
https://docs.unity3d.com/ScriptReference/Tilemaps.Tile-gameObject.html
the doc doesn't clarify
what do you need to do specifically with the tiles/gameobject
i want to extract tile tag
thats the main and only purpose
tile tag/ game object tag
so this isn't a tilemap object
dammit im back again
I get it
Jesus how long have you been helping
tag Water
then why does code above not work 
because its not part of the tilemap?
bruh its literally null
hence ur if statement not hitting
there is no error if u dont try to use something null
just get it how you would get any other gameobject
how do i fix that to get god damn tag bro 
i cant think anymore been struggling with this since morning
how do you want to get object? with a raycast ?
yeah
collider.gameObject.tag
jesus i think i know what u mean
my gravity is weird and idk how to fix it
navarone u are boss
its like no matter what I put it at I still fall slow
fr navarone helped me so much earlier
show current script
did you fix ?
i am speechless.
working on it now but 99% sure i know what u mean
I was editing it in project settings but I googled it and put in some code, I'll send the code
what happen to the :OhNo emoji..
Last two lines
this is hella wrong
yValue
this is supposed to be your rigidbody.velocity.y
or a multiplied version f it
also gravity x ?
now i cannot jump
forgot how to do jump with .velocity but you have to add onto the current value
then pass that inside Y
what where when am i adding onto w
"So firstly he’s already got a Y velocity that you are just overwriting 🙂 Hence the weirdness… You could add something to his velocity: rigidbody.velocity = rigidbody.velocity + Vector3.up * 2; Or you are probably better adding a force: rigidbody.AddForce(0,10,0); Bear in mind that rigidbodies…" found that in google
rigidbody.velocity = rigidbody.velocity + Vector3.up * 2;
Can I use that
are you reading this https://gamedevbeginner.com/how-to-jump-in-unity-with-or-without-physics/
or is that unity answer
its a unity answer
Hello, I’m trying to get my character to jump by changing the velocity along the y axis. I’m making a simple snowboard/skiing game so the character slides down a hill and the velocity keeps going down as well. I’m able to get him to jump a little when he’s going slow down the hill, then as he speeds up he jumps higher and higher. And then when h...
error
"'Component' does not contain a definition for 'velocity' and no accessible extension method 'velocity' accepting a first argument of type 'Component' could be found (are you missing a using directive or an assembly reference?)"
so my code
doesnt know what velocity is?
your reference is rb based on your original post
told you this error alone doesnt say anything
show the line u changed
I added the if statement
you want rb.velocity += Vector3.up * 2
wowahahhh
ok that did SOMETHING
my guy just kinda
flew
because ur constantly adding
to itself
think you need to do in some sort of button press
btw how do i do that
with the grey
surround it with the backtick `
along with this
Yes, and you'll also need a ground check so that you can't keep pressing jump while in the air. That part is a little bit more complicated
that was going to be my next quetion but ima take this one step at a time
how can i determine the material of the face a physics.checksphere hit?
if (Input.GetButtonDown ("Jump")) { rb.velocity += Vector3.up * 2; }
I have added that code
and there are no errors but I cannot jump
you could always try addforce
would the code I wrote out work in theory? Like did I use an if statement right?
where do i plonk it in
I don't think it's the velocity assignment. Your button press looks wrong, but I'm not sure if you're doing a controller input or something that I"m not used to?
Mine usually looks like Input.GetKeyDown(KeyCode.Space)
something like
rb.AddForce(Vector3.up * 2, ForceMode.Impulse);
you can also try swap out your getbuttondown for a getkey then use keycode.space or something just to test the input detection
addforce doesnt work when u use.velocity
hm ok
show current script recent
Yea, AddForce and velocity are different ways to move
So for the alternate option I could just sawp getbuttondown for getkey? And then google how to use keycode space?
it would just be
Input.GetKey(Keycode.Space)
oh okay
you could consider adding in a debug.log to see if the button is even registering
or input.getkeydown if you only want it to enable for 1 frame after clicking
Well as far as I know, GetButton is usually for controllers

Debug.log ("some message")
add it in the if statement
and then test jump to see if message prints
in console
if (Input.GetKeyDown(KeyCode.Space))
{
var vel = rb.velocity;
vel.y += 10;
rb.velocity = vel;
}```
try this
I THINK IT WORKS
why is it that sometimes if i go high enough up I just fall through my plane?
nice
ty bro, legit 8 hours sturggling with this stuff
try turning the collision to continious mode

saying instance on set to object on line 22
for the 1st code
Fixed!!
Okay final issue
I can just double jump infinite times
lol
you need a grounded check
Suggestions on the best way to have an enemy ai detect the edge of a platform, reverse direction, collide with an opposite wall and reverse again? (Basically just like 3-4 different collision checks?)
eg Physics.Raycast or Physics.Spherecasst etc.
oh speaking of which
maybe raycasts
BoxCast has been my go to way for ground checks recently
any tutorial that shows grounded check will show
k
So I've got a raycast that I've set to originate from the front edge and point down, which seems to be handling the "edge of platform" scenario, but I'm having trouble getting the raycast to flip sides when the sprite flips. I don't know if I need to set up like 4 different ray casts to detect in every direction basically?
Yea, this is definitely something you should do some google research on. Raycasts are super easy once you understand them and hugely useful. Worth learning for any project
ohh you only flipsprites and not rotate player itself ? i suppose in that case u would need then ray for all directions
Well I mean right now the sprite is just the default square that I reverse the localScale.x for
topdown or side view?
Side
I tend to rotate object on the Y axis
I'm gonna go learn c# then come back to this
or at least the basics
get an understanding of it
That's a good start
I'm trying to learn how to use the new input system and so I was changing a bit of my code.
What's the ideal method for moving the player character?
I was using transform.Translate originally but the movement is odd since it just stops completely when I let go of a button, instead of slowing down in a more realistic way, but then somewhere I think someone mentioned to try using AddForce. But now my character just falls over on the spot when I press a key instead.
yea, I think that was my next attempt
hey how can i make 2 gameobjects the exact same, like to have the hotbar slots in my inventory change with the ones on the screen?
and what would it be called btw
You need to check the constrains on your rigid body if it's falling over with force
This is for 2D obviously, but just check the appropriate freeze rotations and it shouldn't fall over
Yeah it's 3d that I'm working with. Now that I've frozen rotation, I can see that he doesn't actually move at all when I push a key, so just trying to figure out what's going on
!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.
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
private PlayerInput playerInput;
private InputAction jumpAction;
private Rigidbody rb;
// Speed of the player
public float speed = 5.0f;
// Jump force of the player
public float jumpPower = 5.0f;
[SerializeField] Transform groundCheck;
[SerializeField] LayerMask ground;
// Start is called before the first frame update
void Awake()
{
playerInput = GetComponent<PlayerInput>();
jumpAction = playerInput.actions["Jump"];
jumpAction.ReadValue<float>();
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
// Get the horizontal and vertical axis values.
float horizontal = playerInput.actions["Movement"].ReadValue<Vector2>().x;
float vertical = playerInput.actions["Movement"].ReadValue<Vector2>().y;
// Move the character based on the axis values.
rb.AddForce(Vector3.forward * vertical * speed * Time.deltaTime);
rb.AddForce(Vector3.right * horizontal * speed * Time.deltaTime);
// Jump if the player is grounded and the jump button is pressed.
if (jumpAction.triggered && Grounded())
{
rb.AddForce(Vector3.up * jumpPower, ForceMode.Impulse);
}
}
bool Grounded()
{
return Physics.CheckSphere(groundCheck.position, .1f, ground);
}
}
Modify your force values, 5 might not be enough if that's what you were using with translate? They're 2 very different systems
Dont mulitply rigidbody with Time.delta time
Sure I'll give that a try
Just to check then, is AddForce actually the generally recommended way for having movement on a character?
And the other thing I was meaning to ask is, is locking the rotation not a proper fix for this? As I figured it is gonna cause a problem for me when I want the character to turn while running if holding W & D for instance
I'm brand new to Unity so sorry if it's a stupid questions
Oh yup, I missed that. You don't want delta time when adding force or velocity
If you want very physics based movement - yes, otherwise you can use MovePosition
It generally behaves a bit different and you will have different problems with each of them that you need to solve, but its not a question about what should you do, but more about what you want to do
Theres 2 types of movement, rigidbody and just moving the transform. Rigidbody is useful if you want it to respect physics and react appropriately to getting hit for example. It is also extremely tedious to get one to move exactly how you want in comparison to moving the transform.
Moving the transform is much more tedious in getting it to not go through walls
MovePosition on a kinematic rb is also the same as just moving the transform position. It just does extra stuff like give it a velocity during the move
You don't want to lock ALL the rotations. Just the axis that makes them fall over. Y axis should still be unlocked so you can rotate in place
Yeah it's definitely more useful physics wise as I just want to make a sort of platformer at the moment with large objects etc that swing and knock you off etc
You can still rotate it by locking all axis. That locking only stops it from rotating due to physics
But it can also cause somewhat weird interactions. You can see this by locking position and throwing an object at it
Instead of locking all rotations, you could constantly apply torque to get it towards the rotation you want
Someone please help me. In my scene, I have an array of players gathered by using FindObjectsWithTag("Player"). I want each player in my scene to have a unique number (1-8). I've tried accomplishing this via lists and dictionaries, but whenever I do, I get the error "index is out of bounds". Is there a better way to go about doing this?
tl;dr I want to create a list of player objects each with a unique number attached to them (1-8).
I have a question about coding. I was told that the code is different for 2D projects and 3D. But how much different? Even the movement? Is there any place where i can read about code for 2D? (2D Similar to Enter the Gungeon, Dont starve or games like this?)
Add debugs like how large the array is. You are trying to access an element that doesnt exist.
Hmm I see
It's a lot to wrap my head around. I tried using the "Starter Assets - Third Person Character Controller" asset recently, that's actually exactly what I want as the character moves, rotates and such in a proper way.
My goal is to get to that point atm, but I want to try to do it myself and learn rather then import theirs
I mean it's different in the sense that you're working mostly in Vector2 vs Vector3, and for physics and colliders most of the 2D stuff is appended as 2D, like BoxCollider2D
Physics is different in 2D and 3D, and that's basically it
As bawsi said, and you were told yesterday, debug it.
The data structure you use is irrelevant to this issue.
Doesn't matter if it's an array, list, or whatever.
Debug.Log?
Oops... Lol
Is just that? A physics thing? do you guys think 2D is easier than 3D? (Again .I mean games like Cult of the lamb, dont starve, etc) the only thing i can think of is when i used to use GameMaker or similar for 2D games and i would just put invisible blocks for not getting out of bounds.
I find 2D harder because the assets are harder to work without an artist
I have something like that. I have the number of players in the scene in an integer variable, and it displays in the log the number of players in the scene. But it doesn't keep track of each individual player, just the number of players.
the code is exactly the same mostly @formal escarp
Do you guys have any link i can read talking about how to start stuff like a bullet hell? i hope i am not being annoying.
the logic all that is the same
It really doesn't matter much
I mean both are suitable for different things. It depends on what you want to do. Some ideas will be easier in 2D some harder
Well. I care about making it work. For example, for college we had to give today a 3D thingy where character should be able to jump, use raycast to kill enemies, make stuff move etc. but the visuals did not matter so eveything was a cube or spheres. Can you do the same tho right? For 2D.
Bullet hell game.
btw i failed my exam today. I spent all week coding but before we gave that to teacher we had to take a exam and i got 8/15. and you needed 9/15. so teacher wont even look at my prototype of game. 💀
If you really do not care if its 2 or 3d, a 2d game saves you a lot of trouble in different scenarios
I suppose you can use placehooler srpites sure
3D is just easier to work with esp if you're not particularly good at drawing
I don't reeally think it's the genre that matters, but what specifically you're trying to accomplish.
I mainly care about mechanics working.
sculpt tool actually pretty easy to use in blender, but for the life of me I can't draw 2D
Do you debug the data structure itself? Like the number of items in it, the length or count (are you using a list or array right now)?
There's assets for everything. I'm a horrible artist, I use place holders for basically everything. I just like making mechanical projects. Lol
Just a prototype. like, being able to move enemies shooting stuff at you, etc. something simple so i can start from scratch.
in 2D sucks, when you want to add sprites from asset pack they look completely different from another asset pack
3D more or less has 2 style
sylized/Lowpoly and Realisitic
No thats absolutely not true, different 3d packs can look horrible together even if in the same style
That's going to happen if you're using assets from differnet packs in 3d too though.
btw im a bit sad i failed the exam man. i was 1 question away from going thru.
wake up call to study more
Perspective, attention to detail, scale of details to each other, topography, all of them can ruin the look
yeah I mean art direction is everything, but just saying 3D is easier to blend together than 2D
can anyone help me with an issue im having in unity?
im going to take my face off.
Yea, like I said i"m not an artist, but I'd much rather work on 2D assets then 3d. Lol
beat me to it
but at least now i know some of the basics. how to move, raycast and how it works, how to make jump and platafforms move, etc.
take one thing at a time
i think its a great start. a month ago i did not know how to anything of this.
well i cant really explain the problem thats the issue
I know how to do that on 3D tho.
We can't help if you can't tell us what's wrong. Lol
anyways. thanks guys. ill go and try to find anything that i can read that it tells me how to start bullet hell 2D.
if you can't explain it you won't ever solve it 🙂
i have small issue cant figure out why. Using function to convert cell to world position and one coordinate is converting properly but other isnt. z is converting good but x isnt.
how can we help to something you cannot explain @eternal sage
Too high level. Think of it in smaller pieces. Don't think "how to make a bullet hell" think about what are the core mechanics that make up a bullet hell and start learning each of them individually
method that is converting cell to world position. not sure how one is converting properly but other isnt
why are u still using tilemap function lol you dont have a tilemap
Like, how characters shoot at the CURRENT position of the player for example but to make the bullet not follow them? but rather detect "oh. player on X25 Y30 Z8 i shoot that position"? i think you are right. i learn mechanics.
You forgot a semicolon on line 17
just to convert its position to world, because i need to pair cell position with object data and for object data and its access via ray i need world position 
and how to move i guess. i am not even sure if the code of moving on 3D and 2D is the same but im guessing no because of the Vectors as previously said.
Exactly, that's 1 small piece you can work on, but it is a big mechanic of a bullet hell. Figuring that out will help you with a lot of the other pieces as well
Tilemap.GetCellCenterWorld will get you the tile at that position of a tilemap. Do you have a tilemap you are trying to get the grid position of
well im new to programming and unity altogether, and im trying to make something duplicate. Im only trying to make it clone once but it does it untill my unity crashes.
okie dokie. i think i should start with the easier mechanics first so i can learn, test, learn, test, learn test. thanks
yes bud @polar acorn and its x minimum is -14 cell position and world position of that tile is -14.something and when converting i am getting -11.something or -12.something
Sounds like you've just got it in a loop with no way out (exit condition). I'm assuming you have it in the Update method then
Does the object you are cloning contain the code that clones the object
I have a plain-old C# class that I want to be able to log an error from. I want to log something that helps me find the offending class (it's always going to be serialized on a component somewhere).
Any idea how I can do that? Obviously I can't just log this, 'cos this thing isn't a unity object.
Perhaps I should just hand it a reference to the component it's a part of.
Ohhh, or that... I alwys forget that one. Haha
can you show the inspector of your tilemap
And it's populated, right? You've got tiles in all the positions you're expecting to get?
yeah its populated but u did point me out one thing that could be issue for something else, tho it still doesnt explain why vallue is not matching for one axis but is for other
hello, I'm struggling to figure out why my code is having an issue passing a gameObject reference from one script to the other.
The currentCar gameObject is initially set as the cars driver door but I assign it as the actual parent car gameObject with the transform.parent.parent... code.
the log statement shows it's the instantiated prefab gameObject, but for some reason my code is having an issue passing it to another script that needs the reference.
// CarRadialMenuManager Script
private void SendCarToMechanic()
{
currentCar.GetComponent<DriveCar>().ExitVehicle();
currentCar = currentCar.gameObject.transform.parent.parent.parent.parent.gameObject;
Debug.Log("currentCar = " + currentCar);
// this line below is giving the NullReferenceException
mechanicController.AddCarToList(currentCar);
}
//MechanicController script
public void AddCarToList(GameObject car)
{
carList.Add(car);
}
i figured the issue. ty for pointing some stuff out it indirectly helped
mechanicController.AddCarToList(currentCar);
mechanicController is null
oh wow, you're right I forgot to assign the reference in the inspector 🙃
after 10 hours i completely fixed my problems
ty all that helped
gn
apsolute gigachad
@ navarone
huh what was it ?
https://gdl.space/hequxatoqa.cs
So I have this script that uses animation key events to run most of the methods and I'm planning on adding a bunch of other spells other than fireball, but I want to know if I'm doing something like super wrong and it'll bite me in the ass later on
keep track of the weapon/spell type in script , then you could only ever need 1 method to call to fire
they can even be scriptable objects that have their own methods
just swap out the asset and run its Fire method
Yeah I was going to make a simple GUI that with button presses 1 2 and 3 will select which spell it is using, but I just wanted to make sure it seemed like scalable I guess. Like I've never really gone too big with games so idk if adding like even 30 different kinds of spells would be a ton
SO?
ScriptableObject
its a class as an asset
more or less
they just goated to create variations of something
so having a list of a ton of spell strings wouldn't be good?
I'll look into all of that
I mean you could do some type of dictionary look up or something
wouldn't be so horrible
kinda flimsy , not a big fan of strings unless I make const but then you're making a big ass const class
private void spellSelect()
{
if (Input.GetButtonDown("Fire1") && firing == false && selectedWeapon.Equals("Staff"))
{
Debug.Log("firing-true");
firing = true;
anim.SetBool("Firing", true);
//Everyspell will have their own if statement
if (selectedSpell.Equals("Fireball"))
{
Debug.Log("FireBall");
anim.SetTrigger("Fireball");
}
}
}
Like in this the last if statement, each one will have it's own spell its checking and the selectedSpell will be chosen from like clicking a button on a GUI
and then I have a big state animator tree and each transition to each spell has a unique trigger
imagine how big you have to make the if statement to check all possibilities?
even with a switch
Yeah thats true, it would be like 30 different if statements
Whats the cleanest way to cast a Vector3 to Vector3Int? dealing with it often enough to where I’d rather not constantly do (int)x, (int)y,(int)z
well I plan on having them in like classes, like fire ice electric, so I guess it could check what class its in then what spell exactly to shorten the amount of checks
i usuaully store my specifc logic in the specific ability
my caster doesnt care what its casting, the cast takescare of it
it justcares about cooling times and speed
Na ScriptableObject’s are what you want here. They are the equivalent of prefabs but just for holding data.
Tyty, dunno how i didnt find that
so your saying have it be like a method called, castSpell(currentSpell) and then that currentSpell class would have all the script to it
I'll definetly look into those too
it depends on the game
your spell would probably have a child class to its specific type of spell
If you did it via ScriptableObjects you could just store a
string animationString
Then do animator.SetTrigger(currentSpell.animationString)
whatever is mechanically the same would have the same SO/Class for behavior
only data type changes
Okay, well thank you for all the info, hopefully it all turns out okay
eg all weapons/rifles have the same thing going on mechanically. Fire projectile, only thing that changes is the rate of shooting etc.
Ohh so have all the common data to each spell on the castSpell method and everything else in its seperate thing?
the commonality would be the method that fires this and behaves according to the data
instead of CastingFire, you just Cast(fire)
then cast method knows what values to use from fire and how to handle the rest
def give scriptable objects a look, they're pretty powerful for this stuff
hello, I have cars that will become children of lifts in a mechanics garage. When the lift goes up by animation, the car is supposed to move up with it. but it doesn't seem to work when the cars rigidbody is attached to it.
I tried different combinations of setting the rigidbody of the car to isKinematic = true, detectCollisions = false, and useGravity = false
but with those options it seems like the car will raise up just a little bit, but not all the way up with the lift.
the only thing that has worked so far is completely removing the rigidbody on the car at runtime before it goes on the lift and then when it comes back down off the lift I put a rigidbody back on the car and give reference to the few places in scripts that need it.
the problem i'm having with that approach is that it seems to mess up the way the vehicle drives. like for example when turning it tilts way too much, yet all the same settings seem to be applied to what controls the car mechanics.
I really don't want to completely remove the rigidbody from the car as it seems to give me problems, but I don't know why the other approaches I took didn't work.
any ideas?
https://hatebin.com/uaqcdyhvlb - Inventory Manager, grabs icon from the item data to be put in inventory slots
https://hatebin.com/eamjjznyko - Item Data Scriptable object
https://hatebin.com/ctccksuysr - Used to define the item data for each items prefab
https://hatebin.com/frwqjjvqri - Menu Manager, when opens inventory lists items inside of it
currently the items can go in the inventories list in the script
but it cant ever show up in the games inventory
i get an error from the 1st script from line 48, object not set to instance of object
if i add an item, itll create another slot at the bottom
Setting the rb to kinematic should work. If it doesn't, it must be some of your code interfering.
Make sure you don't run any of the car driving logic, when it's in the lift.
If it's using wheel colliders, might want to disable them too(I don't remember if they can be disabled though)
var itemIcon = obj.transform.Find("icon").GetComponent<Image>()
There are 3 things that can be null here:
-obj
-the "icon" object
-the image component.
Check which is it to know how to deal with it.
In fact, the past thing is irrelevant, so only 2.
so i changed obj to be set to itemContainer
now i get the error from line 47
which i think is an improvement
GameObject obj = itemContainer;
var itemIcon = obj.transform.Find("icon").GetComponent<Image>();
What error, and what's on line 47 now?
we have no idea what line 47 is
you posted several files and you've made changes since posting them
you are not getting an error from line 47
that's impossible
GameObject obj = itemContainer;
itemContainer is a field, and reading a field cannot cause a NRE
Probably the old code
NullReferenceException: Object reference not set to an instance of an object
InventoryManager.ListItems () (at Assets/Scripts/Item Scripts/InventoryManager.cs:47)
MenuOpener.Update () (at Assets/Scripts/UI/MenuOpener.cs:21)
https://hatebin.com/qzgffalrhj - menu opener
ensure that you've saved the file
yeah idk, I pretty much disabled any scripts running on it beforehand so i don't think that's the issue, but maybe I should go through and look again.
also, the wheel colliders didn't seem to effect the car not lifting. I leave them on when I remove the rigidbody of the car it seems to work fine lifting.
this would be consistent with deleting line 47 and then saving before adding GameObject obj = itemContainer; back in
100% sure
The line of code literally can't cause an exception. It's an instance method accessing a field on its own object.
yeah weird
still
oh
mb
I presume itemContainer is a prefab. Grabbing the Image from the prefab would not make much sense.
im slow
var itemIcon = obj.transform.Find("icon").GetComponent<Image>();
is the issue
the line is different on mine than hatebin and i said hatebins not mine
Making an rb kinematic is the same as just removing it, unless there's something else that's moving it(like your code or wheel colliders).
Well, then it's still the same issue that I mentioned originally.
And still the same way of dealing with it.
.
I would strongly suggest making a component for the "item container"
so that you can instead have
ItemContainer itemContainerPrefab;
Also, yeah, what Fen mentioned about it being a prefab
that component can have a field that references the container's Image.
public class ItemContainer : MonoBehaviour {
public Image icon;
}
e.g.
I almost never store things as a GameObject
like what i did here
public class Item : MonoBehaviour
{
public ItemData ItemData;
}
the important idea is that it'll let you access its components without having to go digging around for them
using Find and GetComponent is very brittle
yeah
if you rearrange the prefab a little, it can suddenly stop working
so make a new script like this
I've been doing some messy UI work today, but I never had problems with components randomly not being found
yes
alrightr
i still dont super understand what im doing with this
the point is that you'll be able to do this
var holder = Instantiate(itemContainerPrefab);
holder.icon.sprite = whatever;
instead of
var holder = Instantiate(itemContainerPrefab);
holder.transform.Find("icon").GetComponent<Image>().sprite = whatever;
do i put this script on my items prefabs?
but it does look better
You would attach it to whatever your item container prefab is, yes.
ohhh so my slots
You would then reference the prefab like this.
not as a GameObject
yeah
it cant be like a GameObject
i don't understand what you mean
just ignore that
i was just restating what you said
i got another error tho
ArgumentException: The Object you want to instantiate is null. UnityEngine.Object.Instantiate[T] (T original) (at <c2d036c16ca64e0eb93703a3b13e733a>:0) InventoryManager.ListItems () (at Assets/Scripts/Item Scripts/InventoryManager.cs:48) MenuOpener.Update () (at Assets/Scripts/UI/MenuOpener.cs:21)
I use GetComponent about a dozen times in total in the game I'm working on right now.
Eight are GetComponentsInChildren calls used so that I don't have to manually drag objects into a list (which are always parented below the caller).
The other few are all TryGetComponent calls in physics messages, like OnTriggerEnter
bump 🙂
to the image?
No. You tried to pass a null reference to Instantiate.
I presume you passed itemContainer to it
That means itemContainer is null.
Assign the prefab to it.
I said nothing about an Image.
Show me your code again if this is not the case.
It doesn't matter whether icon is assigned or not on your prefab if you don't have a reference to the prefab at all
alright I'll look into it a little more
I don't think there's a straight forward way, as the checksphere doesn't even return the hit info.
i dont understand what im assigning this too
im being very dumb
to reiterate:
- your "item container" prefab should now have an
ItemContainercomponent on it - your
InventoryManagercomponent should have a reference to this prefab. The reference should be in a field of typeItemContainer
hmmm, i it possible i can use a checksphere to get if its hidding something then a ray to grab the info?
This field should replace the GameObject field you originally had.
the itemContainer field should now be an ItemContainer.
oh the script as the component
I don't know what that means
the component ItemContainer is the script
I only use "script" to refer to the actual source code.
The thing you see in the inspector is a component.
You don't know what it's overlapping with though. The only thing it tells you is that "something" is overlapping. Might want to use OverlapSphere instead. At least that way you know what object is overlapping.
alright
You can reference a prefab by any component on the prefab's root object
alright
When you instantiate it, you'll get a whole new object
(it doesn't just duplicate the component or something)
public ItemContainer itemContainerPrefab;
void Start() {
ItemContainer myContainer = Instantiate(itemContainerPrefab);
myContainer.icon.sprite = ...
}
yes
ItemContainer myContainer = Instantiate(itemPrefab);
myContainer.icon.sprite = item.icon;
okay, good. and did you drag the prefab into the itemPrefab field in the inspector of the inventory manager?
that will prevent it from showing up, yeah
sorry you have to deal with me im trying to progress learning 💀
well
now the error is in line 50
NullReferenceException: Object reference not set to an instance of an object
InventoryManager.ListItems () (at Assets/Scripts/Item Scripts/InventoryManager.cs:50)
MenuOpener.Update () (at Assets/Scripts/UI/MenuOpener.cs:21)
okay, so what's on line 50?
myContainer.icon.sprite = item.icon;
is it from the myContainer or item.icon?
like what isnt being set
use the thread, please
thread?
i started a thread here.
mb
How do i fix this, So when I hit the pipe it should be a scene and i can play more but it is not poping up, So hlow do i fix this?
use Debug.Log statements to check if your code is running at all
In OnCollisionEnter for one
Also in GameOver
Does the LogicManager have the Logic tag?
i know there's a way to simplify this but this is just to catch all edge cases for my enemy AI, lol
if((playerInSightRange && !playerInAttackRange && playerInLineOfSight) || aggroTime <= chaseTime && (!playerInAttackRange || playerInSightRange && playerInAttackRange && !playerInLineOfSight))
wait actually thinking on this, this doesn't work because now my line of sight mechanic is moot
ugh
how can i get the movement speed of a non rigidbody object?
My brain can't think of any ways to clean that up specifically but could maybe be worth having a property or two that contains that big check instead for better readability?
true
I have a question so I have a game object in scene one, and in scene two there is a prefab of that game object. My character has a script attached to it that the game object in scene 2 needs to access but it cant since it is from originally from scene 1 (Im using do not destroy on load). I need help to find a way that the gameobject in scene 2 can access it when the player enters the scene
I might understand it wrong since I don't have the full context but maybe worth seperating your bools into
hasValidTarget => playerInSightRange && playerInAttackRange && playerInLineOfSight
readyToAttack => aggroTime && chaseTime
hasValidAttack => readyToAttack && hasValidTarget
I’m not sure
Look at the inspector for it then. Tags are at the top
You are searching for it by that tag
also just a random guys opinion but playerInSightRange might be better named playerInRangeOfSight so it's consistent with playerInLineOfSight
Wait I’m taking a really big shit rn
The game over needs a tag?
GameOver is a method.
The object with LogicScript attached needs the tag
Looks like you called that object Logic Manager
Tags go on objects
That's it, and you got it
Does what work? FindGameObjectWithTag("Logic") works
nope it does not work
Did you do the debugs to check the rest?
act like ur talking to a 13 years old ok?
it makes things not hard for me
I was doing stuff like this at 13, so 🤷♂️ (not unity, but light coding)
https://docs.unity3d.com/ScriptReference/Debug.Log.html
Read the docs, it has examples
I am 13
how could I place points on a sphere but each must be atleast x distance away from any other
Ok 👍
I dont get what u mean by use debug
Did you look at the link?
It literally has example code
yes but it says use debuh
I mean... not really?
Just add code like the example to the places I said above. Anything. Then the stuff you write in Debug.Log() will show in your console
Debug.Log("words");
Bro, look at the link. Take a minute to think about it. Take a minute to think about how you can use it. If you need to, look up a tutorial on it.
You are trying to determine which functions are running, and using Debug logs will help with that, because you will only see the words in the console when the code runs
13 is MORE than old enough to figure this out
well im dumb............. lol
also i dont get what u want me to do ur saying to read all that but i dont know why im reading all of that
Age old excuse a lot of people tell themselves
You add the code to a function. If the function runs, you see the words in your console... so simple
ok there
so know i will ask 1 more time at the end of what script do i put Debug.Log() or Debug.Log("words");?
Neither... dang bro
THEN WHAT!...
You add text in the method call. Text that makes sense and is descriptive
bro im so lost
"You add text in the method call."????????
You may want to stop doing unity and do a beginner c# course then...
Do you know what a method is?
The things with these: ()
You call a method when you write that somewhere.
Except when you are declaring the method (when you see something like public void in front)
Debug.Log("any kind of thing I want to write here") calls a method that writes that text into your console
If you write Debug.Log("my oncollisionenter method successfully ran") inside your Oncollisionenter method, wouldn't that help determine things?
OH
Log is a function
it takes parameters
Mouse over it
read the errors

