#💻┃code-beginner
1 messages · Page 151 of 1
it pings the object in the hierarchy
I clicked on it and it didn't do anything
wow, i just learned of this physics debugger, as well as the frame debugger, these tools are awesome
its subtle.. when u click once it highlights it in a yellow box
if u double click it it will automatically select it
it doesnt highlight it htough
wait im dumb
waiit no it doesnt
it works if I do a different gameObject but if I do Debug.Log("Click", hit.transform.gameObject) nothing happens
but if I just do Debug.Log("Click", gameObject) it highlights an object
but I only have 1 object named WallEZ so I know which one it is
anyone know how to fix The referenced script (Unknown) on this Behaviour is missing!
Remove it and add a valid script
well idk what its on lol
its just popping up 4 times
cursed 
Unfortunately it doesn't tell you which object. I think there's a few scripts floating around that will track it down
any suggestions?
are you sure its not the ones from saving/compiling scripts while in play mode?
why would it take in the transform to assign the new object a parent
sorry if that was worded badly
this is for instantiating, should've been more specific
well, if you want to parent it on the hierarchy then you're free to do that, otherwise it'll just be in world space
i need it to instantiate as a child of another object
Can you tell me why this doesn't work in the isometric world?
if I press W then it goes to the left
well, then you give it the parent of the object you want to child it with
why is it a transform, and not a gameobject
all gameobjects have a transform (if they exist in the scene, then they must have some type of coordinates in it)
it's just a unity thing
alr i just didn't think it made sense lol, i figured it would take a gameobject
help guys
you're right in a sense that it would make more sense to be a gameobject ref, but if you think about it more it is about placement in space (vector/rotation/matrix via local coordinates) which is more related to transform values
what ide is this?
alright thank you 😊
Rider
your assigning the currentrunmovement.z to y
i could be wrong im just guessing
and which one is needed?
I have a top-down camera, the character moves normally
but there is no isometry
im confused
you said your character is moving the wrong way
Yes, that's right, he doesn't walk correctly in isometry
if I press W it goes to the left, if I press A it goes down
it turns out 90-degree turns, instead of 45
In theory, if I press W it should be 45 degrees
But instead I turn 90
It doesn't look like you are coding it to go 45degrees. You are using a lookat and rotating that way
transform.Rotate(new Vector3(45,0,0);
As for movement, you are using WASD as arrow keys. And applying the position of the arrow keys. Most isometric aren't left to right and up and down though. A tile based isometric you usually want left x2 and up x1 for example.
But you have the code on going left / right/ up / down. It's just a guess though as the input keys are using the newer input manager and would need to be verified there as well
Basically you need to take the input and adjust it for the view of your game
No, why are you adding a lookat?
If you want to rotate it 45 degrees, just do transform.Rotate(new Vector3(45,0,0));
Like, you can just rotate it 45 degrees without needing to add anything else
I'm not sure why it is doing a lookat etc.
But maybe it's needed? It would depend on the context of the rest of the project
Why are my Debug.Log()s are so different? The left image is 2021.3, and the right image is 2022.3
I haven't changed any settings that I know of. The only difference is the first is a Windows project, and the other is a Mobile project.
Same code, same debug yet :
- The 2021 Windows version is cleaner and I can double-click it to show the line in VSCommunity.
- The 2022 Mobile version is cluttered (having the line number way down the stack. and a double-click does not open VSCommunity
Well, how do I move around in an isometric world?
I'm making a custom editor for one of my scripts right now but the object assign box is super small when there is plenty of space between the label and box
This is my current code:
dungeonGen2.distObject1 = (GameObject)EditorGUILayout.ObjectField("Object 1", dungeonGen2.distObject1, typeof(GameObject), true);
dungeonGen2.distObject2 = (GameObject)EditorGUILayout.ObjectField("Object 2", dungeonGen2.distObject2, typeof(GameObject), true);
EditorGUILayout.EndHorizontal();```
And ChatGPT is telling me to split each one into two lines to set the label size like this:
```EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("Object 2", GUILayout.Width(70));
dungeonGen2.distObject2 = EditorGUILayout.ObjectField(dungeonGen2.distObject2, typeof(GameObject), true) as GameObject;
EditorGUILayout.EndHorizontal();```
Is there a way to set the size of the label and keep it all in one line per object-label pair? I tried just putting the GUILayout.Width(70) after "Object 1" and it didnt work
If I do as you suggest
I'm not sure on the specifics, but the right one has a bigger preview pane below it (you can click and drag that middle line to increase the size)
im aware.. but thats all it is on this version
I don't think I can be more specific over discord on my phone, sorry!
Is that in the editor view or while testing on device?
its the editor..
What version is that one?
im just trying to figure out what the difference is exactly.. b/c the Big one.. doesn't open Visual Studio when i double click it.
like the smaller version does
the big one
and the small one
just strange.. unless the mobile setup uses different types of logs?
Im not sure why the one on the right is showing a detailed stack trace. But it's not narrowing it down to code. I'm suspecting there is a debug option enabled somewhere for stack trace digging
thats the only thing i can think of as i didnt really change anything besides from 1 line to 2 line
ill try to compare the two and see if theres just a tickbox im missing
You have stack traces set to full
Go through the top right menu of the console window, or the player settings and set them to Script
ur a life-saver
❤️ so much better
And the double click to open in VS works again!
not sure how that got flipped lol, TIL📝
The setting for the window is annoyingly the same as for builds
i didn't mind at first, until I started looking for line numbers.. had to scroll half a page to find the first script hyperlink looking thing
How good is this solution?
Why am I being pinged?
so that the control is normal in 3d isometry
what on earth does this have to do with me
We've been talking to you, haven't we?
I can't see well, I have a disability, don't you get mad 😭
my two cents: if it works, roll with it. If there's an issue with it you'll discover it before too long,
and if it needs optimized in the future, that's a future project..
- does it work ?
- can you understand it ?
it works, but I don't understand how it will affect memory
it cant be worse than polling for input.. which is what usually gets done
well, thank you
open up the profiler, and check
I don't know how to work with him yet.
It literally says what to use instead
if your Unity version has it as obsolete it should mention obsolete methods no matter the IDE, no?
download a rider for yourself
not sure
brb! lol
yes
I use it for free
the EAP just started yesterday
code: https://hastebin.com/share/ikibexemim.csharp
The problem is that there shouldn't be that space between "objectives" and "obtain one coin", then when i run the complete function it tries to replace the white space instead of obtain one coin
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I've been using it for half a year now
it says you have a subscription
visual studio is ole' reliable.. always there when you need it most..
but rider, ❤️ me some rider.. like that new toy you don't need but looks great cruising around town in 😄
I didn't even come in.
I activated the code that was sent to my email
I shared it with a friend, and he uses it too
You got the license somehow—presumably by paying for it
Maybe
I can't physically buy it, my banks don't work.
Are you using the github student developer pack then?
no
🏴☠️
no
lol jk with ya 😄
I just downloaded it from the website and wrote to them
I get all the updates that come out without any nonsense
and wrote to them?
well, lucky you
yea, i need to email em too.. see if i can get a hook up with free liscense
I was told that I can use it until the release of the 2024 version
after that, she will turn off
Right, well I have no idea why you buried the lede
iirc its free if you contribuite to open source repos
You can see all the discounts https://www.jetbrains.com/rider/buy/#discounts
can you tell me a good plugin to put the code in order?
@rocky canyon this what I meant 🙂
so the conversation earlier just sort of ended... when I click on the debug message for Debug.Log("Click", hit.transform.gameObject); nothing gets highlighted
so that he formats my code beautifully
The only cases that can happen as far as I know is if the object was destroyed or isn't in the scene or hierarchy for some other reason
the student one specifies "university email address" - but there is a checkbox for high school, is there like something im missing
no objects are destroyed
No idea, if you're a student you can just go through this to get loads of stuff https://education.github.com/pack
Can you send the entire script !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 System.Collections;
using System.Collections.Generic;
using UnityEngine;
/* Script Purpose
* On Room Frame instantiation:
* add empty walls around them
* add actual walls where walls already are
*/
public class AddWalls : MonoBehaviour //Called when new room frame is placed
{
[SerializeField] GameObject wall, blank, cam, parObj;
[SerializeField] BoxCollider linearOffset;
[SerializeField] private LayerMask wallMask;
/*
* wall: the wall that will be added upon room creation
* blank: empty gameObject
* cam: the camera
* parObj: parent object of the frame, holds all of the walls etc. as children
* linearOffset: the box collider for the frame which determines its size
* scriptHolder: an empty gameObject that holds many scripts used as a really shitty library
*/
[SerializeField] float wallOffset;//percent of distance the wall is between the center of the frame and the edge of the frame
//I could have done it by distance but for some reason I couldn't figure out how???
//Called when new room frame is placed
void Start()
{
gameObject.GetComponent<Renderer>().enabled = false;
GenerateWalls(transform.gameObject);
FindNeighbors();
parObj.name = $"Room ({parObj.transform.position.x/6}, {parObj.transform.position.y/6}, {parObj.transform.position.z/6})";
}
void GenerateWalls(GameObject obj)//generates empty wall parents around a room on all sides except those adjacent to other rooms
{
for (var i = 0; i<= 3; i++) {
Quaternion rotApplied = Quaternion.Euler(0, 90f * i, 0);//adds 90 degrees each iteration
Quaternion rot = obj.transform.localRotation;//rotation of frame, applied to walls
Vector3 framePos = obj.transform.position;//position of frame
Vector3 offset = new(0,0,linearOffset.size.z * 0.5f);//offset from the center of the frame
offset = rotApplied * offset * wallOffset;
offset += framePos;
GameObject newObj = Instantiate(blank, offset, rotApplied * rot, obj.transform.parent);
newObj.name = $"{blank.name}{(NSEW)i}";//renames walls based on direc1tion they are facing
}
}
private void FindNeighbors()//finds if there are neighboring frames
{
float sizeX = linearOffset.size.x * 0.5f + 2f;
for (int i = 0;i<=3; i++)
{
//Debug.DrawRay(transform.position, Quaternion.AngleAxis(90f * i, Vector3.up) * Vector3.forward * sizeX, Color.red, 5f);
if (Physics.Raycast(transform.position, Quaternion.AngleAxis(90f * i, Vector3.up) * Vector3.forward * sizeX, out RaycastHit hit, sizeX, wallMask))//shoots ray, rotates by 90 degrees per iteration
{
Debug.Log($"{Quaternion.AngleAxis(90f * i, Vector3.up) * Vector3.forward * sizeX} {90 * i}");
Debug.Log($"Hit object {hit.transform.name}@{hit.transform.position} from {transform.position} with run index {i}", hit.transform.gameObject);
Debug.Log("Click", hit.transform.gameObject);
Debug.DrawLine(transform.position, hit.point, Color.red, 5f);
}
}
}
private enum NSEW//pos Z = north, pos X = East
{
North, East, South, West
}
}
FindNeighbors is where the issues are
code: https://hastebin.com/share/ikibexemim.csharp
The problem is that there shouldn't be that space between "objectives" and "obtain one coin", then when i run the complete function it tries to replace the white space instead of obtain one coin
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I can give you the key and you can try
I do not know how many times it can be used
would be greatly appreciated
write to me in private messages
I can't see what the issue would be. Perhaps try to Debug.Break() when the issue occurs so it pauses, and then you can see the state of the scene at that point.
What is the name of the object it looks like it's hitting (when selected via the physics debugger overlay?) at that point in time...
Perhaps use the debugger instead of the logs to see if you can gleam any more info, like the hierarchy or something else
how do you view what is being hit via physics debugger?
Just by looking visually and using the Mouse Select option in the bottom right menu, selecting the object
these screenshots are showing objects there though?
those objects are ignored via layermasking
can you tell me how to make steps for a character so that there is not a lot of sound of steps?
what's this object?
that's the wall that has arrows here
if WallEZ there doesn't exist, this bug doesnt happen and it doesnt register as hitting anything
and this one?
Can you disable the blank wall that it looks like it's hitting, and then advance the frame and look again?
right now, the bug happens if the cloned wallEZ exists there and doesn't if it isn't there
Does the cloned wall get moved around at all?
like redo it with the blank wall disabled or disable and continue?
the cloned wall does not get moved after instantiation
No, just checking if there's something there when you disable the one it's apparently hitting
yeah the code instantiates it prerotated and premoved
if (Physics.Raycast(hit.transform.position, hit.transform.rotation * new Vector3(0, -1f, 0f), out RaycastHit hitInfo, 0.5f, wallMask))
{
Instantiate(newWall, hitInfo.transform.position, Quaternion.Euler(new Vector3(0, hitInfo.transform.eulerAngles.y, 0)), hitInfo.transform);
}```
that's the code that puts it there
with newWall being WallEZ
Do any of the parents of WallEZ have a rigidbody?
there are no rigidbodies anywhere in the scene
if this works it's probably not the solution you should go with, but it might fix it... can you add Physics.SyncTransforms before FindNeighbors?
still doesnt work
I have no idea at this point. I think you'll have to upload your project somewhere to have someone else look at it unless someone else has an idea
can someone tell me what is wrong with this?
private bool[] myArraybool = new bool[30];
I want to set a max. length directly in the script because I want to keep my Inspector clean.
then recreate a new array and copy all stuff into it
or using some wrapper of an array ie list
What do you mean?
Atleast my code can not be right if Unity say IndexOutOfRange.
But what do I have to write to limit my bool array to "30"?
I can't find anything in google because all peoples use a public array and give their lenght value in the inspector.
you already limit the length by setting the length
is my code not wrong?
private bool[] MyBool = new bool[1];
void Start()
{
print("MyBool 0 = " + MyBool[0]);
print("MyBool 1 = " + MyBool[1]);
}
ofc you cant access the memory space with index >= array.length
what do you mean?
the last print is to make sure thaat it should not work.
but even if I outcomment it I still have this error.
its always confusing me when '0' does count and when not.
If I say bool[1], does this not mean the "0" is also counted?
array index starts from 0
so whats wrong with the code up there?
IDK what " index >= array.length" means
your array length is 1 and you try to access [1]
Ok now it becomes day.
Its just so weird I thought all the time:
private bool[] MyBool = new bool[1];
mean a value of 2 bools because the '0' does matter in this private bool.
and basic counting, for open interval [0,b) ie 0<=index<b the count is b-0 while for closed interval [0,b] ie 0<=idx<=b count is b-0+1
hence the valid range of index is [0,b)
ok thx.
Hey all so I'm trying to get a chest to spawn random loot when opened. I have the following code to do this:
if (collision.gameObject.CompareTag("unlockbronze") && playerAttributes.bronzeKeysRemaining > 0)
{
playerAttributes.RemoveBronzeKey(1);
Instantiate(chestLootPrefabs[chestLootPrefabsIndex], collision.transform.position, collision.transform.rotation);
StartCoroutine(OpenChestDelay(collision.gameObject));
}
this does not throw an error, but it doesn't instantiate the loot either. If I remove the "collision" from the transform position and rotation, it works and instantiates the object on the player, which is obviously not what I want to have happen. I tried making a script and attaching it to the chest directly but it doesn't trigger since the chest is static (plus I'd prefer not to do it that way if I can help it). Any thoughts or help?
So have you confirmed that the code is running?
I didn't debug it, but the other parts of the code function as intended (the bronze key is deducted from inventory and the chest is destroyed after a delay)
so the code block is at least executing
Because if it is, then it is instantiating the object. Perhaps just not where you think it is?
well, nothing new appears in the hierarchy. I guess I'm wondering if the collision.transform.position is correct syntax, or if its doing something else (this was a complete guess on my part to try to change the spawn point from the player to the object the player collided with)
figured it out. just had the tags set to the wrong chest type. Thanks for the response!
Guys 1 question when I type using UnityEngine.SceneManagement sometimes it works sometimes it doesnt
show an instance of it not working
you need to configure your !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
• Other/None
https://docs.unity3d.com/ScriptReference/Quaternion.LookRotation.html
So in this example they don't normalize the direction placed into this method, nor normalize the quaternion afterwards. It says it does set it to a normalized forward direction afterwards is why I ask.
testing there doesn't seem to be a difference but with rotations like to lie to me
I believe they normalize it, however that's not gonna be guaranteed if you use any other library
Quaternions from Unity methods are always normalized however
they are never going to be broken
does someone know how to make dropdown like here in my own script?
The easiest thing would be to use an enum
okay
oh thanks
Here's the code im using for rotating the steering wheel in my car, i want it to rotate back to original position when i dont turn the vehicle though, any approaches i can take?
Why when I click create a new palette and create a folder, nothing happens and I can't create a tile palette?
This is on 2D btw
ok so like probably a dumb question but what is the advantage of using TMPro components over like legacy text components, almost every Brick wall I have run into coding in unity so far (still early learning but you know) has had to do with TMPro and me not being able to find good info on how it works
From what I remember it is mostly just because there is finer control over the style of text, might be wrong though
how are those things called so I can create a window that does something later please? Like I only need the name, the rest I'll try to search it haha
Ah i gotcha thnak you
thank you*
This is a code channel. #📲┃ui-ux for ui questions. TMP works just as basic text element when it comes to basic manipulation. And if you want more advanced usage there's a wealth information on YouTube by original creator, any cursory search would've landed you there.
i was asking because I have had issues with it in my code but i understand, i will use the respective channels for Components in the future, tbh I forgot they were there
Just a question
When I press the play button on unity all the buttons I've placed dissapear
if (incrementInfo.abilityCastAmount > 1)
{
void SetIncrementRange(IncrementRangeTypes rangeType, in Vector3 a, in Vector3 b, ref Vector3 unitsPerIncrement)
{
if (continualCastData.IncrementData.IncrementRangeTypes.HasFlag(rangeType))
{
unitsPerIncrement = (b - a) / (incrementInfo.abilityCastAmount - 1);
}
}
//Can't use ref keyword on other structs
SetIncrementRange(IncrementRangeTypes.StartPosition,
continualCastData.IncrementData.PositionIncrementA,
continualCastData.IncrementData.PositionIncrementB,
ref incrementInfo.startPosUnitsPerIncrement);
}
How do I pass these vector3 structs as a reference which are backed by a property field with a private setter? It seems that perhaps it's the 'in' keyword I need, but examples show that the 'in' syntax is also attached when sending in the parameters yet that gives me similar errors to using ref.
should be impossible, properties are method and you cant ref on some return register
So what's the alternative here? Just don't stick your structs inside of properties?
it's really a minor thing in this scenario, but I do have some larger structs of variables so it would be silly to copy them repeatedly just to read them.
ah, even pointers have a similar problem here too eh
return ref? forgot if unity c# allows you to do this
The property would have to be a ref return
If it's just for reading, you could use the in keyword relative to methods. With properties, it's more like accessing the actual backfield although the underlying behavior would be getter and setter methods.
What do you mean by readonly here, why do you care about by reference in this case if they're readonly?
guys is there a built in method for squared distance?
(b - a).sqrMagnitude
in this scenario I'd have to copy the vectors to read them inside of this method
being ref is not actually ideal either I guess if they were modifiable, but it's a private setter property field
it would be in keyword I think
or ref readonly?
I'm kinda confused, is the idea that you can't change the declaration of the SetIncrementRange method
and there's a compiler error because you're trying to pass a non-ref property by ref
To be clear, if you use in with a non-ref returning struct property you incur a copy, and the copy is passed by ref
guys what the hell is this?
Maybe have the structs be light weight, don't have them as structs or use a method to define explicit parameter constraints 🤔
Can you show the error from the console window? The image is too small.
okay
yeah it's not a big deal here, but first time I've ran into this issue which I'm surprised I've not before
Hello, have you looked at this post ? https://stackoverflow.com/questions/59829252/unity-error-does-not-contain-a-definition-for-isgameobjectinmainscenes it seems you may have to rebuild the library folder because some files may be corrupted
oh ok thanks
why do we use CompareTag and not tag==other?
!ban 1196088124799979551 bot spam
nicholas05355 was banned.
You get an error message if you typo the tag name & it's marginally faster
do i get an error or it returns null?
It's a compile-time error. It always returns a boolean.
oh ok ty
not a compile time error, it will throw an exception at runtime
== tag will not throw an exception, it will return false for a bad tag
Don't add deltaTime
hey guys, so Im basically watching an old tutorial video, the guy uses 2020.3,8f1, and I have the 2021 .3.14.f1 editor would that create a problem?
Don't cross-post
thank you for being helpful
I am using the 2017 version course on the 2021 version and there were no problems)
They have been answered in #💻┃unity-talk
I'll download the 2020 just in case
small differences in the interface are possible
I see
can I ask why you're using 2017?
just out of curiosity
okay, okay)
#🖼️┃2d-tools (or the channel for the render pipeline you use) or #💻┃unity-talk , this is a programming channel
im doing an inventory and i wanna get some info from the Slot UI's with another script,im trying raycast and i get nothing i dont know how to do this
That raycast won't work
if this is UI
to give you an idea why. Go into your scene and see where you UI is positioned compared to where your camera is at
i was thinking about that
but i have no idea how to fix it
https://docs.unity3d.com/2019.1/Documentation/ScriptReference/UI.GraphicRaycaster.Raycast.html
Is the raycast you'd want to use, but there's also interfaces such as
https://docs.unity3d.com/2018.3/Documentation/ScriptReference/EventSystems.IPointerClickHandler.html
That's a more common approach
IPointerClickHandler does not need to be on the ui thats gonna be clicked?
You stick them on components and the'll trigger
when you're over that specific gameobject
There's quite a few like IDragHandler (one of the more useful ones)
noice
this will hit stuff other than the UI too I believe, but you can always iterate through for UI specific elements
hey
can you set multiple vars with one = in chsarp ?
e.i. :
int somevar1;
int somevar2;
somevar1, somevar2 = 10;
why would you var primitives
what do you mean by that ?
a = b = c
var is for when you don't want to type out the whole dictionary kvp
but seriously, the vs debugger has trouble with var
ah yes, but here i am not using var ?
Is there a code question in "it"?
oh sorry sleeping here, right Dalphat's correct then ;p
no worries man
No, it's just that every time I get close to the object it starts to disappear, it's not related to the code.
https://unity.huh.how/scene-view/clipping-planes
Ask in #💻┃unity-talk next time
ok ty
Hello
So I am trying to get the camera working
I can get the main camera to work like fps
I am now trying 2rd person but this code is giving me an error
could anyone explain to me why this code cannot be accepted please?
It's ok even if you have a theory to why it's not working
we can work it out together
using UnityEngine;
public class AudioScript : MonoBehaviour
{
private AudioSource audioSource;
public AudioClip[] audioList;
private void Start()
{
audioSource = GetComponent<AudioSource>();
}
public void DinoSFX(int sfx)
{
audioSource.PlayOneShot(audioList[sfx - 1], 1f);
}
}
I get an argument null exception but I have already assigned the mp3s into my GameObject
that has this script
and on what line is the error coming from?
please be specific when you're asking for help with exceptions
well, you'd better start debugging
notably, what if audioSource is null?
although "argument null" makes me think this is an exception complaining you asked the audio source to play a null clip
show us the error in the console.
remember that we cannot see your screen..
Okay, so that definitely means that audioList[sfx - 1] is null.
to clarify: you have assigned AudioClips into your AudioScript component
you aren't putting anything into a game object
My guess is that you have several AudioScript components, and that one of them has missing clips
If you click on the exception while the game is running, the editor might select the offending object
(I'm not sure if it will here)
It's my playerobejct
but that's impossible I already audioclips into element 0 and element 1
i already assigned*
Show the inspector for the AudioScript.
Okay, now search your scene for other AudioScript components
you can do this in the hierarchy
t:audioscript
okay, so now we want to do some "sanity checks"
before you try to play the audio clip, log the clip and the current object
log?
Debug.Log("I'm trying to play this: " + audioList[sfx - 1], this);
okay
I wonder if you're creating a new instance of AudioScript at runtime. This will show if that's the case
Thanks for letting me know
I have fixed with a tutorial regarding vector3
but isn't it the same thing?
why wouldn't my code work?
Looks like the error isn't happening there.
I need help with something I ran into. Lets say Gun1 has 10 bullets and Gun2 has none. When I switch to Gun2, I can shoot only one bullet as if it registers the weapon switched when I click. Ill send the scripts
meaning the actual clip is there?
weapon switch script
Right. The clip is non-null and there's no exception.
weapon shoot script attchached to player
you can think of a tuple as a grouping of several objects
they're sometimes useful when you just want to return A and B from a function
(you often just use out parameters for that in C#, though)
So what's wrong then? why does it have an exception when the audiosource plays it?
there is currently no exception in the console
are you seeing an exception in the console?
yes when the audio source plays it
i dont know if anyone can help me but i am making shooting game and have made it possible to shoot and setup a crossair in the middle of my screen but the bullets dont go to middle of my scrteen they are like of with 1 cm is there anyone who has had simmilar problem and could help me
{
Ray ray = playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
RaycastHit hit;
Vector3 targetPoint;
if(Physics.Raycast(ray, out hit))
{
//hitting something
targetPoint = hit.point;
}
else
{
//shooting in air
targetPoint = ray.GetPoint(100);
}
Vector3 direction = targetPoint - bulletSpawn.position;
float x = UnityEngine.Random.Range(-spreadIntensetiy, spreadIntensetiy);
float y = UnityEngine.Random.Range(-spreadIntensetiy, spreadIntensetiy);
//returning direction and spread
return direction + new Vector3(x, y, 0);
}```
this the code that calculates the direction
Isn't the entire point of this code to make it not perfectly centered
I don't understand why you'd get an ArgumentNullException out of this, though.
what?
You're literally adding random spread
Maybe if it was an extension method
Check if audioSource is null.
how?
but its not spreading its always on same place just a bit under my dot
log it!
and ooh, I think I get it now!
here's why it's happening
when you do GetComponent<AudioSource>() and it fails, it returns an invalid unity object
it doesn't literally return null, though
When you call PlayOneShot, it winds up doing this
PlayOneShotHelper(this, clip, volumeScale);
where PlayOneShotHelper is
private static void PlayOneShotHelper([NotNull] AudioSource source, [NotNull] AudioClip clip, float volumeScale)
notice how the first argument is called source
and finally...
IntPtr intPtr = MarshalledUnityObject.MarshalNotNull(source);
if (intPtr == (IntPtr)0)
{
ThrowHelper.ThrowArgumentNullException(source, "source");
}
oh god that's frightening
Try logging x and y, see what numbers you're rolling, check if they ever change
god, I don't enjoy how Unity conflates C# null with Unity's own notion of "null"
oh do I actually have to add an audio source?
It is an albatross about the neck of unity they cannot escape
like my dinoplayer gameobject?
i've seen weirdness, but this is a new one
that was really unintuitive
"is this null?"
"well yes, but actually no"
okay thx
It searches for an instance of a certain type
If you call gameObject.GetComponent<Foo>(), it tries to find a Foo on gameObject
you can also call GetComponent on any Component type; it searches the component's game object
and then the error it caused is one that should intuitively be impossible
this being "null" is so bogus
I expected audioSource.PlayOneShot() to immediately cause a NullReferenceException
(and it would have, if audioSource = GetComponent<AudioSource>() was never called)
it went from real null to a non-null object that Unity still considers to be null
Extension methods have this behaviour regardless of Unity null
Yeah, that was my first thought
and what Unity did wound up being kind of similar to an extension method
(passing this as the first argument to another static function)
Can I messege or call someone to help me with someone in my game
I fixed it, added an audio source component to my DinoPlayer GameObject I kinda get at what you're saying, so I tried to add an AudioSource component and it fixed it
thanks
The tricky part here was how the error appeared.
No, just ask the question here
Lets say Gun1 has 10 bullets and Gun2 has none. When I switch to Gun2, I can shoot only one bullet as if it registers the weapon switched when I click. Ill send the scripts
player shoot script attached to player
hey lads. i set up this settings menu with a volume and music slider, but it dosnt seem to be working correctly. the volume slider is setting the master volume, but the music slider is setting both the master, and music volume. what am i doing wrong? sliders and audio mixer groups have been set up correctly
wait ill send the code in a sec
i'm guessing that's doing it
oh, you fixed it in the inspector
musicSlider.onValueChanged.AddListener(setVolume);
this sounds wrong, though
you're calling setVolume when the music slider changes
yea
this code is from a long time ago, when i followed a brackeys tutorial
i just wanted to reuse old code and not write new code
well, you probably want to call setMusicVolume when the slider changes...
already done that
Your code still calls setVolume
read your code!
that explains why both sliders are changing
oooooh
wait, so i dont need to set this on value changed up?
since a listener has already been added for the sliders in my code
Either way works.
I have a script that is trying to set the vertices of one gameobject (a standard 3D plane) to another gameobject (also a standard 3D plane).
I'm getting an error that there is no Mesh attached to Plane gameobject. I don't see how a standard Plane doesn't have a Mesh... How can I make this work?
`public class meshgrab : MonoBehaviour
{
public GameObject grab;
// Start is called before the first frame update
void Start()
{
this.GetComponent<Mesh>().vertices = grab.GetComponent<Mesh>().vertices;
}
}`
some clarifications, first
gameobjects don't "have" vertices
a GameObject is just a thing in the world that can hold components
a Mesh is not a kind of component. I'm a little surprised that didn't cause a runtime error.
You want to grab the object's MeshFilter component
You could just reference it directly instead of referencing a GameObject
so,
[SerializeField] MeshFilter source;
[SerializeField] MeshFilter destination;
void Start() {
destination.mesh.vertices = source.mesh.vertices;
}
I'm not sure if you'll need to do anything else after setting the vertices property
All right, I'll try that. Thank you! =]
Mesh is a unity object class that represents mesh data
It won't be directly attached to a game object 'cause it's not a component
i have some questions if you all dont mind...
is 2d or 3d easier for a beginner?
what are some beginner projects because my ideas are way to complex and hard to make. like how do i com eup with an idea or know what to make?
that is all for now.
private void Update()
{
GameSpeed += gameSpeedIncrement * Time.deltaTime;
gameScore += GameSpeed * Time.deltaTime;
MilestoneScore();
}
private void MilestoneScore()
{
if(Mathf.FloorToInt(gameScore) == milestoneGameScore)
{
audioSource.PlayOneShot(milestoneClip, 0.2f);
StartCoroutine("MilestoneText");
}
}
Anyone know why my audiosource is playing multiple audioclips even if the condition is only hit once?
the actual audio file sounds fine
when played by the game, it stacks thus making hurtful to ear to listen to
if the game score increases slowly enough, it'll produce the same value when floored to an int for several frames
10.01 -> 10
10.32 -> 10
10.64 -> 10
10.89 -> 10
record the last milestone score you achieved and only play a sound if your score differs from that
comlpletely then?
same problem
many score values will produce the same integer
wdym?
when you reach a milestone, store that score into a variable
only play a sound if that variable is different from the current score
so that the game will ignore these repeats
im not sure if this is the best place to ask this?
I found 3D easier, but that's probably because I do a lot of 3D stuff already. It's easy for me to mash some assets together
You should start with something like !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
thank you also i was hopeing to get into 3d becasue it seemed cool.
you use your imagination. After all that is where games start, a good idea
well im just starting out and i want to make things like open would games and visual novels but they seems to hard at the moment.
they are, indeed, hard to make without experience, so start simple
also sorry for my spelling im kinda dyslexic.
3D is easier just because sprites are hard
i got error
u are can help me for fix this: Could not resolve all files for configuration ':unityLibrary:GoogleMobileAdsPlugin.androidlib:detachedConfiguration2'. See the Console for details.
what about 3d movement/animations? are they not as hard?
Don't spam every chatroom.
okey
3D animation is easier than 2D since you just lerp values
while 2D sprites you're drawing every frame
that makes sense
of course there is resources to cheat 2D animation, but there's more popular methods of making 3D assets look 2D to get the benefit of animating them in 3D
im starting to think maybe i should make an fps or is that too hard? as i said i dream big.
still too ambitious, learn to walk before you try to run
Without just firing me off the ide command...
Anyone else having issues with VSCode not showing default Unity information? EG: It doesn't show me void OnEanble auto completes etc?
It used to work perfetly fine, but, I assume something got updated somewhere and now something is broken.
fps is actually a little more intermediate because you're dealing more with rotations. A lot of games you can get away with just rotating on a single axis or even disabling rotation completely and moving using world coordinates with velocity.
Just want to inform you that making games overall isn't easy
platfomer in 3d?
i know but its kinda my dream to make one.
yep, not a bad idea
i would like to say thank you all for helping.
Target a particular game and try to clone it
I always suggest implementing existing board games because you don't need to focus on the game play, just the implementation and visuals
I couldn't really get what you meant, but I just decided to have a bool flag to check if the audio was already played once, then resetting the flag after the my CoRoutine ends since they go hand in hand anyway
int lastMilestone;
public void TryMilestone(int score) {
if (lastMilestone != score) {
lastMilestone = score;
PlaySound();
}
}
like so
was anyone able to look at my scripts
Wouldn't just that make it so that as the score increases the method gets played over and over again?
presumably you'd call TryMilestone only when your score equals the milestone score
you could also just calculate a new milestone score whenever you reach a milestone
hello! if i setactive to false one object then seti it true acaig, will it restart?(like the scripts, will they execute the start function again?)
No.
Start runs once.
OnEnable runs many times, though
ok thanks
I mean that's what I intend to do anyway
in that case you don't have to check for duplicates at all
I mean only at certain points it would recalculate like at 1000 pts it would change the milstone from 100 to 250
something like that
and can i call script functions from other scripts while the gameobject is not active?
it doesnt
yes you can call a function on a non-active gameobject. or what do you mean?
it didnt work for me. i found another way
Another way to call a function? Show what you were trying. You definfitely can call functions on inactive gameobjects.
Calling a function works fine. Find does not
this is the settings script
Get the reference first
In general you should probably just avoid any and all functions with the word "Find" in their name
if you're doing it in update, yes
or doing multiple find operations in a single update
in general you should never use any Find() method, there might be some special uses in Awake() or Start() only for singletons etc
no im only using it in start or other events
imagine you change your object name in hirearchy
and your scripts doesnt work
Find() type methods are terrible - dont use them
is getcomponent also bad to use often?
What is an alternative?
Yes but there are special circumstances where you're probably going to call the function. It's not as terrible as find where you'd search the entire hierarchy or children of a transform etc
and what could i use instead of this?
i googled it and the best way its to just use [SerializeField] Transform . GetChild is also bad apparently
Properly reference where you can and use it as less often as you can - physics callback methods would probably be a valid scope to use get component.
serialize the field and drag the reference, the object is already its child. Find method is unnecessarily brittle
alr
is anyone here able to look at this rq
i dont understand the question here, can you explain
there is a white space in between "objectives" and the actual objective, which would be fine but when I try to register that objective as completed, it thinks that the objective is in that white space
if that makes sense
Is there a better solution as this script?
using UnityEngine;
public class SoulFragement_Anzeige : MonoBehaviour
{
[HideInInspector] public int SoulShards_collected = 0;
}
I mean its really everything needed.
I have 30 scripts that needs to interact with this integer.
better to do what?
maybe a premade parameter conponment that I dont know about?
what are you trying to do exactly
could look into props
So you need several components to be able to share a value.
use a SO
using scriptable objects for sharing mutable data is fun, but can also very confusing for the inexperienced
true
I think what you're doing is reasonable.
yes.
and making a script for just 1 line of code seems a bit out of place of everything other script does the work and this script is only there to contain a simple integer where every other script can have access to it, no matter if some other scripts get destroyed together with the gameobject.
I'm still kinda confused on the issue sorry
There might be a better place to store the value, of course, like on a "player" component
if only players can have soul shards
if a gameobject gets collected by the player, it access the script, make "SoulFragement_AnzeigeSCRIPT.SoulShards_collected++; and destroys itself.
sounds like you have an extra object in there, then
i think problem is description
description might have the extra whitespace?
ooh that's true one sec
it doesn't appear to have one
oh wait
wrong screenshot
but still
how do u get your list looking like that in the inspector?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(fileName = "New NPC", menuName = "NPC")]
public class NPC : ScriptableObject
{
public new string name;
public string[] messages;
public string[] objectives;
}
custom class
its just a string[] though. or is that what it looks like in the newest unity version? i havent tried
how do I post my code like this format ?
are those rich texts? whats with the sprite tags
!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.
so i can use a coin sprite
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour
{
[SerializeField] private float moveSpeed = 7f;
[SerializeField] private GameInput gameInput;
private void Update()
{
Vector2 inputVector = gameInput.GetMovementVectorNormalized();
Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
float moveDistance = moveSpeed * Time.deltaTime;
float playerRadius = 0.7f;
float playerHeight = 2f;
bool canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDir, moveDistance);
if (!canMove)
{
// cannot move towards movDir
//attempt only X movement
Vector3 moveDirX = new Vector3(moveDir.x, 0f, 0f);
canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirX, moveDistance);
if (canMove)
{
// can move only on the X
moveDir = moveDirX;
}
else
{
// cannot move only on the X
// atempt only Z movement
Vector3 moveDirZ = new Vector3(0f,0f, moveDir.z);
canMove = !Physics.CapsuleCast(transform.position, transform.position + Vector3.up * playerHeight, playerRadius, moveDirZ, moveDistance);
if (canMove)
{
// can move only on the z
moveDir = moveDirZ;
}
else
{
}
}
}
if (canMove)
{
transform.position += moveDir * moveDistance;
}
Debug.Log(moveDir);
float rotateSpeed = 10f;
transform.forward = Vector3.Slerp(transform.forward, moveDir, rotateSpeed * Time.deltaTime);
}
hello guys, so I am following Code monkeys complete tutorial for beginners and although it's fun I have a problem with this code, i have been trying to fix for a bit now (1 hours ish and its driving me crazy)
entire class does not belong inside Inline
use the proper sites
I mean
tehre is a few extra }
and lines they are just irrelevant
to problem
and discord has caracter limitqs
so couldn't past whole code
put debug.logs like Debug.Log($"Objectives String:\n{objectivesString}"); and check UpdateObjectivesText for example
print them all
basically whenever my character moves, it does a complete U turn before turning
so you decide how to share code? thats not up to you to determine
its annoying to read on mobile and line numbers/formatting
okey I am sorry
use the sites linked..
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
also share the tutorial because you probably copied it wrong
💬 This was a ton of work to make so I really hope it helps you in your game dev journey! Hit the Like button!
🌍 Course Website with Downloadable Assets, FAQ, Related Videos https://cmonkey.co/freecourse
❤ Follow-up FREE Complete Multiplayer Course https://www.youtube.com/watch?v=7glCsF9fv3s
🎮 Play the game on Steam! https://cmonkey.co/kitchencha...
timestamp : 2:14:00
I tried with and without f in the Vector3 though as expected it didnt change anything, I thought maybe the problem was that when I put moveDirX or Z the normal value of the vector is no longer 1 but it should have made an error for him too / didnt work when i tried to fix it in the transform forward
ty for the help, it was an issue with how i was placing the new lines \n
can you record a video of your issue
also are you sure the pivots are correct
should be, I didn't invent just copiing the code then pausing to understand what just happend
(video is loading)
should isn't certainty be sure
well i double checked in the video its the same code for pivots, but I do think problem is with them
" transform.forward = Vector3.Slerp(transform.forward, moveDir, rotateSpeed * Time.deltaTime); "
I think problem is in this line
just don't know how to fix it
yeah code monkey writes kinda bad code
well he for sure claims a lot that his code is good practice and game publishing worthy lmao 🤣
he said it like 10 times in the first 2 hours
yeah and im the president
world
nice
select the player object with the movetool and check the scene is set to Local Pivot
its in the upper left corner
I dont have unity open rn
hopefully its not in center mode and got all offset
what does that mean ?
and yeah it's in Pivot Local like shown here
Thank you btw :
can you show it with the movetool on the player object
Yes, video loading
oh ok screenshot would be fine
ok i stopped the video ( i have bad internet)
but basically with this I did a test and it still doesnt the same thing
can someone help me with a problem I ran into. Lets say Gun1 has 10 bullets and Gun2 has none. When I switch to Gun2, I can shoot only one bullet as if it registers the weapon switched when I click. Ill send the scripts
pivot looks okay
thats the weapon switch script
what about Player itself
not PlayerVisual
thats the gun script
same
thats the player shoot script attached to player
wouldnt it have made more sense making 1 message with all the scripts instead of this scattered thing
look how far the mesh is from the main object pivot
all you need to do is reset
sorry lol
the position of the PlayerVisual
after he does smth I pause the video and mess arround to understand more
and i forgot to put the visual back
my bad
good evening lads
its fine, is it fixed?
would you be able to take a look at the messeges I sent
I agree, but gotta start somewhere 🤷♂️ and his course is a bit entertaining
but if you have any recommendations I would love to have them !
and i will do them as soon as finished with this one
I would browse !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Noted, will do ! thanks again
which one you sent many
Lets say Gun1 has 10 bullets and Gun2 has none. When I switch to Gun2, I can shoot only one bullet as if it registers the weapon switched when I click. Ill send the scripts
https://gdl.space/sihomagiro.cs
thats the gun script
https://gdl.space/udosukiled.cs
thats the weapon switch script
https://gdl.space/zugubohofe.cs
thats the player shoot script attached to player
Figure out why it can still shoot
#💻┃code-beginner message
Can someone enlighten me with how the t argument from the color lerp works? I want to have a fixed transition time between two colors in my game
https://unity.huh.how/lerp/overview
incase you write it with time.deltatime this explains more why people write it wrong when using thathttps://unity.huh.how/lerp/wrong-lerp
t should be a value that goes from zero to one - not a fixed value.
Mathf.PingPong returns a value that "ping pongs" between 0 and the second argument
based on the first argument
so 0 -> 1 -> 0 -> 1 -> ... here
I don't know how I would check if it happened at the same time or delay
Put a log in the on disable callback and see if it prints
move your subscribe
PlayerShoot.shootInput += Shoot;
PlayerShoot.reloadInput += StartReload;
to OnEnable
and unsubscribe in OnDisable
also here
foreach (Transform weapon in transform) {
if ( i == selectedWeapon )
weapon.gameObject.SetActive( true );
else
weapon.gameObject.SetActive( false );
i++;
}
add Enable disable of Gun script
Pseudocode progress += Time.deltaTime/duration color = lerp(initial, target, progress)
Implies that the default duration should be 1f
Ok, I'm starting to understand, but I need more studying it appears, having trouble comprehending

think of t as %age complete where 0 is 0% and 1 is 100%
so saying that value traveling from 0 to 1 is the time it takes for it to switch colors?
yes
it's how far you've transitioned from the start value to the end value
t would be the percentage of transition between the first and second
Where the first and second are constant but t accumulate towards 1 (100%)
So lerp has to be in an update function for it to work smoothly?
or a coroutine
For example, using age years += ... age = lerp (child, elderly, years)
it prints
Lerp gives you a value between two other values. That's all it does.
A common misconception is that calling Lerp once will make something "move on its own", or otherwise smoothly change over time.
If you smoothly change the value of t and repeatedly call Lerp, the resulting values will smoothly change over time as well
do it in Update, do it in a coroutine, do it in a method that something else calls from their Update, do it in FixedUpdate...
void Start() {
foo = Mathf.Lerp(0, 1, bar);
}
This will set foo exactly once when Start runs.
it's no different, conceptually, from just doing
void Start() {
foo = 0.5f;
}
I'm having a hard time implementing the last step. I made a gameObject to attach the script too, but when I I do
else
weapon.gameObject.SetActive( false );
GunScript.SetActive(false );
I get an error.
weapon.GetComponent<Gun>().enabled = false;
The conditions are true so the object to shoot for the gun will still occur. As to why it's not Gun1, I'm not sure because we weren't shown when you logged Gun1
Only Gun2 should ever log according to your code
no, because all guns are always subscribed to the events set up in Start
private void Start()
{
PlayerShoot.shootInput += Shoot;
PlayerShoot.reloadInput += StartReload;
}
I changed this to onenabled
well repost your latest code
foreach (Transform weapon in transform) {
if ( i == selectedWeapon )
weapon.gameObject.SetActive( true );
weapon.GetComponent<Gun>().enabled = true;
else
weapon.gameObject.SetActive( false );
weapon.GetComponent<Gun>().enabled = false;
Debug.Log("switched");
with this I get an error with the " weapon.GetComponent<Gun>().enabled = true; "
so the Gun script is not on the weapon gameobject?
it is
also you will need to add braces
I added them and now I don't get an error. When I switch from Gun1 to Gun2 it prints " Gun2 " and if I switch back it prints " Gun1 " . If I switch from Gun1, the script(Gun) attached to Gun1 disables, but I can still shoot only once
so show your latest Gun script
guys a simple question. is a ray every frame bad? like 5-6 rays per frame would cause noticable lag?
Rays are cheap
a ray is just a struct, extremely efficent
you mean Raycast ?
Now read what I initially wrote
yea that
oh ok thanks
i'd be doomed if 5 raycasts per frame made your game lag
i underestimate a computer's peformance. coming from a guy who used to own a intel 4gb ram mac
i mean this one isnt much of a upgrade either but yea.
4gb, my first computer had 4k
should focus on the higher dips in FPS like Poly count, poor LOD, Post Processing, Batches etc.
yea i do that . tho i need to know more about post processing. ill check up on that later
Thanks for the help about color lerp, everyone I'll just continue tomorrow as I'm still having problems trying to apply it to my game
https://gdl.space/vidacozafa.cs
is this what you mean
what are you trying to do with it ?
I said UNSUBSCRIBE
Simply transitioning from one color to another that is triggered by an if condition
then I would transition the same colors again vice versa from another if condition
oh so jjust get rid of the ping pong ?
I did, I tried a coroutine and it felt weird, especially the color transition wasn't there, but I think you mean I would just put Time.time as t?
here shows how to correctly do color lerp
im super new and i just closed my hierarchy where did it go 😭
not a code question
The Unity Manual helps you learn and use the Unity engine. With the Unity engine you can create 2D and 3D games, apps and experiences.
where do i go to ask this question
how would I do this
also just reset the layout if you're confused
Oh thanks a bunch!
well if
PlayerShoot.shootInput += Shoot;
is subscribing
what do you think unsubscribing would look like?
ahhh I got
i.e the opposite of += is...?
Also wished I could have understood how lerp worked better to not trouble all of you trying to explain it me that much lol

no worries! its confusing at first , but if you think of it like it was suggested where it just represents a % between 0-100 it start to make sense the more you use it
I see, thank you so much again for helping me out!

no problem 🙂
Now I have a fully working raycast and I think I should had better used a trigger with a 1.5meter long invisible collider in the middle of the camera...
Because I have some hiding spots that uses triggers and colliders and it seems that the invisible triggers and colliders does block the raycast and I cant collect items in a wardrobe.
You can layer mask the raycast
but on what exactly?
what layer does the gameobject with the raycast script need? it seems just every collider or trigger blocks the raycast.
you use the layermask to hit the objects which are on the layers you want or to exclude the objects on the layers you dont want. Your choice
but how can I tell it to pass though the object with the wrong tag?
not tag, layer
You don't, you use layers
raycast are physics so they go by colliding with each other through Layers
its what helps control interaction between physics object
So say I had this weapon in the players inventory that gains more damage when an enemy dies. The only way I can think to do this is for the enemy to create a reference to the player, and then when it dies, see if the players inventory contains that specific weapon, and if it does, change the stats of that weapon. I feel like there has to be a more efficient way to do this, but I can’t think of any.
I dont have any layers included in my code.
Only one "selection.CompareTag"
the layer parameter is in the Physics Raycast function, it helps "filter" what to hit
do you even know what a Layer is?
hi everyone i've spent 3 whole hours trying to leave the code intact while still adding a new variable that controls how intense the speed of each planet slows down when it gets closer to the planet with + 1 index than the current index and speeds up when getting further, i was hoping someone here could give me an idea and end my suffering. Here's the working code without the desired behaviour i said above:
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
define speed...slows, rotation? movement? Cheese production?
Cheese production please.
||Position||
can't slow down cheese production, the goats don't like it
how can I tell it to ignore every layer besides "walls
I cant see anything with a string name that says whats the layer name.
You create a layer mask
only confusing stuff "int layerMask = 1 << 8;"
dont worry about bitmask rn use layermasks
whats confusing about that
[SerializeField] private LayerMask whatToHit
int 1 is smaller, is smaller than 8. why 8? IDK....
nah those are bitshifting
< is smaller, << is something else
modern day child devs, not a clue what a bit is
Okay there's plenty of people who don't understand basic concepts but this one is actually a pretty complicated bit of syntax and functionality
they're here to make a game though not general hardware/software knowledge..
give them a slack
It's a bit unfair to give that response about bitmasks in beginner code
agree, they are confusing already as is let alone in beginner gamedev
Is there a way to like broadcast a signal and then any classes with specific code to take that signal can then say, execute a method?
That, my friend, is exactly the right question to ask.
hi everyone i've spent 3 whole hours trying to leave the code intact while still adding a new variable that controls how intense the speed of each planet slows down when it gets closer to the planet with + 1 index than the current index and speeds up when getting further, i was hoping someone here could give me an idea and end my suffering. Here's the working code without the desired behaviour i said above:
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Let me guess, events and delegates do EXACTLY what I just described
Yep. Incredibly useful. You'll start to see the use cases for these everywhere once you understand em
Awesome, thanks
how to only change rigidbody2d velocity y vector
I've studied events and delegates in C#, how to they differ in unity?
they dont
Ah so the title of the video was for more practical uses in Unity then?
Hey, not really a coding question but i'm using the Super Character controller, but it's not working as expected, the character moves but only forwards and back, and moving left or right moves the camera, In the scene if i move the character around the camera seems to be attached to the player but in game it is not. I would like the camera to follow the character and mouse movement points where the character should be walking
Unity has it's own implementation UnityEvents and UnityActions but basic c# ones work even better
Ah, I see thanks
u can get individual axes with Vector2.y so just assign that
Mario in a summer shirt
it seems that the "actual" player is not aligned with the model
and the camera seems to be acting like first person???
it has a function to tick either first or 3rd person... strange
it's betetr once i align it with the model but the camera still doesn't follow the character
@polar acorn so I think I understand delegates, I just had a question. Should I have a script that only holds delegates, like a sort of delegate hub script to make adding methods to the delegates easier?
You could, but it's probably better to define the delegate on the thing that has the event
Since it's the thing that needs it, it's nice to see them all in one place
but there's no real performance or anything ther
Firstly you will need a tupple array the same length as planets
(float prev, float next)[] planetDistances
so you can keep track of the distance per planet from the previous and next planet in the system
and maintain this in Update.
Let me know when you've implemented this
Ah i see, so I should declare it on whichever script activates the delegate?
hey guys, is there a way to integrate Dali Ai into unity? Want it for a game as an image generator
experimenting with generative ai in 2d games
if it has an API then why not..
most stores ban AI like that though so you cannot earn on steam at least
oof
var velocity = rb.velocity;
velocity.y = ...
rb.velocity = velocity;```
It was really confusing but I finally figured it out what you meaned by this. thanks.
good stuff!
@silver sun Actually forget what I said
Your best bet is to scrap your planetSpeeds array and implement a Planet class containing the following
Transform
Speed
DistFromPrev
DistToNext
and then you can implement simple methods to maintain these values
so that you can pass the transform of the prev and next planets into a method and use the transform to calculate the distance between them
why can i not use transform.position like this?
what's the error
because it's a property
Position is a property and not an actual field
properties are just fancy methods 🙂
should be capitalized though
I know right
so i need to declare a new variable and change position by the variable?
yes
did you look at the link I sent
it explains the fix too
and then set it back
yeah
When you attempt to access the y component of the position property, you end up calling the getter that returns a copy of the Vector3 struct. Modifying the copy will not affect the actual backfield member of the property.
how do I send a whole unity project for someone to test with - I have a really weird bug that someone couldnt fix even after I followed all of their suggestions and they suggested I send it to someone who can test it and find what could possibly cause said bug
Assets->Export / Assets->Import
alright thanks!
someone know why the font like this?
this is a code related channel
how can i limit rigidbody.velocity without clamping it and can i limit only vector3 x and z values
plz help
you can adjust teh x and z values seperately..
combine them all together and then pass a new vector
remove the Y component, do your clamping, and then put the Y component back in
or that ^
horizontal = Vector3.ProjectOnPlane(vel, Vector3.up);
vertical = Vector3.Project(vel, Vector3.up);
// do something to horizontal
vel = horizontal + vertical;
not sure how one can limit it w/o clamping it tho
this would work with any axis, not just the Y axis
even if u wrote ur own if()else() conditional to stop it from going over or under, thats still a clamp
useful if you want gravity to change directions (and just more pleasing to look at, IMO)
or clamp whatever will work
i need to try making a game with tons of gravity shifitng
Normal. As its name suggests, Text Mesh Pro uses meshes to display your text. And to display a mesh you need a material, and to render a material you need a shader. They are the two things that appear when you expand the font asset. The converter creates a SDF (signed distance field) shader, and a material for your font.
The material preview looks really funky because it's not exactly meant to be drawn on a sphere
ty
Also, if you're curious, those two things are sub-assets
similar to what you see on an imported model
so how to solve it?
Solve?
There's no apparent problem here
Or you forgot to add it in your original question!
It doesn't count it as a font
What makes you say that?
What steps did you do to create that font asset?
I downloaded a font from the internet, did font assess creator and put it in the file.
are you sure it was the TMP one ?
screenshot it
YUP
also not really code issue 😛
Your font doesn't have the same icon as the one in the TMP_Text right now. It should also be the blue "F", instead of the generic scriptable object icon.
When creating the font asset, did the utility display any errors?
ok ty
Also what's the extension of the font you downloaded? And optionally make sure its license allows embedding it in software
i have this code that gives 2 rawimages a render texture. is there any way to make the first one remain the same after assigning the render texture to it? bc if i move the camera right now both raw images modify
you're assigning the same texture ofc its gonna modify them both
store it inside a variable?
what kind
Texture ? RenderTexture ? w.e u want
probably better to store it as RT if you need to do RT specific stuff after without having to cast from inherited Texture class
if you don't want the first image's contents to change..don't change them
i tried this and it is still updating
just reassigning variables does nothing