#๐ปโcode-beginner
1 messages ยท Page 377 of 1
UnityThings โข๏ธ
Ah maybe that
actually, that might not even work either
If you want to continuously rotate a rigidbody use MoveRotation instead, which takes interpolation into account.
for some reason, this works in Update to make smooth rotation.
I agree the docs disagree
but this is Unity
It will be a lot better than trying to set the transform's rotation when the rigidbody is set to interpolate
since that causes you to fight with the rigidbody
uhhh it works now
private void HandleMouse()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.fixedDeltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.fixedDeltaTime;
cameraLook.y += mouseX;
cameraLook.x -= mouseY;
cameraLook.x = Mathf.Clamp(cameraLook.x, -85f, 85f);
cameraHolder.localRotation = Quaternion.Euler(cameraLook.x, cameraLook.y, 0);
}
private void Update()
{
HandleMouse();
}
well that's just wrong
you should still not have deltaTime on inputs
you're using fixedDeltaTime in a method you called from Update
and it's still wrong to use delta time at all
just get rid of it and divide your sensitivity by 50
also, note that this is exclusively rotating the camera holder
it's not rotating the rigidbody at all
so your player isn't going to turn to face the direction you are looking
yuh ik
i can only do so much to stop you from doing objectively wrong things here
remove fixedDeltaTime and adjust your sensitivity
i did that
hi i have wierd issue, i am using TextMeshPro i added font, when i create new material from default shader and color it green it works, but when i rename that material cuz i dont want to hav SDF 1 2 3 45 i want to have greenOutlineFontShader, when i rename it i cant select it as mterial in textMeshPro in inspector, wtf? it all works until i rename it
I love Unity's "Do as I say not as I do" approach
Any noobs in USA timezone interested in teaming up with other noobs for a small project?
!collab
We do not accept job or collab posts on discord.
Please use the forums:
โข Commercial Job Seeking
โข Commercial Job Offering
โข Non Commercial Collaboration
ty!!
anyone tips to learn coding in unity i find that most tutorials write the code and let you copy it and i want to learn how to do it
!learn
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
Roll-a-ball tutorial
yeah same problem
also some https://www.w3schools.com/cs/index.php goes a long way
i followed the roll a ball tutorial but they give you the code
and you can't figured it out on your own if you try
some of the vids are bad at explaining the code
yeah but had it with some unity learn things to
check the stuff pinned in this channel
Imo this one is really good
https://learn.unity.com/project/beginner-gameplay-scripting
explains both Unity - specific functions and regular c# stuff
Theres plenty of simple and easy ideas which you can code to ur own imagination
np. All you need is the very basics on how to read c# code, the rest is literally reading the documentation
docs explains(usually) what each function in the API does
yeah i checked visual scripting out to see some functions to XD
and other things
didn't knew before it stood in the docs
does someone recommend some good books to learn from?
but i can read the code i find that simple but to make it yourself idk where to start
hey mention a few books. But these are probably stuff you should worry after you learned how to do 2+2 on the computer
to make it yourself you think of what you want to do then lookup the functions you need through the docs/googling
I dont understand whats wrong
never thought of that really but now you say it it is really dumb of me
!cs
Join the C# Discord server, a programming server aimed at coders discussing everything related to C# (CSharp) and .NET. https://discord.com/invite/csharp
this is a unity coding channel
ty
is this look wrong?
in the beginning it feels overwhelming and you have to like "memorize" stuff but its not like that
i installed the unity plugin on visual studio code but i still dont see like the recommendations idk how to explain i am dutch XD
what are you trying to do?
it doesn't look inherently right or wrong - although those variable names are pretty bad
oops
did you follow the setup steps ?
Geeft niet. Microsoft hebben ook instrukties in het Nederlands
im having a player manager that couple with PlayerStat/playerweapon/playerinventory/etc. and when a script that needd value from another script i get it through player manager just afraid its gonna be a noddle of coupling ๐
i can understand english a little bit ;D
placeholder for testing stuff
but makes it more difficult
Why is it named Stat6 instead of what that stat actually is
numbering stats 
just placeholder ill define each one when im theree
just want to know if this is a good practice or i can do something else better
simplify it with scriptable Object and you dont have to worry about coupling much
accessing something many layers deep isn't necessarily coupling
just high level abstraction
If anyone has a tutorial on implementing Steam achievements using Unity VS, can you ping me?
does SO only to contain data do i want to define method in there for anyreason?
SO can have methods
think of them as a fancy static class that unity treats as an asset of sorts
i get this message should i install this for unity?
ah yes, absolutely
when you install .NET SDK restart your PC (very Important)
hmm it does make a whole lot clearer to think them as static class
thank you
well do you have a 64 bit os lol
nah you gotta do it iirc
iirc?
if i recall correctly
hi everyone. i made a quiz game. everything works without problem when i run game in unity. But after i builded my game, game doesnt work correctly. (questions are not showed when game started). What should i do i dont know what could be problem is? As i said i can still play in unity. but build not working right.
Is it just UI ?
but first I would check any console errors in build, you can use onscreen console or devmode
I think the question must be showing but in it must be behind the background
Yeah check the player log file in a development build.
thanks guys i will try it
Try to add ur phone resolution in the editor and try playing in that
When actually does OnAfterDeserialize work? I was watching something and the dude switched the item on a database scriptable object and it updated itself?
I read the docs I did not understand why it happened
https://docs.unity3d.com/ScriptReference/ISerializationCallbackReceiver.OnAfterDeserialize.html
It executes immediately after Unity finishes writing serialized values into the object. This means that Unity has created the object and filled in its fields.
I'm guessing it's being used to set some non-serialized fields
this also explains https://docs.unity3d.com/ScriptReference/ISerializationCallbackReceiver.html
private int currentHealth;
[SerializeField] int maxHealth;
you might want to write maxHealth into currentHealth after deserialization
and yes, the page for ISerializationCallbackReceiver explains what happens
It's a good way of rebuilding Dictionaries without using 3rd party tools
Yeah he is using dictionaries inside
OnAfterDeserialize is the very first moment you can safely use the serialized lists to build the dictionary
Doing that in a constructor would be too early.
so onbeforeserialze splits the Dict into 2 Lists and onafterdeserialize reconstitutes the Dict from the Lists
all right thanks.
if i write Co i should get console but it doesnt stand here
did you actually make a Console application?
just making a cs files does nothing
You need the assemblies and such
no you shouldn't Console is invalid at that point in the script
create a script from unity then double click it, you will find all the Unity ones (hopefully)
make sure its all setup in External Tools
nicee
nvm XD
regen project files too , it might
i had 2 visual studios on XD
i see it thank you so much this is going to make it easier
it really does
nahh that just means your brain unlocked a new achievement 
XD
damn i am learning so much now so quick XD
asked chatgpt what void meant now i am reading his code and trying to understand it what you said earlier
i learned about recalling an event to idk how to explain it
oh god learning through chatgpt is pretty bad
at least as beginner is not a good way to start, it will mislead you
or show bad habits
oh okay i wil not use it ๐
well for learning
trying to make smth simple so i am asking for a really simple game idea
yeah use it for other stuff , learning aint one of them
Are you dutch?
damn
no he answered to me i am XD
Nope
oh leuk om een nederlander tegen te komen
zeker XD
here some simple game ideas.
Pong, breakout, Angry Birds, Flappy Birds, Spelling Game etc.
make a 3d version of them
Flappy bird is always a great first project . . .
then i am going to start with flappy bird
i learned blender so i can make a cool model ๐
angry birds gets no more love ๐ฆ
I have this function connected to an Input Field, but the input doesnt change when I hit enter... what am I doing wrong?
I'd say do that, then Galaga or Gradius clone . . .
thank youu!
they removed the first game and are making bad sequels ๐ฆ
and i need to make multiple maps and a physics engine
its still fun to make in unity, all you're doing is playing with physics
playing w/ physics never get boring
yeah true
i can go make angry birds to
is procedural generation hard in unity
prob yeah XD
because otherwise you need to make a lot of levels
Quaternion.Euler(x, y, z) Appears to be setting rotation in world space. Looking through the API I'm not finding how to change the rotation based on the parent
or 1 level XD
ohhh okay... I hadnt picked it from the dynamic part ^^;
just make 3-4 levels but harder on each one lol
world or local space will depend on where you are assinging the result to
use transform.Rotate
im going to make one model and that is the red one XD
oh really simple models just a sphere XD
use primitive shapes in the beginning, put graphics later
I'm trying to assign the rotation within the Instantiate method
then you want the yourTransform.localRotation ?
this is more question of #archived-game-design
well going to be diffcult to include the main mechanic which is swiping / holding left to charge a shot . how would one even do that in fpv
yeah okay XD
But localEulerAngels() can't be used as a method
yes, beacuse it's not a method
it's a property of Transform, and you read and write it
is there any way to round numbers into a small decimal instead of an int? like, rounding down 3.14 to 3.1 instead of just 3
unity's Snapping.Snap method can do that
also eulerangles is not a quaternion
which is what instantiate wants
Do you need to actually change the number, or do you just want to display it with less digits?
I want to change it yeah
lemme try that!
Start with a simple idea and create a to-do list of the games' features. Don't feature creep or do anything big
I got stuck working on a custom inspector for a package and haven't touched Unity in months. Now I'm (trying to) learn C++ . . .
Hi! (im back ;,)) I've been trying to make the attack point for my player character to be shaped to a polygon collider but it keeps saying that "no overload for method OverlapCollider takes 2 arguements and I've gone thru so much documentation and trial/error but am still very stuck.
code: https://gdl.space/ikabidarid.cs
thanks for any help in advance!
documentation? doubt
please i swear
https://docs.unity3d.com/ScriptReference/Physics2D.OverlapCollider.html
There isn't any form of OverlapCollider that takes only two parameters
I want to tryQuaternion.AngleAxis(180, Vector3.up) but I have a feeling this will be in world space and not local
did you look at docs of Physics2D.OverlapCollider
I mean idk that has nothing to do with what I suggested lol
You mean now that digiholic linked you
so where did you see it takes 2 parameters
also is IDE even configured?
pretty sure it shows you what signature is
But what you suggested doesn't work with the Instantiate method
yes it does
yeah i got it working
So, if you looked, then you know that it doesn't have a definition with two parameters. Why are you trying to input only two parameters . . .
how... would I do that with snapping? the scripting API isnt really helping and there is literally nothing else online q.q
I have my doubts lol it shows you inside the code editor what the 3 parameters are.
so you either are not paying attention or its not configured to help you
im very new to this, i didnt know what that meant
im trying really hard to pay attention i didnt understand
if you dont know something look it up.
"what is parameters in function" etc
Try breaking down the error message. It says no overload for OverlapCollider takes two arguments
You can lookup c# overload and c# arguments if you don't know what they are . . .
ok thats fair
i really didnt mean to ask pointless questions i thought i was genuinely stuck
small part of yesterdays search history
either Snapping.Snap didnt work or Im dumb... any other suggestions, guys..?
found a way I think.
Quaternion.Euler(Transform.localEulerAngles + new Vector3(0, 90,0)); I'm guessing this is more of what you were talking about?
not at all
nowhere did i mention eulerAngles
i said Instantiate takes Quaternion instead of eulerAngles, not sure why you keep insisting on using that lol
transform.localRotation gives you the local rotation as Quaternion
show what you tried
I found another way
transform.localRotation = startWall I think I got it now lol
Where private Quaternion startWall = Quaternion.Euler(0, 0, 0);
Protip: Quaternion.Euler(0, 0, 0) can be written shorter as Quaternion.identity if you wanna clean up your code a bit
Question, how would i go by adding a portal like pick-up system, where the object floats in front of the player, but the item kinda sways to the players camera, not just following. So its kind of delayed?
is it better to check if the inventory is full in Update or everytime I add an object??
lots of ways - for portal though it'd involve something like setting the Rigidbody velocity towards the "holding point" in order to allow realistic physics interaction
Surely, every time you add an object. It's better for the performance.
Okay, thanks a lot
Ideally you won't even have an Update function for most scripts
Okay i'll try that. Something like movetowards?
No, setting velocity.
MoveTowards isn't a way of moving things anyway, it's a math function to calculate a position
Oh ok
Update is called every frame, so this will decrease your performance if you do all these things there. Aditionally, it's much more readable
thanks for this advice!
Doing nothing is always more performant than doing something. The more often you can manage to do nothing instead of something, the better
Im planning on making a crafting system similar to little alchemy (with drag-and-drop events) does anyone know how to check if the place where my object lands is in an specific area?
IPointerEnterHandler/ExitHandler and just store whatever the most recent object was?
one more thing: if you only check if your inventory is full in Update, anything that adds more than 1 item to your inventory in one frame will overfill your inventory
Somehow this Instantiate(walls[0], transform.TransformPoint( -2, 0, 2), transform.localRotation = leftWall); is causing the left wall to be spawned with a world position of (-10, 0, -2). The object that is spawn this wall has a world position of (0, 0, 0)
checking if it's full in Update is just flat-out wrong
Im using the IBeginHandler, IDragHandler interfaces but I dont really get if the object I drag should be an special class of objects that can be mixed or something
Okay, I see, thanks!
- Scale and rotaiton also affect
TransformPoint transform.localRotation = leftWall< you sure you want to be doing this inside the Instantiate call?
Seemed like the cleaner way to do it. Instead of instantiating it and then transforming it. Their weird thing is it only effects the objects rotated at 90 or 270. The objects at 0 and 180 have the proper positions
Have you actually looked at the Instantiate documentation?
but you're setting the rotation of the object the script is attached to as well as the one you're instantiating with this
is that intended?
I doubt it
can i make interface which requires index input
Hello, I ran into a problem I dont understand why it wont destroy the game object, I even put a log to see if I hit a wall and it prints when I do hit a wall but it doesnt destroy the game object.
- script to detect hitting a wall https://gdl.space/ujeqarajay.cpp
- script to destroy gameobject upon hitting a wall https://gdl.space/awexosivuq.cpp
Wait, so the transform.LocalRotation is changing the object the script is attached to and not the object that is being instantiated?
how do expect the HitWall varaible to be filled with anything ?
How am I setting the rotation of the object the script is attached to?
wait. This code wont even compile. is your IDE configured
transform.localRotation = leftWall assigns this object's localRotation to leftWall
or rather it assigns the value of leftWall to this object's localRotation
Hello, I am using https://github.com/CMDRSpirit/RollercoasterDesigner this package to make my one roller coaster. Sadly it is not very polished but I have one problem with it. When I set the StartSlope Variable it sets its own. (See Attached video https://drive.google.com/file/d/1CJEgclQS7Q3JbD32qIymqrm9aiU7Gspt/view?usp=sharing) Also when you try to make a vertical loop or any other loop it glitches out at makes it so you are not inverted.
I tried to get Chat GPT do help me fix it but that didn't work. I came to the conclusion that this line might be the source of the problem float3 startSlope = lengthsq(StartSlope) != 0 ? StartSlope : float.NaN; Here is the scipt https://pastebin.com/j957ybX3 and the GitHub project https://github.com/CMDRSpirit/RollercoasterDesigner
A toolset for creating and operating realistic rollercoasters in Unity. Includes per car simulation of forces, like rolling resistance and acceleration through gravity with full integration into th...
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.
and then passes that as the world rotation for the instantiated object
I don't understand what I'm missing here with the rotations
Should I just instantiate the object and then transform the rotation?
do you want the object with this component on it to be rotated whenever you instantiate something?
i wondered whats the proper way of getting something like that, i have big array of interfaces, and these have some field in them which i want make array of, do i just loop through each of them
No, I just want to rotate the object that is being instantiated
then why are you doing transform.localRotation = leftWall
Does anyone know how to do a drag and drop system like in Little Alchemy? (I reckon it creates a copy of the object that can be mixed right?)
you should prob explain for someone not familiar with the game
what makes it so special?
Oh okay sorry
Because I was trying to set the local rotation of the object that is being instantiated
as has already been pointed out, that sets this object's rotation, not the instantiated object. and then it passes that as the instantiated object's world rotation
the thing is it is a game in which you have an inventory with different items. Also you have a big space in which those items are manipulated. Whenever two items are mixed they are converted in something else (crafting)
this is how it looks
Yup, I see that. So how do I get this objects local rotation?
you cannot assign the local rotation in the Instantiate call, you have to do it after it is instantiated. so pass Quaternion.identity for the rotation, then on the following line assign the returned object's localRotation
I still dont understand how it works by looking at a still picture lol
Ill look it up hold on
Because you wrote transform.localRotation = leftWall
That's what that does
Yup, I got the answer now. Thanks
next time please read the docs and save yourself a lot of effort
ohh this is pretty simple in terms of UI
I searched the docs first and when I can't find the answer or don't understand I come here.
@ionic zephyr just use the event trigger basically to do an OnDrop or OnEndDrag
So you read the Instantiate documentation and did not see that rotation could not be set in local space?
Ive already created this inventory system I am stuck with the drag and drop stuff
well first thing to know is it UI or SpriteRenderer
you mean UI Images?
My inventory is made up of slots that have an Image and a quantity text
I used Grid Layout Group
https://docs.unity3d.com/2022.3/Documentation/ScriptReference/Object.Instantiate.html I don't see in here where is says that it can't be set in local space
so UI then. Canvas
Yeah, sorry
You can use methods such as these for example
https://docs.unity3d.com/2018.2/Documentation/ScriptReference/EventSystems.EventTrigger.OnDrop.html
I started using the IBeginHandler interfaces
yea
those are pretty much the way through event system
or just get raycast hits from the Raycaster directly , thats also an option
' If the position and rotation are specified, they are used as the object's position and rotation in world space.'
Maybe. The thing is that I dont really know how to program it since I dont understand if I should create a clone of the object in the inventary evertime I drag it?
It is difficult to explain sorry
Then that would mean that I can't set the local position either
only you know how your setup is and how an object is created
you said you already got the recipe part ?
not using that method overload, no
Not the receipt but the UI and the inventory collecting items system
but I dont know how to do this, I thought of making a DraggingItem component and make also a CraftableComponent for the objects in the crafting area but Im really lost
do you have a way to determine if its craftable or not etc.
the basic gist of it, I use scriptable objects to check recipies. I use the object being dropped on to call a "TryCraft" function or something
hi, i have a horror gave and i need the monster to shoot object, but i tried codes from youtube last few hours and nothing works, can someone help me please
"nothing works" are you sure you just didn't mess it up by copying wrong.
very unlikely multiple videos and "nothing works"
Hello there. I wanted to make my own little 2D Pixel Game for quite a while but im more like a designer rather then a programmer but im willing to learn C#. The Problem is, there are to many courses and guide and im not really sure, whats the best content for me to start this journey. For some more informations. I want to make like a basic demo of an 2D Pixel RPG and there for I want to make my own scripts with C#. Like an Inventory system and so on. Does anyone has a clue what content I could use of does anyone can recommend a C# course for a beginner? Greetings! ๐
!learn
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
start with pathways ^^
this goes for you too @tulip tendon
I thought of making the sprites of the objects draggable and if when I stop dragging the image it is located within the crafting area, Ill create an object with the Crafting component, which can be mixed with other objects
i edited some parts of the code, becose it gave me few errors, then th bullets just came out of nowere
does it sound logical?
Thank you but is it just about C#? I feel pretty good in the usage of Unity itself.
Also, do you know a way in which I could make sure a certain object is located within a certain area??
ok they have both but do look at the microsoft site linked
idk what that means, you have to show the problem and what you tried to resolve it along with what exactly you're going for
are the objects just UI representation of inventory items you have ?
@languid spire @rich adder Thank you guys aswell. I will take a look! ๐
yes
Im confused on that part
as you can see, the slot has an image, which is the thing I want to make draggable
oh ok so you dont know how to make it draggable ?
just set its position to Input.mousePosition in the OnDrag method or use Update
I do, with the interfaces, but I dont understand if I should make a Clone of the object
whenever it touches the crafting area
what do you need a clone for ?
because the images are just that, they dont have the function of being mixed with other objects
they don't have to, they can just be placeholders
but you do need some scripts to determine its craftable
so the sprite images and the crafting objects should be the same?
if the sprites do stuff they are no longer just sprites but part of the logic/mechanic
Okay, maybe its simpler that way
not a fan of working with UI myself but yeah you have to have a way to determine what you dropped on is a craftable object
I typically just have UI invoke an event to a manager of sorts
instead of dealing with the logic directly
could you explain this? Maybe its better of what I am thinking
so basically If I have a script on the UI image you can drag onto. this script just says "Hey something was dropped on me , Invoke this event with this value (the object that was dropped on it)
then the manager that was subscribed to this event does the logic, because each spawned item has this event so on creation just subscribe to it when Instantiated
So the crafting should be done on a separate manager?
Its mainly preference / workflow . I personally would do so
Okay really helpful
when chain stores get money , they count it (through machines that ring you up) but whos the one that does processing and payrolls pays everyone is the company that owns those stores
I also have a doubt, how can you check if an object is located within a certain area?
oooh, okay
thanks for the metaphore
I would just make a dropzone be an Image set to opacity to 0
this way all the UI event system work, like OnDrop
and you can resize it how you want through Canvas
Hello, is there a way to reset the entire scene without stopping play mode from within a script? Alternatively it would take longer but I would have to reset all the position, rotation, velocity, angular velocities of multiple gameobjects so
but what if I want to move the objects freely in the dropzone?
and also
how can I ensure the object is located in that zone
within those "borders"
You can check for example PointerExit the dropzone image if its holding an item already to "drop it" where it is
I think you might be jumping 20 steps ahead already ๐
oh okay
but what I am saying is
if I drop the object in the crafting area it stays there wating for it to be mixed
but if I place it outside i want to destroy that object
you can use OnEndDrag on the Sprite you're dragging
how do I ensure it stays there
if its not dropped on anything you destroy or whatever
but how do I know what "anything" is?
the Canvas Raycaster is always raycasting from your cursor, you can for example check if the raycast pointer is not on any UI elements of interest
how?
ill show you an example rq gotta load up unity ๐
IDropHandler has a parameter that tracks PointerData which contains the object dropped onto
basically this
I haven't used it in a while but PointerData should contain all the information you need
indeed
okay thanks dont worry
if I drop what Im holding onto "nothing" it returns where it was for example
How can I access it?
this is just what i need
You access it by implementing IDragHandler, IDropHandler, and other interface classes for pointer data.
Check out IDropHandler here: https://docs.unity3d.com/2019.1/Documentation/ScriptReference/EventSystems.IDropHandler.html
yeah, I already implemented those
yes exactly I use EventData
like ```cs
public void OnEndDrag(PointerEventData eventData)
{
var obj = eventData.pointerCurrentRaycast.gameObject;
Debug.Log(obj);
if (obj != null)
{
if (obj.TryGetComponent(out UISlot uiSlot))
{
SetUISlot(uiSlot);
belongsTo = BelongsTo.Slot;
image.raycastTarget = true;
return;
}```
for rigidbody 3d transform.position = new Vector3(transform.position.x, transform.position.y + 0.5f, transform.position.z); is it better to put it in update or fixedupdate?
neither. dont mix rigidbody and transform movement
how do i crouch then
just change hitbox height?
wtf has crouching got to do with movement?
Not sure what this code you've shown has to do with crouching or why the suggestion would preclude implementing a crouching system
It is not clear what you are asking
This teleports the object up 0.5 units.
You didn't state your requirements or goals, so there is no way you can be helped.
mb again but i think i solved it on my own ๐
I have both the shoot and movement script follow the cursor they both dependent on a variable named rotaionZ. First where should I put the script that gets mouse cursor rotation and how can I update it in both scripts?
It doesn't matter that both have a variable with the same name, they're two different variables
I have the gun follow the mouse cursor and check it the location is more that 90 degrees to slip the sprite. So it is the same variable but used in both the sprite slipping and updateing the direction of the gun
eventData.pointerCurrentRaycast.gameObject doesnยดt return the object in which I dropped my dragged object correctly
They're different variables with the same name. They both might even end up representing the same value, but they'd each need to be set independently. They don't "share" variables
does anyone know how to know where the object has been drop?
What did it return instead?
the object I was dragging
So it returned the object which was dragged
the same object I was dragging yeah
Get the objects position and it would be where the object is atm
you have raycast target still enabled on what ur dragging ?
thats prob why
I'm not sure what the issue is
this is the code
_clothBackground is the background of the interface
whenever I drop the object, the Raycast returns the object itself
did you see what I wrote?
yeah
do you have Raycast Target enabled on the thing you're dragging
if you don't turn it off, of course the first returned object is what you're holding onto
I have both the gun rotation updated and character flip in the same player controller script. But I want to separate the gun rotation from the player controller script to the shooting script
Oh my god, thanks
and when interacting (mixing as I explained befor) with other objects is it better to do it with RayCast or with Colliders and Triggers?
Okay, so they're the same script currently, but you want to split them. You'll keep this variable in whichever script the CursorRotation function ends up in, and have the other script reference that one to read its rotationZ variable
Now I cant drag the object
what I do is toggle it on and off
on when start draggin?
Okay I will try that. Thanks a lot โค๏ธ
And what if I use Colliders and Triggers?
if they are UI why are you using colliders?
Maybe Its better to create this system not UI?
Are crafting systems commonly created with UI? I really donยดt know
depends on your game
In my case is it convenient?
Also, speaking about recepies, how are they programmed?, I donยดt think it is writting a bunch of "ifยดs" right?
I use scriptable objects
Probably ScriptableObjects
It depends entirely on how or what you'd want to do with it. For example, you could evaluate combinations using a bunch of if statements, flags or whatnot. It's open ended.
or plain old C# objects that you serialize into a scriptable object
you might want to be able to handle recipes without needing an asset
I mean, I guess you can create non-asset ScriptableObject instances, but,
In my case in which objects combine forming another when interacting each other?
maybe "ifยดs" are okay?
Just make what you can
you don't want to implement the actual recipes directly in code
you want to write code that reasons about recipes
(which are just data)
not a big code monkey fan but this video kinda summarizes the whole process with Crafting using SOs
the thing is my items are objects
of a class
I didnยดt use Scriptable Objects
they are just for the recipe not the item itself
oh so those drag and drop objects should be Scriptable Objects?
just the crafting system and recipes, helps matching
the output can just be a GameObject or whatever u got
look over it and you will see
Okay, thanks a lot guys
Lerp in coroutine
for rotation you can prob use Slerp
https://unity.huh.how/lerp/coroutines
shows how to implement duration for example
or use a tweening library (if you already have a need for one or could use one in other situations as well, don't just download an entire tweening library for a single rotation)
ah yes Dotween can do this in one line lol
Oh ok
navarone, Im thinking of making the Image as a placeholder from which you generate the objects that go into the crafting area
and cloning from it
what is the 2d version of physics.CheckSphere
See how i get many instances of the "Earth" object? I think Iยดm going to make the image of the slot a "generator" of instances of a class "Craftable Object"
since 2D only has circle and not spheres..
You need to make a manager of Item amount
like quantity
i looked for any that sound like checksphere but for circles and stuff and there arent any that seem to check they just return either a list of colliders or the first collider
OverlapCircle
alright thanks
it still returns a collider, but you just null check that and that tells you if anything at all was found there
I have my VSC Configured for Unity but it appears my Quick Actions and Refactoring is no longer showing up! Any reason that may be? The only thing I can think of is variables that arenโt being referenced properly rather than an issue with VSC.
Or a mistake in proper inheritance?
i don't understand what you mean when you say you think it is "variables that aren't being referenced properly", but if your quick actions and other IDE related features are not working, then try regenerating project files and restart vs code. if that doesn't work, try reconfiguring it. and if that doesn't work then consider switching to a real IDE that isn't liable to break every 5 minutes
i want to start dev. games in unity, does it make sense to build projects wiht c+ first to have an understanding of the p language or should i just go straight unity engine
I appreciate it but not sure what is gained by that last part. One could at least specify alternatives.
Unity uses c# not c+
i meant c#* ๐
what are you actually trying to do that isn't pulling up Quick Actions properly?
there are three code editors that are supported by unity. one is jsut a code editor with plugins that make it act like an IDE (vs code), the other two are fully featured IDEs and a simple google search, or even just looking at #854851968446365696 would have told you they are Rider and Visual Studio
I think it will give you a great advantage in Unity to understand C# first. Yes
alright so i think ill start learning c# first, thanks
If you know the basics and are simply moving to the unity platform, you may be able to get away with just some !learn tutorials - api, workflow etc. Else you'll really struggle if you're trying to learn to program and use Unity at the same time.
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
oh yeah never noticed
Trying to generate override methods for a state machine. Just to save time. Nothing crazy. Donโt want to type them for each state but will if I need to.
add missing cases you mean? make sure you're doing it on the variable in the switch
Unity code chat help will tell you about how they know better and answer a question last.
if you're talking about implementing abstract methods, that should be a code action on the type name.
You can also type override and the start of the method name whil in the class, and it should provide you with a list of available methods to override
Unity code chat will completely misunderstand a problem, not bother doing any research, then get mad when someone else tells them something that they don't want to bother researching at all
anyone know how to fix failed to update android sdk package list?
You HAVE been answered. The very first reponse gave you an answer
There have also been questions to help clarify what you mean, which you ignored
hey so i want to use math.lerp to lerp a gameobjects rotation from where its at to 0 on all rotation axis how would i do that exactly
also check out this page for info on how lerping (or slerping) works: https://unity.huh.how/lerp/overview
it even has a link to a page that explains how to do it in a coroutine
aight thanks
Why isn't this working, It seems to not be getting past the if statements. https://i.imgur.com/B6lMjlb.png
The second if statement is the one with the issue
why are you comparing floats like that? you should pretty much never compare floats for equality, use something like Mathf.Approximately. but also why the magic numbers
What do you mean by getting past the if statement? Are there any errors or are you referring to the statements never being true?
Nope no console errors. The object just isn't rotating. Without the if statement they rotate just fine.
unless you set something to 24.938 aint no way thats gonna happen. Ah yess you're using quaternion as they were euler
Rotation would be a quaternion, so consider not to even bothering evaluating it.
oh yeah those numbers are way off for a quaternion, which is normalized
The object starts at 24.938
Oh ok
yes eulerangles and quaternions are different
and even if they were the values you see in the inspector for its euler angles, you should never base your logic on the euler angles like that since they are interpreted from the quaternion at the time you read them. and rotations can be expressed in a very large number of ways using euler angles
any idea how i can make it so it does that but rotates to look at the player?
https://gamedevbeginner.com/the-right-way-to-lerp-in-unity-with-examples/#lerp_rotation
just replace it with slerp
ok thanks
how i make class with lists that doesnt start as null
use a field initializer
i added = new List<string> to them next to class but they still output as null
i dont want manually activate each of them
wdym by "they output as null"? Show your code.
show your code
wwhen i create new followdata i want lists to already be done
that's what will happen there. the lists will not be null when you create an instance of that class
they are null
show where you are seeing that they are null
What makes you think that?
How do you setup dialog for multiple characters? Right now I have it ghetto rigged as a string in a script but what if if I want to reuse the same dialog system for other characters?
private string[] dialog =
{ "ใใใใกใฏ",
"The poor bell is jammed, it's like the heart of the town has stopped beating.",
""};
ok it was because i was confusing i with ii
Don't hardcode the array of strings, serialize it to the inspector and add it there for each NPC
Dialogue systems are complicated. A good first step is maybe make a ScriptableObject where you can store dialog and reference it from a character.
Oh smart, smart.
(though architecturally speaking, this isn't the greatest method, but just to answer your question)
also how can i make array of that class to autofill itself
That's a fairly simple way to go about doing it, thank you so much
define "autofill"
new followdata[] to have all in array not null
Assuming it's an array of a class, you have to populate it
for(int i = 0; i < followdata.Length; i++) {
followdata[i] = new Something();
}``` for example
so regular way
yes, the regular way
thought i maybe can add [notnullable] something
if it's an array of a struct, it will already bne filled with the default version of the struct, since structs cannot be null
but you should also note that structs cannot have field initializers
so struct will make it both autofilled and lists autofilled
so reference types stored in the struct, like lists will default to null
aw
arrays are always autofilled with the default value for the type
For classes, the default value is null
For structs, it's a zeroed-out version of the struct
oh i realized i dont want go by adds but by exact indexes
can i for example access 1000 index of list and it will auto extend to that range?
hmm so whats the best way for array of unknown length which i want to fill out with nulls in middle in some cases
answered here
isnt dictionary just list but double?
ah right using ints in non index way
the int would be an index in the example of Dictionary<int, MyClass>
technically called a "key" but it serves the same purpose
Hmm I'm stumped, my dialog system works for one character's interaction but when I apply the same thing to another character they refuse to speak lol
https://gdl.space/lifekeseni.cs
The problem is that it won't set canvasDialog.SetActive(true) for some odd reason
Oh here we go, I'm getting an error message now
read the full error - it will give you a filename and line number
on that line, you are trying to access a GameObject that has been destroyed
But I'm not destroying anything as far as I understand. I mean obviously I am destroying something but I don't get where that could possibly take place
Start with this
filename and line number
Read it, or you're flying blind and guessing
I'm setting it to false at the beginning manually but other than that there's no reference to it being destroyed
DID you do what I mentioned yet
read the error
you seem to be ignoring that part
and trying to skip ahead
you need to know the filename and line number where it's taking place. Without that, you're wasting your time.
There should be an error thrown every time someone doesn't read the error properly
but they would need to read that new error too which probably won't happen
Also do a find all for "Destroy" in your project files
it's likely due to a scene change not an actual Destroy call
true but you never know lol
sure, but i am also pretty familiar with their project at this point. but they still need to read the stack trace for the error to see where it is actually coming from
The error disappeared
A recursion that would result in a crash. A worthy punishment.๐ง
don't worry. if you did nothing to fix it, it will be back
Yeah I cannot replicate the aforementioned console error
I'm really confused how it's working for another character but not the one that was duplicated. I made some adjustments to address the null error but i'm pretty sure that won't fix it
private void OnTriggerExit2D(Collider2D collision)
{
hasEntered = false;
if (canvasDialog != null)
{
canvasDialog.SetActive(false);
}
dialogInt = 0;
}
have you actually confirmed this is the source of the issue?
have you looked at the filename and line number of the error yet?
Yeah I double clicked the console error and checked the offending line
and which line was that
canvasDialog.SetActive(false);
the one in OnTriggerExit2D?
Yeah
and how is canvasDialog assigned
Ok what oyu shoudl do then is this:
if (canvasDialog == null)
{
Debug.Log($"CanvasDialog was null on {name}!", this.gameObject);
}```
is this object perhaps a DontDestroyOnLoad object?
If I'm reading this correctly, no
This is a screenshot of the game running
anyway you may simply have a copy of this script on an object in the scene which is referring to an object you destroyed
I don't get how I'm destroying something when I don't have that call anywhere in my scripts
You say it works on the primary object and then doesn't on the duplicated one, have you checked the inspector to make sure everything is still referenced correctly ? and that the game object is active when you need it again ?
you should pause execution when that variable is null so you can inspect wtf is happening. you can use Debug.Break() to pause play mode. or just don't null check and enable error pause on the consoel
also, unrelated to the issue (probably) but you don't need separate components for "Girl Dialog" and "Boy Dialog" and stuff if it's just to display dialog. you can reuse the same component
Oh okay, let me go back to the drawing board and see what I can come up with, i'll try that Debug.Break() trick technique
As boxfriend said, you just need to create a prefab that you can instantiate when you need it and just update the text if its a simple dialog with no uniqueness
i mean, it doesn't need to be a prefab. just reuse the same component type, the copy with a different name does exactly the same thing just uses different values for its serialized variables
So I figured it out, because of the way I've implemented dialog system I actually need to have an empty string so that it can iterate upon it
huh?
I think the way I did this line
https://gdl.space/laxahizemo.cs
// When it reaches end of dialog/array, set dialog canvas to inactive.
if (dialogInt >= dialog.Length)
{
canvasDialog.SetActive(false);
// Reset dialogInt to 0 so you can speak to them again
dialogInt = 0;
}
i don't see how any of that would cause the error you were experiencing
Yeah I'm confuddled too
did you bother doing what i suggested and actually look at what is happening in your scene at the time the error occurs? or are you just taking wild guesses about what is causing it? because it seems like you are doing the latter
I can't, because the error refuses to reproduce
well yes, you're specifically preventing the error now. put the debug.break in the else statement with that debug.log call
what did you do before when it was throwing the error? do exactly that
don't tell me . . . was it throwing the error when you left play mode? and not during play mode?
Yes
maybe say that next time so that we don't have to go through all of this pointless debugging
OnTriggerEnter2D will be called when exiting play mode or leaving a scene when there is a trigger overlap happening in the scene at the time you do that
Oh that makes sense, well I'm glad we fixed it
so if you were exiting play mode while within the trigger that caused that OnTriggerEnter2D then it will call that method and because everything is in the process of being destroyed at that time you get that error.
for some reason unity said this is expected behavior and not a bug
I'm trying to make it so that I can pause and unpause the game using the escape key, right now pausing does not work but unpausing does, I don't understand why
this is the code
it doesn't even do the debug
This is the correct image
if I manually set gamepaused to true and the pause menu to active escape does work to unpause the game, but pausing does not work
I tried to just have the if gamePaused == true (for unpausing which does work) and placing the pausing code in else, same result
nvm I'm an idiot I fixed it, I'll explain how. The script was linked to the main menu, which is DISABLED by default. that's why the script didn't work. I attached it to Canvas instead not which is active. Might not be the best place to link it but it seems to work now
But also look at your logic
You set it to true right before checking if it's true
Yeah I noticed that right after, changed it into an else
I've got a fun new issue to deal with now ๐
Pausing using the escape key now works fine, but in ever level except the first I can't click my buttons
I didn't have EventSystem gameObjects in those scenes, seems to work fine now
Though I don't really understand what the eventSystem does, that it's needed for buttons but not other scripts
It handles all the UI interaction events
Gotcha, thanks!
How do I sync runtime frames with animation frames? For example, I have an animation that shoots a bow at frame 50 (in the animation controller) and I want to do something. However, this code executes faster than the animation
int frame = 0;
while (true) {
if (frame == 50) {
// do something
break;
}
frame++;
yield return null;
}
How do I do this without using animation events?
Without Animancer (paid asset), probably not easily without animation events 
Does Time.UnscaledTime or Time.RealtimeSinceStartUp work on application's internal clock or uses System's time as reference?
~~You're using a while outside of coroutines, this will cause the entirety of this codeblock to run within single frame.
Idk if animation frames are in sync with application's frame rate or not but just in case you can try to execute this inside a coroutine, and use yield return null; to seperate each frame inside the while loop~~
yep, thanks that was a typo I forgot to include it. However, the do something actually executes much earlier than animation frames, seems like they are not in sync
Yeah, i guess animation events would be the way to go then
I can't use animation events because if I have more "do something" (e.g. 1000), I would need to create 1000 animation events which is not feasible
You only need one generic "do something" event and the logic would be based on what animation/state fired it and what object receives the event.
Unless you have 1000 different animations that need different events..?
hey all, having some trouble right now with an editor window I'm trying to make, I have the MenuItem attribute set up correctly, as it works with my other editor window I've made before, but for some reason this one doesn't seem to appear in the window tab?
the "MarcLerp" editor window is my own custom tool I've made earlier and been using for a couple months, however my new one doesnt seem to appear :/
both inherit from editor window
Not a topic in familiar with but does #if unity editor have anything to do with it maybe?
Also on GUI
I have
using UnityEditor;
#endif```
at the start of each of them
You also don't need to wrap your stuff in that if you put your editor window/editor specific code in an /Editor/ folder
the reason I dont have it in an editor folder is because when I originally built the tool I was a lot less experienced, and now theres ~800 lines of code that can't be called from another monobehaviour if its inside the editor folder ๐ฅฒ
Bumping cuz got scrolled up. If anyone knows answer much helpful
if you can declare somewhere when you want this event to happen, like at 50% or 0.5 through the animation, then you can just try checking the normalized time https://docs.unity3d.com/ScriptReference/AnimatorStateInfo-normalizedTime.html
Or have a timer which runs at the same time you start the animation.
I use my own timer and it works well, assuming you arent taking into consideration stuff like transitioning which may cause your animation to not play fully. I define a total length which is how long the animation should play, then use another value (0 to 1), which indicates how long into the animation an event should happen.
That's why you seperate editor scripts and gameplay scripts 
problem is its an editor monobehaviour
like it only executes code in the editor
its for like positions and stuff
its super janky
https://docs.unity3d.com/ScriptReference/Time-unscaledTime.html
time in seconds since the start of the game
its made of sellotape
but instead of rebuilding it I kept adding to it and now its like a bomb inside my computer
well clearly not, if you said another monobehaviour is calling code on it
So if i blackout and change the system's time, and come back, it will say whatever time has physically passed regardless of what my system's time says?
I'm trying make line of sight in a 3d space. I'm trying to use a mesh at runtime to get a cone shape, however I don't understand the problem that is happening when setting the vertex positions. When the player moves, the origin vertex moves in a different direction than the player, the rotation of the mesh also does not follow the players rotation. I have very little experience with making meshes this way so I'm coming here to ask what I'm doing wrong with the meshes positions.
theres a monobehaviour that basically calls a function in the editor window when saving/updating data basically
i have no clue what "blackout" means in this case. Its literally just the time since the start of the game
Blackout as in don't close the game but just put it in background or minimize
Onapplicationpause = true if you will
I've noticed the first vertex will follow the player if I set it to Vector3.zero
So I thought it was using localPosition since the object is a child of the player
I get that by documents as well, question is does the time since start of the game get calculated via internal clock? Or does it refer the system's clock for calculation
why? maybe try doing it in reverse, have the editor window grab what it needs rather than being given the data. That'll be an easy way to not rely on such editor scripts.
Just curious, can you even build the game? EditorWindow is under UnityEditor
But using every conversion to world position I found online for the vertex didn't work when setting the position to the position of the object
im not sure how its calculated honestly or how it is affected in such case
Theres more information here but you might just wanna test that case you're asking about
https://docs.unity3d.com/Manual/TimeFrameManagement.html
It sounds like it's calculated internally, but yeah I guess I'll need to actually test this first. Thanks!
yeah I dont have it in the editor folder but the game runs fine
My only thought was that it was using local position, however even this code doesn't fix the issue
Vector3[] verticies = new Vector3[3];
Vector2[] uv = new Vector2[3];
int[] triangles = new int[3];
verticies[0] = transform.TransformPoint(transform.position);
verticies[1] = transform.TransformPoint(transform.position + transform.forward);
verticies[2] = transform.TransformPoint(transform.position + transform.right);
uv[0] = new Vector2(0, 0);
uv[1] = new Vector2(0, 1);
uv[2] = new Vector2(1, 1);
triangles[0] = 0;
triangles[1] = 1;
triangles[2] = 2;
mesh.vertices = verticies;
mesh.uv = uv;
mesh.triangles = triangles;
๐ 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.
๐ 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.
๐ 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.
New to scripting so bear with me. I am making a simple game where the player is controlling a plane that is constantly moving forwards, which they have to guide through hoops without crashing. The plane is also meant to be restricted to certain boundaries so they cannot go off screen. I was able to get that portion right, but because of that I cant make it move forwards which should be simple. How can I fix this?
To move the plane forward, I use a simple one line code which works, but since I am using a new Vector3 to add the restrictions, I am forced to set the value to 0 based on my understanding.
You are not forced to set it to 0 you can store the result of your transfrom.forward calc in a variable and put that as the z value of your clamped transform
I need to send a raycast x degrees from a transform forward. What would be the best approach to get the direction? I would like to add that I plan on doing subsequent raycasts all the way to the back of the transform.
you should 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
You can rotate a vector with a quaternion, scroll to the 2nd description
https://docs.unity3d.com/ScriptReference/Quaternion-operator_multiply.html
though im not sure what direction you're trying to get from the question
Actually I had another thought. My goal is to have the player fly towards rings which they need to fly through and not hit. Would it be smarter to make the player be stuck on the z axis and have the rings come towards me?
Thanks, I think this is it.
Actually I'm not sure I need to fire a ray towards this direction so it needs to be a v3
depends entirely on the type of game this is. Like an infinite scroller, then yea this could be a possibility
I think Im going to go that route. Thank you!
public static Vector3 operator *(Quaternion rotation, Vector3 point); guess what it returns ๐
Ahhh
I ran into a bug in a game of mine (platformer with similar physics to sonic), where a particular aspect of the physics appeared to be frame dependent. I attempted to replicate it in a new project in a much simpler manner to make debugging easier, and it seems the frame dependency carried over, but I don't really understand why there is frame dependency, or if that's actually what the issue is.
To me it looks like the issue is frame dependency, as the blue cube goes faster and higher the lower the frame rate, shown in the video. I also don't believe Time.fixedDeltaTime is ever getting changed, only the target frame rate, and I don't think the two are related. If the issue is frame dependency, could anyone point out what the issue is in the code? The code is pretty simple and short, as seen in the video, though a particular if statement is pretty specific to this physic sticking.
from a quick glance, i see rotation is frame rate dependant. Try getting this value in fixedupdate from the rb.rotation.
also with transform.position, replace that with rb.position
will give it a try
It looks to me as if the issue still persists
Here is what I changed in the code, perhaps I still left something unchanged: https://paste.ofcode.org/yt2Wi5FbSUyww4yYV9AzQ9
unless im missing something else, it could be because of still using stuff like transform.right and all that. You could calculate it from the rb rotation with Quaternion * Vector3.
like Vector3 forward = rb.rotation * Vector3.forward, and similar with the others.
Could give that a try, I do wonder if any of the maths is frame dependent, tho I've been told that may only be the case if Time.fixedDeltaTime was to change
One sanity check you could do is print out some info from fixed update, save that somewhere (maybe even just write to file) and compare the 2 tests. You could see stuff like at which time they actually have a difference, maybe one is considered sloped or grounded while the other isnt
Fair enough, I did remove all the ground there was, and it seems the issue was just based around the slope bit, as the blue sprite would go around the circle much faster at 60fps compared to 240fps
there is something im unsure of so i will test something, that it may even just be related to those ground checks and how it is using groundCheck.position.
alright, I'm quite confused as to why there appears to be frame dependency so I could assume I'm missing something that may be obvious
hm these shouldnt even really be issues cause its being called from fixedupdate but i also am not sure if theres a difference in 2d objects
yea I find it quite strange
in my original project I thought the issue would relate to how I retrieve inputs or even just something in the Update() function messing it up, but here with all those potential problems seemingly gone, I'm quite lost
im willing to bet its because of the child object, or the transform.right/those directions being used at least
were u able to change those?
from a quick test, at decent speeds and interpolate turned on there is actually a significant difference
currently trying to change the transform.right stuff into rb.rotation things
would
Vector3 rightDirection = new Vector3(Mathf.Cos(rb.rotation * Mathf.Deg2Rad), Mathf.Sin(rb.rotation * Mathf.Deg2Rad), 0);
Vector3 upwardDirection = new Vector3(Mathf.Sin(rb.rotation * Mathf.Deg2Rad), Mathf.Cos(rb.rotation * Mathf.Deg2Rad), 0);
be a correct way of getting the directions with rb.rotation?
nah just this, unity does the math for you already
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.VFX;
public class Domain : MonoBehaviour
{
[SerializeField] private VisualEffect vfx;
[SerializeField] private InputActionReference vfxSpawnKey;
[SerializeField] private InputActionReference WarpSpawnKey;
[SerializeField] private VisualEffect Warp;
private void Awake()
{
vfxSpawnKey.asset.Enable();
vfxSpawnKey.action.performed += OnVfxKeyPressed;
WarpSpawnKey.asset.Enable();
WarpSpawnKey.action.performed += OnVfxKeyPressed;
}
private void OnDestroy()
{
vfxSpawnKey.action.performed -= OnVfxKeyPressed;
WarpSpawnKey.action.performed -= OnVfxKeyPressed;
}
private void OnVfxKeyPressed(InputAction.CallbackContext obj)
{
if (vfx != null)
vfx.Play();
else
Debug.Log("There is no vfx attached to this component");
if (Warp != null)
vfx.Play();
else
Debug.Log("There is no vfx attached to this component");
}
}
using a Reinit(); how do i stop warp vfx after 15 seconds
So if I'm in 2d and I want to get the right direction of the transform, I would do
Vector3 right = rb.rotation * Vector3.right
?
ye doesnt matter if ur in 2d or not. transform.right is a vector3 anyways. theres a conversion done for you from Vector3 to Vector2 that allows you to use it anyways
we can make a thread for this also, might take some more messages
Do I have to convert rb.rotation into something else first? Am I not multiplying Vector3.right by 0 if the player is flat on the ground, thus making a Vector3.zero?
That's fine by me, thanks for your help this far :)
Hey, can anyone please help with getting a decent rotation camera going? Been searching for hours on YouTube for a script and found almost nothing..
!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.
ty
I was pointing out that you should format your code? Is there an issue?
When setting up a spawn manager, should the function of the object be done in the spawn manager script or should I make it a seperate script? I am just trying to make them move in a certain direction until they pass the player
What do you mean with function of the object?
The actual spawning?
```float angleSection = 180 / _numberOfRays; Create Radial ````
Is there a reason why I'm unable to produce a ray behind the transform?
{
Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.up);
Vector3 rotatedPoint = rotation * transform.TransformDirection(0, 0, length);
return rotatedPoint;
}```
Like the thing they are meant to do. Simply wanting them to fly towards player while they need to dodge them. Would I set that up in the spawn manager script or make the script the child of the object
I pretty much got them to spawn but havenโt done the actual movement part so they come towards player
im having this problem where in vs some of my code that should be color coded just isnt, is there a setting that i need to change in vs or something that i need to do to get the colors back?
!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
cool, that worked thanks ๐
Hey so like, is there a code out there to decide spawn points like something with coordinates?
sure
what does that question even mean? If you are, again, asking for a code handout, you have been told on more than one occasion that this server does not work like that
I am just asking if theres actually a code out there in Unity which makes things spawn in a certain place based on coordinates.
why dont you read the documentation on Instantiate
Yeah just read it, still making little to no sense to me.
i want make custom string type which holds variables of different variations of same string, which thing is best
you mean between a struct and a class ?
should i start by learning general c# or unity specific c#
general, at least the very basics
alrighty thanks
interface is not going to work for you. So that leaves class
Anyone can help me fixing my IDE? 0 errors in the console, can enter playmode and build just fine
yet i have a lot of errors in the IDE itself
a lot of namespaces cannot be found like using TMPro; using UnityEngine.UI;
open Solution Explorer, Right click on solution, reload with dependencies
what IDE ?
vs 22
should work. Screenshot complete window
hey I have some code that im using to give 2d objects a fake height. my issue is when i give the object im testing on a rotation of any kind and want my x position to
move based on the objects rotation, it still goes off its world position of x. Also how do I type my code in chat properly?
!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.
!code private void BodyPosition()
{
if (onGround)
{
return;
}
if (!onGround || body.transform.position.y > shadow.transform.position.y)
{
parentObj.transform.rotation = new Quaternion(0,0,rotation,1);
// body.transform.rotation = new Quaternion(0,0,rotation,1);
verticleVelocity += gravity * Time.deltaTime;
body.transform.localPosition += new Vector3(0, verticleVelocity, 0) * Time.deltaTime;
parentObj.transform.position += new Vector3(horizontalVelocity, 0, 0) * Time.deltaTime;
// shadow.transform.localPosition += new Vector3(horizontalVelocity, 0, 0) * Time.deltaTime;
}
if (body.transform.position.y <= shadow.transform.position.y)
{
onGround = true;
verticleVelocity = 0;
horizontalVelocity = 0;
body.transform.position = new Vector3(shadow.transform.position.x, shadow.transform.position.y, 0);
// gameObject.transform.position = body.transform.position;
transform.rotation = Quaternion.identity;
}
}
๐ 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.
Don't do the command, read the bot's message instead ^
updating vs22 version didn't work, im installing english language now and i'll send a screenshot
there is no such thing as reload with dependencies
try regenerating project files?
Edit->Preferences->External Tools->Regenerate Project Files
you need the csproj files
ik
that's not the issue
my IDE just doesnt recognize some unity namespaces
but i have 0 errors in the console and can enter playmode and build etc
Try regenerating project files
I did try that several times
What checkboxes do you have ticked there?
What can you tick?
Try deleting the csproj and sln files and regenerating
all of them?
Yes
worked partially
for some namespaces
now it doesnt only recogznice DOFade on canvas group component
from DOTween asset
but it works, no errors etc
Is is an extension method or something?
hello my loverlies, did my first bit of c# without an example to follow yesterday , its silly its noob but honestly it made me so happy LOL
Welcome to C#
๐ ๐ ๐
guys do you have any similar enemy AI code like the horror game granny?
patrolling and smart Ai thing
Hi, in the following asset I made the mistake, that I built it and when I opened the menu of the game, I changed the resolution from 1920x1080 to 800x600. It was now a small window and it looked pixelated. I tried to undo it, but it doesnt work. after a lot of searching I gave up and deleted the project and imported the asset to a new project. I built it and opened the game. It is still 800x600... does anyone know how to fix that? (Here the link to the asset: https://github.com/DevionGames/inventory-sytem)
need some help on how to start dm me
!learn
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
Alternatively see the pinned messages, check https://unity.huh.how/ or use 
btw here is the script for the resolution:
!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.
yes, the next question is, why is there absolutely no debugging in your code?
... its not my code ๐ its just an asset
What happens when you log width and height just before calling Screen.SetResolution? What does this log?
Also, does it possible skip the if statements? You could also log these
oh okay... ill try it
what has that go to do with anything, you have access to the source so you can debug it
Hey, I just wanted to check, do I need to use the line 'pTimer = timer' or is that irrelevant because the IEnumerator has already started etc..? ```cs public void DotEffect(string spell, float timer, float damage)
{
switch (spell)
{
case "Poison":
pTimer = timer;
pDamage = damage;
StartCoroutine(Poison(pTimer, pDamage));
Debug.Log("I've chosen poison > d = " + pDamage + ". t = " + pTimer);
return;
default:
return;
}
}```
!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.
the assignment is irrelevant in the context of the coroutine but pTimer is a class scope variable so maybe it's being used elsewhere
Awesome, thanks. I'm moving my Dots into a new class, so I only added it to the class scope because I thought it was needed, I use it here for readability so wanted to check I'm not doing more than I should ๐ - public IEnumerator Poison(float pTimer, float pDamage)
if you are using class scope variables no need to pass them as parameters
Unless I'm going the wrong direction, I plan to use the switch command for other things like "burn" etc.. so I'm thinking I do need to pass them?
no, not at all
you may need to pass them into the coroutine so it has fixed values not affected by other processes
How is that? It takes an object and instantiates it on the coordinates you specify
That was part of my testing but my logic is hoping that "Tower > DotEffect(Poison, 4, 4)" > [2 second wait] > "Tower > DotEffect(burn, 5,2)" are not going to be effected by each other because the coroutine for poison has already been started?
correct, if you pass the values as parameters. Value type paramaters have a fixed value at the time of the call
Thank you very much! (Again) Really appreciated ๐ ๐.
Dude, Unity learn is a great resource
How do I make a moving platform without using the setparent method? in 2d
why would you even need Setparent for a moving platform. Platforms dont have parents
for your platform theres a part of the code where you add to its transform, smth like transform.position += moveDirection
you can then track if your player is in contact with the platform with OnCollisionEnter or OnCollisionExit. if the player is in contact with the platform when the platform is moving, you can also move the player
public bool inContanct
void Update() {
transform.position += moveDirection;
if(inContact) PlayerController.instance.transform.position += moveDirection
}
void OnCollisionEnter() {
if(other.CompareTag("Player")) {
inContact = true;
}
}
void OnCollisionExit() {
if(other.CompareTag("Player")) {
inContact = false;
}
}
not tested do not copypaste in
moving platform/elevator logic makes me cry
its not horrible unless you're using something else besides hardcoding to move your stuff
some days I use an animator because funni effects
but nowadays I just have a state machine and transform.position += moveDirection
I'm not really sure the right way to go about it using rigidbodies. It's never smooth no matter what I try
yeah unfortunately.
you can also track position delta
but still a bitch to use
idk how breath of the wild does it
AAA magic goes crazy
It works for elevators since you can add that illusion, but moving platforms to jump between is a pain
this code works ok for jumping
just that it doesnt carry the velocity onto the player
@eager spindle Thanks, this worked great, but if I want the player to jump according to the speed of the platform while jumping, should I use rigidbody?
no
when collision exit, you can check the direction of the platform. use the direction of the platform to push the player
does your player have rigidbody?
yes
okay ฤฑ will try
I'm using webgl platform unity
Is there any way I can make it so that let's say I use pun2
And I want to make it so that when I go to the link
And roomcode can be a I'd i have given and can I get that roomcode of the url and use in my code?
Ping me on reply
guys do you have an enemyAI script patrolling around the map and if the player seen it will chase you
Reply to me or dm if u have one thank you!
unity 3d btw
you cant really communicate from the webpage to your unity game. the dumb solution would be to host an external server, say in Flask.
the external server will serve your game at root. the external server will serve any extensions to your game as well, while attributing the device's MAC address to the game. when the game launches, it checks your external server to see if theres a room code cached for it
i do but we won't code for you ๐ด
I asked my lord and savior chatgpt he did send some interesting solutions
the approximate solution is to make a Frustrum raycast that's the same size as the camera, or a spherecast or whatever
when the raycast hits the enemy, activate the enemy, and turn on the enemy AI
chatgpt ๐คฎ
ill review it onesec
This one line makes me believe it
i have the enemy ai code but the prjblem is when i build the game, instead of the enemy patrolling the whole map it just spins around in one place๐ญ
Application.externaleval()
run i mean
yes
which one
Thanks so much
Hi guys, I was trying to reset the scene using a script (as seen below) since I have to reset the positions, rotations and velocities of many gameobjects but my unity crashes everytime I execute the code. Do any of you have any alternatives to reset the scene ?
public override void OnEpisodeBegin()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
navmesh agent
navmeshsurface
wdym by "crashes"?
By "crashes" I mean that the entire game engine freezes and i can't click on the window anymore
Sounds like maybe you're doing something like reloading the scene as soon as the scene starts. That will make it reload the scene infinitely and crash Unity.
The solution is - don't do that
Ok I think I understand the problem now tysm๐
and navmeshsurface
Does add listener in buttons put it into a list of listeners of the button or does it replace the current listener?
what does the word 'add' suggest to you?
so it does add another listener. i was overthinking it too much
good guess
adds, yes
I am working on a idle game and I cant get number higher than 10,000,000,000,000,000,000 in my code for number notations does anyone if I can bypass this number?
what datatype are you using to represent the number?
a float
welll that's a huge problem
you know there are precision limitations to simple datatypes like float right?
Most idle games use something like https://github.com/Razenpok/BreakInfinity.cs
you'll get a much wider range if you use doubles instead of floats
Dang I was just about to post that library, you beat me to it
but "BigNumber" data types are appropriate for completely ridiculous sizes
Ok thank you
It looks like this just uses a long for the exponent and a double for the mantissa
so it's conceptually similar to a 128-bit float
you know, recent versions of c# have a 128 bit integer now. where's my 128 bit float. I demand a System.Quadruple
@hollow dawn first of all, you shouldnt have multiple controller.Move() calls in update, you should only have a single one which handles all of them