#archived-code-general
1 messages ยท Page 79 of 1
if those faces were joined up, then you'd get a nice solid outline
but then the edges would not be sharp, since it would be smoothly blending the orientation of the faces
issue is i imported them from the unity asset store as placeholders until i make proper models xD
so yeah, highlighting looks good anyway
outline effects can be fiddly
here's the same effect done in Blender
you can see some funky parts where the effect breaks down
yeah i see what you mean
the HDRP outline effect I use duplicates the mesh and redraws it several times with slight offsets
very reliable, but also...probably not the fastest
The best result I have seen didnt scale the model vertices to obtain the results but worked as a PostProcessing effect. Mind you, I never actually did an outline shader so I would not know if it challenging to do so this way.
yeah, i cobbled it together from some tutorials and I only mostly understand it
The same outline likely wonโt work for the highlights either because itโll just extend each face outwards and look silly
oh yeah, you wouldn't want that for a highlight effect anyway
Is there any way I can do the opposite? As in hollow out the centre
So it leaves a box of sorts
unclear
instead of the one to the left a box like this of sorts
this is what ive currently got
i just mean instead of a solid box, a frame essentially
making it red
sorry for the delay, I am on Unity 2021.3.10f1 and TMP 3.0.6 which seems to be the latest available version?
hm, im not sure
You should ask these type of questions in #archived-shaders , not here
I didn't really consider it related to that initially, and i didnt know what else it fit into
Well it looks like a shader is applied, and I haven't seen any code yet
Not to mention you're more or less asking for an opinion rather than an actual problem ๐
Well yeah, but you could say that about almost anything. And the description of the channel states ask questions and discuss, i know its not directly related to coding but i didnt see anywhere that fit better so i thought no harm in posting it here as no one was asking anything at the time anyways so i wasn't interrupting
Alrighty well if it's not a shader, #๐ปโunity-talk would also be fitting.
eh i guess so. I dont see why its a big deal though, i wasnt getting in the way of other conversations
I have these coding channels open alongside other channels, so if I see new messages I usually check them whilst working, should there be a question.
I understand it's not not as important now as if there were more conversations, but keeping it in the right channel is still easier for some people that might check these channels (also, the banner mentions general coding concepts in Unity, so it would be off-topic)
you might want to upgrade Unity to the latest 2021 LTS and see if there is a later TMPro version, from what I see in the change logs this may well have been fixed in a later version
there are a number of null ref exceptions fixed of which this looks like one
that error suggests it found an object that it expected to not exist
that looks like a C++ statement, which is very interesting to see in the unity console, lol
ok thank you I will look into it, upgrading Unity version is always a little bit daunting with a big project as it can break things
comparing the result of .find() to the end iterator
It's a C++ assertion checking for null ref
yeah
you should be OK as long as you stay within the same major version
backup your project first
Pretty sure reopening Unity fixes the problem too
it does for the first time I enter play mode only sadly
and it's specifically when you DontDestroyOnLoad the object?
well, this is the line unity redirects me towards when I double click on the error...
I suspect it's a Marshalling problem. nothing you can do about it
and disabling the DontDestroyOnLoad line seems to remove the error (obviously lots of more errors due to this requirement though)
and Scene Load/Reload?
Be interesting to see if you do an IL2CPP build and run that if you get the same problem
oh, right just reloading the scene in the editor removes the error (still for one play mode enter still)
if it's consistent behaviour under given circumstances it's a bug
I don't think this error occurs on builds, I have not seen these messages on the logs at least
do you have Domain Reload / Scene Reload disabled down in Project Settings > Editor ?
iirc it's under a label like "Enter Play Mode Options"
good point, always a single point of failure
reload of static pointers
this would be consistent with the issue going away for one play cycle after reloading the scene in the editor
indeed
hmm, maybe unrelated but trying a IL2CPP build actually fails
oh, show error
different problem, your build environment is not set up correctly
this? I used to enable it to have faster play mode enter but got lots of error after a while
ok, so that's not the cause, then
i wonder if manually destroying this object as the game quits would fix the issue
isn't OnDestroy called on scene destruction when quitting play mode?
Actually enabling Reload Domain may fix it
I'd think it would ignore those settings if you don't have Enter Play Mode Options checked
It looks to me like an artifact from the previous Domain (i.e. Play mode) may be causing the error
yes, this changes nothing
still greyed out
The default is to reload the domain and scene.
need play mode options as well
just tried all possibilities, does not seem to be related
You can enable the Options checkbox and then uncheck the Reload Domain / Reload Scene checkboxes to disable those reloads
in a 2d space how do i make a projectile from the player at the direction the player is looking at
i'm thinking leave Scene unchecked, just the Domain Reload
unity will perform both the domain and scene reloads if you don't explicitly tell it not to
if "looking" means the player is rotated towards the target, you can use its transform.forward
nope still have the same behavior
okay i had added a velocity to the projectile with that but in game it gives an error that object reference not set to an instance of an object
this is my code
shootPoint = GameObject.FindGameObjectWithTag("shootPoint");
Bullet.velocity = shootPoint.transform.forward * bulletSpeed;```
and also the velocity is not added
which line is giving the error?
the velocity line
so either Bullet is null or the Find is not working
if in doubt Debug.Log it, see what velocity is being set to
print shootPoint.transform.forward and bulletSpeed to check if any is 0
Yo not sure if I'm in the right channel but I have a problem with a while loop. I'm not sure why but using an or operator in the while loop still requires both conditions to be true otherwise it won't stop and I cant figure out why
shootPoint.transform.forward is 0
No!
isn't Rigidbody2D.velocity meant to be modified via AddForce() only?
nope
unlockComb and Input.GetKeyDown must both be true for this loop to terminate
And 0 times anything is 0. QED
having your forward vector be the zero vector is...interesting
yea but why and is there a way i can terminate it with only one condition?
sure, you just need to choose the appropriate logical operator
well then now how can i give it a forward velocity
okay wait i think i understand ๐
What I am saying is your assumption is incorrect. That statement as written will not require both conditions to be true
a useful tip
the shootPoint.transform.forward adds a z value which is useless for a 2d game
the negation of A or B is not A and not B
it is not not (A and B)
it also isn't not A or not B
of course, you could also just say not (A or B) and keep it simple :p
ok actually i need a break i will figure it out later thanks for the inputs
oh, yes, if it's 2D, that won't be terribly helpful
you want transform.up, most likely
select the shoot point in the scene view and look at the colored arrows
red - X - right
green - Y - up
blue - Z - forward
I got it working haha, i was too focused on the operator instead the actual logic of the loop
thanks ๐
HFAmount is an ingame currency. I display it in the shop via text. If I change it from the HF script, attached to the text, the text changes accordingly. But If I change the HFAmount from this script shown: the text, nor the data, nor the HFAmount updates. I tried it all with Logging and this script doesnt change anything. Anyone knows what the reason is? (PullHero() is called when clicking a button to buy something)
yes my bad using forward makes no sense in a 2D environment, use right or up depending on your scene and how you affect the rotation of your player
Bet you are using a reference to a Prefab script rather than a GameObject script
what do you mean with that?
my script is attached to a button in the scene
not a prefab
Are you expecting the change to HFAmount in that script to also affect data.HFAmount ?
yes
wrong
so that on the other script i can take it back
yea well thats why im here
how do I do it then?
HFAmount will be a value type not a reference type so values do not carry over
I assume HFAmount is an int, changing the HFAmount value will not change any other value
yes it is, and what do i do then?
so you have to manually reapply the new value to your data
do you know the difference between value types and reference types ?
i tried using SaveData(ref data) at the end of the if statement but it didnt work either
not exactly, i know what values are
then it is time to learn
id love to
HFAmount--;
data.HFAmount = HFAmount;
something like that
yes but in that script i cant type "data.HFAmount"
it says "data doesnt exist in current context" and if i put "GameData data" into the parameters the whole thing doesnt work anymore
or I love to use setter events to keep UI updated
very true. Is save or load called before PullHero?
both
yes because data only exists in your Save/Load methods, you will have to keep a reference to it in your script if you want to modify it elsewhere
So cache GameData in that script then you can use it
and that goes how?.. xd
Game data localData;
void Save(GameData data) {
localData = data;
}
void PullHero() {
localdata.HFAmount--;
}
for example
how can I use .Find (or something else) to find an element in a list and call one of it's methods?
this is what i had: _bottles.Find( listBottle => listBottle == bottleToFindInList);
updated
is there a reason for the "Game data" written like that on the first line
or did you mean "GameData"
typo, fixed
ok :)
what is _bottles? GameObject ot List<T>?
a list of "Bottle", an object/class
this didnt work either
Difference is GameData is a reference object, HFAmount is a Value object. You need to research the difference in behaviour
the output of saved data is still 55 even tho it shouldve been lowered
do you have an error with this line? _bottles.Find( listBottle => listBottle == bottleToFindInList).Foo(); should work fine
Yes, but I want to call listBottle's method now
extra step ๐
_bottles.Find( listBottle => listBottle == bottleToFindInList).YourMethodName(); ?
Find returns the element corresponding to your condition, so you can call the function at the end of the Find() call
the actual element, not a copy
thanks! ๐
hi, how can i resize my ui components during playmode
i want to do this like file explorer
like drag n drop from a corner to resize?
yes something like that
but i just need to resize just width
not height
to be more specific i want to resize scroll view
What comes to mind would be :
-add a child game object at grab-able points
-add script on the child object implementing IBeginDragHandler, IDragHandler, IEndDragHandler
-start grab change parent anchor to left/right depending on child side
-during grab change parents width with mouse position delta
-end grab restore previous anchor
also maybe implement IPointerEnter/Exit and change your cursor to show you can change size when hovering this child
hello, i was wondering, unity animation editor can animate fields of scripts. how is that done ? does unity use reflection to change (lerp) the values or what, it should be sth else right ? otherwise that would be costy on performance
I would expect it to be using reflection, since you don't have to recompile the game to change an animation.
yea true
Thanks ๐
how do you make a list of all bools used in running scripts?
make an array
or a list
bool[] listofbools;
listofbools[0] = bool1
listofbools[1] = bool2
etc
what do you want to do with this?
note that you can't, like, grab a pointer to a bool in another component
so that it updates whenever the other component's bool changes
you... you just don't
i want to have a struct lets say SaveFloat and then everytime its used it adds it to a list in the game manager and saves it
Make a SaveData class that contains all the data you want to use and save, and always use that object during your game
k thanks
Just wanted to say thanks for being my rubber duck, guys. Typed out a huge ass question, thought of something to try, it worked, deleted question. ๐
lmao, it works
I've typed out several long questions and then just not bothered to send 'em
Hi all! I'm trying to generate a particle system purely through code, and it mostly works - except for when I try to assign a Light. Namely, the following simply does nothing; lights.light simply ends up being null. Does anyone know how it can be done, if at all?
hang on, are you getting a NullReferenceException from the lights.light = new Light(); line?
or is lights.light null when you check it later
This.
I realize Light is a component and components aren't meant to be instantiated like this, but you can't exactly generate prefabs on the fly.
I guess you could create a game object, attach a light, and then assign the light component to lights.light
var obj = new GameObject():
var light = obj.AddComponent<Light>();
Guess so. Seems somewhat roundabout though - and what happens when I destroy the GO?
well, then there lights.light will be null again
And if I don't immediately destroy it, then won't I end up with a surplus light in my scene?
Sure I could disable it, but then again - so much clutter!
Is there a reason you can't just have a prefab?
I configure the hell out of it in runtime anyways, so not needing to maintain a prefab would be a lot cleaner.
Also, can you even prefab a component like this?
sure -- you can assign a prefab to a field as long as the prefab has that component type on it
(or, more generally, you can assign an object in the scene as long as it has that component type on it)
Eh, yeah - not doing it in the scene.
I try to stay in code as much as possible.
So doing that in the scene would mean also prefabbing the particle system.
Hey everyone. Is there a way to call a function if a specific function in inheritance script was called? For example inheritance script has AddItem function and if this function is being called, derived script would call OnItemAdded function.
well, if you do go with a prefab, yes
I'd like to avoid it if possible.
what do you mean by "inheritance script"?
do you mean the parent type?
Call OnItemAdded in the base function.
e.g.
class Parent { }
class Child : Parent { }
yeah
I would do this:
I have several types of derived scripts and each of them has to do different things if the item was added
public class Parent {
public virtual void AddItem(Item item) { }
}
public class Child : Parent {
public override void AddItem(Item item) {
base.AddItem(item);
OnItemAdded(item);
}
public void OnItemAdded(Item item) { }
}
If each child type must implement OnItemAdded in its own unique way, then I'd make it an abstract function on Parent, and have the Parent's implementation of AddItem call it
Then override OnItemAdded in each derived class.
As @heady iris said.
public abstract class Parent {
public virtual void AddItem(Item item) {
OnItemAdded(item);
}
public abstract void OnItemAdded(Item item);
}
public class Child : Parent {
public override void OnItemAdded(Item item) { }
}
if Parent can exist by itself, then make it non-abstract and just make OnItemAdded an empty virtual function
Thanks, I'll try this
Thank you so much. This works even better than expected. I expected unity to have something built-in function that activated right when the parent class is called but now I can control when to call OnItemAdded
no prob!
so im making a script that uses an animation curve and the animation curve changes dynamically, which is working, but not the way i want.
When i make an animtion curve it defaults to an ease-in-out curve, which i don't want, i want just an ease-out curve, is there any way to change this?
make a default curve variable
and just assign it to that in Awake or whatever
but wont it just change back to an ease-in-out curve every time i change it?
this is the part of the code
jumpCurve = new AnimationCurve(new Keyframe(0, currentSpriteFloorHeight), new Keyframe(1, currentSpriteFloorHeight + 1));
heightCurve = new AnimationCurve(new Keyframe(0, currentFloorHeight), new Keyframe(1, currentFloorHeight + 1));
iirc you can control the handles on the keyframes, too
looks like you're defining the keyframes yourself
so it will make whatever curve you're giving it there
You should look into the other forms of the KeyFrame constructor:
https://docs.unity3d.com/ScriptReference/Keyframe-ctor.html
ok
there are more parameters you can give
i see there are 3 overloads
I guess you just make an array of keys, then set that property with it
ok ty
oh, duh
yes, go with the second AddKey overload :p
i thought it was a little weird that it didn't exist
so im not exactly that good with this kind of maths
so i dont even know what im doing with this
The tangent value is just the slope of the tangent
so 0 would give you a flat horizontal tangent
1 would give you a 45 degree upwards tangent
-1 is 45 degrees downward
infinity is a vertical line up
ok
it's slope as in slope of a line (y = mx + b) where m is the slope
like tan function i see
just a line function
Play with it a little you'll get it
I do wonder if I'm wrong and it's an angle ๐
not actually sure if it's slope or angle
but it's one of those
where i learned it was y = mx + c lol
i think its a slope though yeah
i guess some people do y = ax + b
so it got mangled together
anyway, i always mess up ease in/ease out
if you want it to start fast and get slow, you want the t=0 keyframe to have a high slope
and t=1 to have a zero slope
I think I'm running into a situation where I need to "inject some dependencies"
so as I described yesterday, I'm replacing my fixed "health" and "stamina" (and etc.) stats with scriptable objects
i have an asset for each kind of stat
that's working pretty nice! but there's one problem
sometimes I want to refer to a specific instance of that Stat SO
for example, I want the default cost for blocking with a weapon to be stamina
but I don't really have any way to access that...
I need to use a specific asset to provide the default value for the "block cost" field
so that I don't have to manually configure that every time
You donโt have a way to access your stats!?
That's the problem, yes ๐
It's actually almost never a problem. This makes it easy to have entities that, say, don't even have a healthbar
It might be too extreme of a design.
As far as I know, there are not supposed to be instances of an SO, or at least thats not how theyโre supposed to be used. Itโs supposed to minimize instancing so everything references one object.
Unless youโre talking about the literal object?
well, by "instance", I mean the single object that's associated with a SO asset
Ah
So how are you storing the stats in a way you cant access specific stats?
just a public List<VitalValue> vitals;, where VitalValue is:
[System.Serializable]
public class VitalValue
{
public Vital vital;
[SerializeField]
private float value;
public float maxValue;
public float decreaseTime;
public float regenDelay;
public float regenRate;
/* more stuff related to regeneration, calculating the current percentage, etc. */
and I have a dictionary of Vital -> VitalValue to look them up
This is very similar to what I was doing before
Vital was an enum
and I had a few named fields on the entity class
public VitalValue health;
public VitalValue stamina;
e.g.
Why cant you look up stamina?
oh sure, I can
guys
i have a problem
setting Time.timeScale to 0 and then to 1 resets a scene
but I need to have the Stamina SO
well that's odd
No it doesnt. Thatโs not where your problem is.
i'm not kidding
I'm gonna go muck around a little more. Thanks for chatting ๐
i checked twice
Why donโt you make a list of SOs then, and on game start convert it to a dictionary?
I do that already, yeah.
So this is only really relevant when I want to have default configurations for things
e.g. by default, a weapon's block should cost stamina to absorb hits with
most weapons will work this way
So have a reference to a scriptable object and default it to stamina?
I guess itโs hard without a lot of detail about your project.
Get it from the dictionary!
with what key, though?
โStaminaโ?
i guess I could just key it on string name and then accept that I have a little bit of hardcoding
it wouldn't be that bad
yeah
it would be a very small number of places that actually care about the name
well, where does that string come from?
The scriptable object name?
right, but I'd have to directly type that string into the code
I think that, at some point, it winds up being inevitable
No you donโt
you have to identify the thing somehow
Well you do
But only once
Just have a public reference to an SO, and on start say if empty { SO = dictionary.stamina. That way if you want a different stat, it wonโt replace it with stamina
yeah
Defaults always gotta be hardcoded if itโs not a value type no?
can anyone tell me how to destroy stop ?:
public GameObject stop;
Destroy(gameObject);
ty
or just Destroy(stop);, since it's already the GameObject
possible teaching moment: why were you expecting Destroy(gameObject) to work?
it ~will~ run without causing any errors, I suppose ๐
{
if (moveup == true && movedown == false)
{
Debug.Log("move up");
transform.position = Vector3.Lerp(startpos, endpos,1f);
}```
why is this moving instantly
you may be expecting Lerp to smoothly move the object over time
this is not the case
Lerp smoothly picks a value between the start and end based on the third argument's value
0f = start, 1f = end
There are lots of packages and libraries that can do this lerping for you, which is probably what you were thinking of
moveUp, moveDown - why do you have two? Can you move both up and down at the same time? You should only have one
i imagine this is like how you ignore a move input if you're holding both forwards and backwards down
yeah that was it
Basicly change it to Vector3.Lerp(startpos, endpos,Time.Time * (a float to speed it up if you want));
note that this will slow down towards the end
its a door operated by a button, i dont want the button to be mashed and break stuff
every update, it will move a small fraction of the remaining distance
i think itll be ok though
ah, so it's a door
here's my suggestion:
yeah i got it to work
public bool open;
public float t;
public Vector3 startPos;
public Vector3 endPos;
void Update() {
t = Mathf.MoveTowards(t, open ? 1 : 0, Time.deltaTime);
transform.position = Vector3.Lerp(startPos, endPos, t);
}```
the door opens in 1 second
hmm
if i have any more issues ill go with that
{
Debug.Log("move up");
transform.position = Vector3.Lerp(transform.position, endpos,0.15f);
}
if (moveup == false)
{
transform.position = Vector3.Lerp(transform.position, startpos, 0.05f);
}
}
public void toggleMove()
{
moveup = !moveup;
}``` this works pretty well
what do the ? and : operators do again
ik theyre a shortcut
this will be framerate-dependent, since it moves 15%/5% of the way to the destination every update
that will make it move (a little less than) 15%/5% of the remaining distance per second
it's one of those things where it never quite reaches the destination
i was wondering is there is a quick access of List<> variables through their attributes, kind of like
// pseudocode
class coordinate {
int x;
int y;
int baba;
...
}
class implementation {
List<coordinate> coordinates;
coordinate a = coordinates.Find(coordinate.x == 1, coordinate.y == 0);
}
Something like this, i currently have a function with a foreach that looks through the list to find the object and return it and i'm wondering what would be a more efficient way of accessing, since this has O(n) efficency.
If there isn't what would be an efficient datatype compared to List?
There's no way to do this in a List without O(n) time
Use a Dictionary if you want to look things up by a particular key
i have collision detection on a moving object, and whenever it goes into some corner, edge or similar hes clipping through. (walls and stuff)
is there a way to prevent that?
im using 3d
What does "have collision detection on a moving object" mean specifically
box collision
and the others are mesh collisions or some rotated planes
and he can like walk through edges and stuff
What does "box collision" mean.
Sounds like you have a Collider on it
But that's only one piece of the puzzle
You need more than just a collider for your object to not move through things
rigidbody it has
Please show and explain your whole setup
What components it has, what movement code it is using, etc
these are components of the rigidbody player, he is moving around like some classic game, with velocity and transform.translate.
the box collider should stop the player from walking against walls and walk on the ground, but in more complex maps that have small rooms and edges he just clips through.
well, now the problem is, he clips through these grey planes from behind and edges and like i said before,
is there a way to prevent that from happening, so he wont just walk through?
Does unity give a preprocessor directive for if the program is running in build mode instead of the editor? I would assume that's what UNIT_EDITOR_WIN is but it isn't clear to me.
Just UNITY_EDITOR should do the job
Okay, thank you.
hey,
im having trouble getting this level creator to work. it executes, but it's not putting an atlas PNG "atlas_#.png" in the output only the bytes file and the level text file.
there are 2 scripts involved im not sure which is creating the issues as no errors are produces also im quite new unity myself
!code
๐ Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
its from a template im using from the unity store "bizzy bee color by number"
dude did you even read the bot? no one gonna download textfiles tbh
this is a 1000 lines
you put both of them together?
why do you wanna make readability a chore lol
you really like scrolling a 1000 lines to debug something ?
so no it should be split as much /often as possible to do so
no assumed you're not cause this is #archived-code-general not #๐ปโcode-beginner
i was told to post here
sorry
@potent sleet this is coming up in vs code
CS0246: The type or namespace name 'Color' could not be found (are you missing a using directive or an assembly reference?)
my this is the issue?? i finally got itellisense working finding out its was a firewall issue so im trying to make up for lost time here too, this has been a long time unsolved problem for me
thats the other script
by whom
someone in another channel
and Color should already be in UnityEngine directive
not sure which script or line that is so I can't say
the second one i posted. the template is old could it have outdated dependencies or?
keep in mind i didnt write this script its part of the template i paid for
the creators are i guess not maintaining services to help the buyers which sucks
@fickle vigil using System.Drawing;
sorry im not sure what that refers to
for this I guess
Color is already in UnityEngine namespace
maybe
maybe ? it's an absolute fact
not absolute
so should i just remove that namespace all together?
why?
no, and considering you don't know anything about the script since you did not write , this is gonna be hard to debug.
Like i said you never shared the Line number of whatever script
thats because it executes with no errors
you literally shared an error
you sent one though
its just doesnt produce the expect atlas png
oh god, have you gone and done something dumb like mess with the compiler unity uses
because it has errors
can anyone help me, or tell me what explanation im missing?
i dont think so
do those planes have Mesh Colliders on them?
then explain namespace BBG.PictureColoring; because file scoped namespaces are a c# 10 feature which unity does not support
yeh thats from vs code not unity
what?
what do you mean?
what do you mean to stop walking?
you can do it in the script, so that game stops when he walks somewhere?
or is it an issue of physic material?
nope, box colliders
why is that so hard to explain... he should not walk into a wall
he should not walk through that wall
ah
can you show the inspector for those plane objects?
but i also use some mario odyssey map to test... and in edges or corners he can just walk through
right.
also why are you using such an ancient version of unity
everytime the word color comes up its showing a red underline in the creator working script
because im making a game for the new 3ds
it does not have rigidbody
also vector2
do all objects need one, like every?
i mean not every
no
??
ok, not every
the boxes dont move
and yet you didnt mention which line of which script
but you need rigitbody here
if it doesn't need physics then it doesn't need a rigidbody. just a collider is exactly what you want for something static
no
well, you also need one if you want to get collision events
the are multipe one sec
but why does the guy slip through edge or walk through that plane, from behind?
they have one on the player. it is not necessary to have one on these static objects
ah, I see
try to use rigidbody on those planes without gravity
show how you actually move the player
4 unity engine;
8 worker
14
15
16
140
141
142
Pretty much all referencing the name space โcolorโ
Hi! I'm storing scores in an array and trying to get a new array with the positions of the scores. for example:
scores = [ 10 , 30 , 20 ];
places = [ 2 , 0 , 1 ];
Anyone with an idea on how I could do it?
ah yeah, it happens with Vertical and Horizontal input, and transform.translate
yeah transform.translate does not respect collisions
Line 4 and 8 are the only exceptions threat are all color or vector2
if you're getting an error on using UnityEngine;, then everything else is going to be hosed
what is that?
you mean dictionary?
i'd bet their error is due to them trying to use filescoped namespaces which i've already pointed out to them is not a feature supported by unity unless they've gone and messed with the compiler
so you want to rank the scores
Nope, arrays. int[]
Exactly
yes, I suspect that would do it
what do you need to do?
I guess I would sort the scores, then get the index of each original score in that new sorted list
(sort, then reverse, since you want high to low)
like: 10 score => 3rd place, 20 => 2nd, 30 => 1st?
And then get IndexOf in the original array, right?
Right.
Yes, this
so use dictionary
this will not handle ties, though
this is about computing the ranks
yes
for ties, I guess I would remove duplicates first
Yeah I will handle that after, thanks! I feel silly for not thinking of that lol
did you read what boxfriend told you
about the namespace
your script can't compile with errors
don't you just need to order all the scores?
32 => 1st place
25 => 2nd place
2 => 3rd place
1 => 4th place
...
yes, which is what I described
i did not understand you before, I'm sorry
prob overkill
OrderByDescending would probably be more appropriate
oh yes
sorry to ask, but whats an simple alternative for that, that does respect colls?
you need to tell the rigidbody to move
rb.MovePosition or rb.AddForce, depending on how you're doing motion
or just setting rb.velocity
using the rigidbody by either assigning velocity directly or using AddForce
MovePosition will not respect collisions either, though having a rigidbody does make it a bit easier to check if it would collide with the SweepTest method
It doesn't? I was under the impression that it did, huh
the documentation says that you teleport a Rigidbody by setting the transform's position
I guess that's just to let it interpolate
interesting, gotcha
it's intended for a Kinematic rigidbody which won't collide with anything
My understanding is that it will cause a kinematic body to appropriately push things out of the way
right, my explanation was worded poorly. a kinematic rigidbody will not be stopped by other colliders
OK well I didnโt write that, so why are they selling a template on the unity store with that in it?
Yep โ๏ธ
which asset
You mean which asset on the store to clarify?
Hence โBBGโ in namespace
no
^
line 8 is bogus in anything earlier than C#10
and Unity is on...C#9, if I recall correctly!
I did a fresh install of everything multiple times and this script in the template never worked
Yes. Because it's not valid.
You can't do that.
namespace Foo;
this is not valid in the version of C# that unity is using.
Change it to
namespace Foo {
/* code in here */
}
Which am I changing Sorry.?
Unity engine? Or bbg.picture.
The one that has the error underlined
Nah it's probably the namespace declaration, seeing that it comes from the asset
Probably, but wtf is up with the formatting of this file
Is that even a script for Unity
so now Iโm not getting the same errors I think I had something wrong with my.net, so I was doing some different installs there and now the debugger is working in unity
I will share the debug console information one second
- that asset is $75, and has a lot of negative reviews... I wouldn't have bought it myself
Never mind I guess I canโt copy and paste the debug console
Doesnโt seem to be able to let you copy and paste
yes you can
I dont know if you can in play mode
It was the only one that isnโt based on colouring square pixels, which I donโt want. Iโm trying to have a colour by number app that I can host artist pictures in
So, when it says run in the bag on the left-hand side, it says select debugger.
It provides me with.net 5+ and .net core
.net framework 4x windows only.
C# godot
Then it seems to do nothing after that doesnโt matter which I pick I donโt understand what to do
VS Code? The debugger plugin is deprecated and not supported anymore
What is it you donโt think itโs directly from the asset?
Yeah oh so you donโt use the debugger in code?
You can't use it yep
it sometimes works!
Well, no wonder itโs not working then
it's very wonky
So everything Iโve been doing should be probably disregarded
but the core problem here is that your script cannot work in Unity.
it uses a C#10 feature
Right the core 10 feature being bbg namespace correct?
Better use a supported code editor like Visual Studio 2022 or Rider, to be able to use the debugger. But that's not the issue here. Can't debug code that doesn't compile
Right the core 10 feature being bbg namespace correct?
I assure you itโs definitely 100% from the asset
Do you want me to change it to โfooโ BGG picture colour?
no, I was simply using "Foo" as an example name
File-scoped namespaces yes. Before C# 10 you had to do
namespace NameHere
{
// Code goes here
}
But since C# 10 you can do
namespace NameHere;
// Code goes here
And the namespace applies to the whole file contents. It improves readability, as it decreases one level of indentation
But, Unity doesn't use C# 10, so you need the first way of doing things
yeah, since you almost never put multiple namespaces in one file
Is there any way to pathfind to the closest spot for the agent, but then stop?
So whoever made that asset either 1. was on some experimental unreleased Unity version, or 2. not in a Unity project at all, and imported the Unity libraries in a standard C# project
one thing that I noticed...
despite using the file scoped namespace
it's indented as if it wasn't
namespace BBG.PictureColoring;
public class LevelCreatorWorker : Worker
{
#region Classes
public class Settings
{
I wonder if VS suggested that you switch to a file-scoped namespace
VS won't as it's aware of the C# version being used, but VSC can be dumb enough to apply the wrong code fixes
well, VS might also think it's on the wrong version :p
i used to have a problem where Unity wrote .csproj files with the wrong C# version...
9, ironically
but yeah, that's my guess
if you just turn that into namespace BBG.PictureColoring {
...and then add a matching closing brace all the way at the end
it should spring to life
Sry for the late reply, here you have the error I get. If u need any else detail let me know.
Exception in transaction delegate, aborting transaction
System.NullReferenceException: Object reference not set to an instance of an object
at NoticiasDBManager+<>c.<Start>b__1_1 (Firebase.Database.MutableData data) Exception in transaction delegate, aborting transaction
The code if someone wants to chek it out ๐
OK so after going into my back up, it is set up the other way that is correct, so yes, it mustโve suggested that but that still doesnโt change the fact that this has never worked as a function I will load from the back up and debug. Where should I be doing the debug then write in unity?
Visual Studio will let you debug it.
Ok let me do that see what it comes up with and then maybe itโll be a lot easier to help me get this running
Something bad happens in the .RunTransaction() lambda that causes this exception to be thrown. Most likely, mutableData.Value is not a IDictionary<string, object> implementor
Or, it's null as the exception actually says. Getting a .Count on it will throw that exception
Hey guys I am currently working on a simple Dialogue System.
In a nutshell every Guest Dialogue will have an NPC response and vice versa.
However the inspector doesn't let me add elements after a certain point. Any thoughts?
Unity serialization has a depth limit of 7
i would suggest breaking this up so that each state in the dialogue tree is its own SO
and you just link them together
Seems like not a scalable system anyway
this will make you very sad very quickly, yes :p
It's going to be a 180ยฐ answer but I would make a graph editor for this kind of dialogue system
Like that's just not readable
Also you won't be able to make branches that return to the main dialogue branch etc this way.
A graph representation is definitely the way to go
Question, my Mac has file vault turned on with that be causing problems because I keep getting a message coming up that says certain files and bundles canโt be open because Apple cannot check it for malicious software and this is happening when I load up the project
i need to look into making custom graph editors
i have this problem when running other people's unity games, since Apple loves code signing
but I've never experienced it in the unity editor
the weird thing is that the 1 time I call the void it gives that error, but when I call it another time it just starts working fine.
Also if I cange the code and save it,
happends. But if I stop the play mode and start it again it works the first time I call the void, but anytime I save a script it breaks. (When I export as an APK it works on the 2 call)
Do I just go in to privacy settings and allow each thing as it pops up and then reload it?
Someone even made a sort-of programming language for that kind of thing and described it in their devlog. It had markers so characters would look at each other when talking, crazy stuff! I don't remember the publisher though, and I think it was closed-source
Itโs probably because Iโm using that template
maybe it also puts markers in the text to tell the game when to spawn items! [74] [74] [74] [74] [74]
ooh, prismatic shards!
stardew valley is a lovely game, but it can be very janky from time to time :p
Oh, and it could also drive animations to represent emotions lol
All this from a text file a non-developer would create, and they made a parser in Unity
I see. Didn't know that . Thanks for pointing that out
Aah I will look into this
Yeah you are right
I understand. It's a school project so haven't really given it much thought
Just curious. Why so?
Can you log mutableData.Value?.GetType() before you cast it? Maybe it doesn't have a value. As for why it only starts working on the second run, not sure. Maybe the first call initializes something, and that thing is only ready at a later time?
I opened unity, entered play mode and it worked, but when I start it again it just stops working and it logs Null
Okay so your query there doesn't return any value
So the first time this thing is called, the system isn't ready (?) and you get a null instead of your dictionary
right, but when I opened the project I did the same as always and it worked
but now it doesnt
I haven't dealt with Firebase from C# so I can't tell where the issue comes from
Np, thx
Anyone experienced with it lurking here, feel free to chip in
So when I stay afk a Unity procces started and when it finished it worked, im going to try to screenshot it if I see it again
these logs are from this:
Debug.Log(mutableData.Value?.GetType());
Debug.Log((IDictionary<string, object>)mutableData.Value);
Debug.Log(cantNoticias.Count);
I didn't write it, no idea.
would assume its a case of they had to stop somewhere, and ensure it does not get stuck forever if it hits a self referential data structure
When it was first created, recursive functions were not a thing. So they agreed on a number they picked at random
Yeah probably a crude infinite cycle prevention mechanism
Also... to avoid the inspector looking like... well.. worse than that
Soooo can you just run and debug the entire project because itโs asking me to open the folder but yet it wonโt let me open entire folder it seems to want to only let me open a file and when I do it doesnโt allow me to debug
Just deleting:
mutableData = null;
It worked
Hm where did you have that lol?
at the end of the lambda
it worked with another script so I just copied and paste xD
Yeah that'll do it. Still no idea why it worked some time and not the other time. It probably never worked
well, ty anyways ๐
I'm not used to work with 3D, can you help with gimbal lock? Here's how I apply my rotation from mouse/stick to the camera:
private void Camera_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
Vector2 delta = obj.ReadValue<Vector2>();
// Create Quaternion rotations for each axis based on joystick input
Quaternion rotationX = Quaternion.AngleAxis(delta.y, Vector3.right);
Quaternion rotationY = Quaternion.AngleAxis(delta.x, Vector3.up);
// Combine the two rotations to get the final rotation
Quaternion finalRotation = rotationY * rotationX;
//camera.transform.Rotate(finalRotation.eulerAngles, Space.Self);
camera.transform.rotation *= finalRotation;
}
heres how it looks (or is that not what gimbal lock is?)
The typical approach is to have two objects in a parent/child relationship
- parent
- camera
Rotate the parent object on the y axis only and the camera with local rotation on the x axis only.
oh ok, I see how that would work but it seems weird to do it that way, if it works it works I guess, ty
and yes it does work ๐
Anyone know if there's a way to programmatically convert a texture (NOT Texture2D) to a sprite?
Unity directional light. 3d objects are lit up on one side but completely black in the other. Is there a solution or does unity just suck? Cuz I can't get anywhere with this garbage
On the other*
oh god no. Camera should be moved in LateUpdate.
so many small issues when just parenting it.
I don't rotate my camera with Quaternions not only because I don't understand them well enough, but because to my understanding they take the shortest path in rotation which is not always what you want to move because it'll rotate around the Z axis also. This is what I do:
rot = Vector3.Slerp(Vector3.zero, new Vector3(-delta.y, delta.x, 0), Time.smoothDeltaTime);
Vector3 newRot = _head.localEulerAngles + sensitivity * rot;
if (newRot.x > 89 && newRot.x < 180)
newRot.x = 89.5f;
if (newRot.x < 271.5f && newRot.x > 180)
newRot.x = 271.5f;
_head.localEulerAngles = newRot;
I do this on an input action, and have the camera follow the position and rotation in LateUpdate
No it's euler that does that and slerp is something for quaternions :3
can you elaborate more?
Slerp is not only "something for quaternions", there's literally a Vector3.Slerp method. It's for rotation.
and the vector3 shortest path vs the quaternion shortest path is different, so a quaternion's shortest path might wobble weirdly in my experience
I'm not sure that shortest route behavior is a thing with Quaternion.AngleAxis, but with .Slerp it definitely is, you can't force a direction with .Slerp to my knowledge.
The issue with other axis' being affected from a lerp is a eular angles issue not a quaternion one that's because quaternions can't gimbal lock. And if I had to guess the slerp function for Vector3's is just a version that converts the eulars to quaternions and converts back
using solely quaternions I run into that issue. how is that possible then?
also don't guess
Vector3.Slerp is for interpolating directions, not positions.
there's also a quaternion.slerp function what do you think that does?
quaternion.slerp interpolates rotations
it's doing the same thing as the vector one but instead vector3.slerp is converted to eular
it's not doing the same thing as Vector3.Slerp
๐
quaternions don't have a direction it's just a rotation
just ๐?
one interpolates directions, one interpolates rotations.
as far as I know these are different. I'll look at the unity C# reference right now to see. But now I don't trust you to explain to me how they're the same or different based on your response of only an emoji.
well I mean I am also busy
https://youtu.be/zc8b2Jo7mno 2:50 is where it shows this
In this video we explore Euler Rotations, the most common method for orienting objects in 3d. It's by-product "gimbal lock" can cause headaches for animators because the animated motion can move in strange ways. Here we learn how euler's "rotation order" is a bit like hierachies, and how changing this order can help us to avoid gimbal problem...
I know what gimbal lock is but Vector3.Slerp is not rotation
it's for directions. Quaternions don't have a direction
anyone have any experience using beebyte obfuscator? had a couple of questions about it and there are no video's/debugging/resources to drill into for it.
So unity is trash then? Ok thanks.
No, the problem is you
Nope
Unity is just bad. The constant depreciation of things people find useful. Taking away good things it had.
lol what
Unity is one of the slowest at deprecating things out of any software I've used
someone is using non-LTS
I swear it feels like there's things that have been marked as depreciated for years and still not removed
If you want to make the backside of objects brighter, increase the environment lighting https://docs.unity3d.com/Manual/lighting-window.html and ask lighting questions in the #archived-lighting channel instead of a coding one.
well, years is what it should be
For one progrids isn't available anymore. And u would think at the very least they could have just made it part of unity
I agree
Thank you. And sorry. I didnt know
Is it? Because I can't find it in package manager anymore. Except under my assets cuz I downloaded it before but even that won't install now.
I'll check again
Just add it via name com.unity.progrids
its a preview package
https://docs.unity3d.com/Packages/com.unity.progrids@3.0/manual/install.html
Is there a way I could get Lerp / SmoothDamp to work while time is set to 0
it's a math function, time is irrelevant
Lerp(0, 1, 0.5); // 0.5
No "job" posts or troll posts please
Is there a channel for that
I was too lazy to look so ima just wait till someone helps
!collab
We do not accept job or collab posts on discord.
Please use the forums:
โข Commercial Job Seeking
โข Commercial Job Offering
โข Non Commercial Collaboration
I require some 1 on 1 save system assistance,
Ask your actual questions, as per #854851968446365696
no, because it's searching by tag
it would be gameobject.find instead correct?
yes, but be careful with that. Searching by name is awful and if there are multiple GOs with the same name, there is no guarantee which you might get back
Anyone know why this SmoothDamp isn't.. smooth?
Don't know what I did but its fixed. Moves to 0, 0, 0 though
Jesus christ I didn't multiply forwards
Nope that doesn't matter
AFAIK because you are moving it to a position based on your current position. It's smooth if you have a consistent origin and a destination, not smooth if you do this thing where you have a = SmoothDamp(a, a + b, ...)
a = SmoothDamp(a, b, ...) would work fine
If you for example smoothdamped your direction vector, and added that to your position it would work fine
this one is a mix of buildpipeline and shaders, is there a way to avoid compiling any shaders for a build, i.e. avoid my always included shaders?
I want to build a console window but shaders appear to still be added
what is the best way to do tile collisions? currently using custom physics shape, but it's so much god damn work
Use AssetBundle which does not include the shader.
Alternatively, look into https://docs.unity3d.com/ScriptReference/Build.IPreprocessShaders.OnProcessShader.html
Can someone please explain why my Input.GetKeyDown(Keycode) function thing dosent work ?
private void Update()
{
if (Input.GetKeyDown(KeyCode.F))
{
ChangeProjection = true;
}
}
Do you use the "new" input system ?
I have both enabled
Are you sure you correctly enable the Active Input Handling to Both ?
I am not sure
The setting should be in Player Settings.
i did update the unity version last year
Project Settings -> Player -> Other Settings as I read on Internet.
I am sorry, this is as far as I can guide you.
Oh ok
Is gameObject.Find("Stuff") so bad that it's illegal, or is it fine to use it in functions that happens every now and then? ๐ค
always best to reference in inspector if not then find with tag would be better
Hoping this does the trick
internal class ShaderDebugBuildPreprocessor : IPreprocessShaders
{
public int callbackOrder => 0;
public void OnProcessShader(
Shader shader, ShaderSnippetData snippet, IList<ShaderCompilerData> data)
{
switch (BuildPipeline.CurrentBuildType)
{
case BuildType.Host:
case BuildType.Client:
break;
case BuildType.Server:
data.Clear();
break;
default: throw new ArgumentOutOfRangeException();
}
}
}```
Is there a general guideline for when I should be putting scripts on the player vs when it should be on an object? For example, I want a script for buttons controlling a spaceship, the player is on the spaceship.
There will be a trigger for when the player is in the ship and then the buttons themselves will need to affect the ships velocity, which leads me to think the script should be on the object.
But I also need to account for player input, which makes me think it should be on the player
Basically should the player detect the box trigger, or should the box trigger detect the player?
You can approach this several ways.
One way is if this is a script that can alternate from one ship to the next then make it ship dependent otherwise you could have it as an input profile that you can switch on and off the player.
So you have one profile for normal input and one for ship input, technically you could use this approach for all forms of input, i.e. switch to normal 3rd person/1st person input when not in a vehicle, switch to ship input when in ship, switch to land input when in land vehicle.
Neither of them. The player should be an "Avatar" as the spaceship. What you want is interface the control of the ship and the player.
In other words, you should be able to control the ship without the usage of input. It can become handy to follow such paradigm in the event where you have multiple target (Avatar, Spaceship, Menu) and source (AI, Cinematics, Player, Multiplayer, Online)
Thanks this cleared up a lot even for simpler interactions
Im slightly confused what you mean honestly, i understand the idea but how does this cause the ship to be controlled without input?
You should always other means to find GameObject. The usage of Find("...") breaks easily whenever you rename or reparent object. It can be a nightmare to maintain whenever your project starts to take complexity. Also, this is not an efficient way in term of performance.
Reference is a good way to manage those type of needs. It can also be done with GetComponent if needed. Tag, Singelton, ServiceLocator or Depency Injection are all valid ways to operate.
The ship most be interfaced with the concept of input. It can comes in the manner that the control of the ship is completely externalize or by the usage of an interface.
This is the Dependency Inversion Principle.
a crude way of having this work is the player has an input interface
{
void WKeyInput();
void AKeyInput();
void SKeyInput();
void DKeyInput();
}```
then when you create different inputs they can implement this interface and this can be inserted into the player as a 'ShipInput', 'LandVehicleInput', 'FirstPersonInput'
```public ShipInput : IInput
{
void WKeyInput()
{
// Move Forward.
}
void AKeyInput()
{
// Rotate Left.
}
void SKeyInput()
{
// Move Back.
}
void DKeyInput()
{
// Rotate Right.
}
}```
```public Player
{
[SerializeReference] IInput input;
}```
Oh I see, thanks for the image! Im still new to unity but i know a good amount of c# so Ill look more into this
The principle comes from the SOLID principle which you probably heard of.
Yea ive heard of it but its been awhile
hello i am trying to shoot raycast out of a car gameobject can anyone direct me to some code or somehow explain how to shoot them out(im new to raycasts)
ping if you can help
Thanks for the example code too! I'll experiment with this on the player
this is extremely abstracted, you would still need to implement the approach to firing the interface methods either via old input system or new input system, so don't forget that.
Look at the 3rd code block for a very basic example.
If you wanna see the raycast you can draw them with Debug.DrawLine(start position, end position, color, duration)
https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
how do i make it shoot out rays in other directions not just up and forward
the input is a vector, you can choose the direction by just making a new vector3(x,y,z) direction. If you want a dynamic direction like the forward direction of the car, you can just take the objectName.TransformDirection(Vector3.forward)
how do i make the raycast start a little more up?
My implementation of OnProcessShader doesn't appear to fire when running build
^
pretty sure you can just do objectName.transform.forward
Lol I actually used transform.forward in one script but TransformDirection(Vector3.forward) in another, oops
in the example code, transform.position is the start position. its a vector, so you can add to it
how would i do that?
Vector3(car.transform.position.x, car.transform.position.y + 3, car.transform.position.z)
i tried this but now worky
Do you know vector math or are you asking specifically about doing it unity?
in unity
transform.position(car.transform.position.x, car.transform.position.y + 3, car.transform.position.z
hb that
with a ending parantehses i forgot
You're just kinda making up syntax as you go eh
U can just add vectors in unity with the + symbol the same way u add numbers
i need to know how that would like in code
i not good at c# learning sytax as i go
I lol'd
transform.position += Vector3.up * 3;
Like
Vector3 offset = new Vector3(x,y,z)
then plug in car.transform.position + offset
definitely have been there in desperate moments, just writing random words in hopes its a function
would i say like Vector3 offset = new Vector3(0,3,0) if im trying to be three units higher?
yep
yes thatll work but also i just wrote it as a new variable to show it, there are still other ways to add like said above Vector3.up * 3;
Now how would i make it slighty downwards
That is left to the reader as exercise
time to do it the fun way Vector3.up + Vector3.up + Vector3.up
so do you guys know how to make it go downwards
Think about it for a minute
we'll wait
I think you can figure it out
I believe in you, if up is positive then...
So I'm trying to make it so you can pan the map around by clicking and dragging, but for some reason it pans in the x and y axis rather than the x and z axis.
{
PointerEventData pointerData = (PointerEventData)data;
Vector2 position;
RectTransformUtility.ScreenPointToLocalPointInRectangle((RectTransform)canvas.transform,pointerData.position,canvas.worldCamera, out position);
camView.transform.position = canvas.transform.TransformPoint(position);
}```
how do i make it pan in the x and z axis?
im talking about rotation
not if its going up or down
how do i make the ray shoot out at an angle from the origin
I would really recommend you look at vector math. the vector is the direction
if (Physics.Raycast(transform.position, -Vector3.up, out hit))
print("Found an object - distance: " + hit.distance);
It goes in whatever direction you tell it to
ik
Vector3.down exists BTW
but how do i tell it to go at a certain angele forward
I have no idea what that picture is showing lol
Ok good you have drawn what i was going to explain, all those lines you have drawn are vectors, they are not angles
how
agian i very new with with syntax and need a example code
what is q?
bro
Before getting into that honestly just experiment with plugging in random values lol. Quaternions are hard to understand at first, and honestly i dont think you know vector math to begin with
Like see what happens when you use idk (-1, -1, 0) as a direction
car.transform.TransformDirection(Vector3.left) * quaternion makes a lot a sense
Doesn't work that way
Quaternion goes first
not just thats what i said
Vector second
how would i represent like 45 degress down?
vecotr3(x,y,z)
So that doesn't make sense
hb a quternion
Quaternion.Euler(x,y,z)
Where those are angles around those axes
Or use Quaternion.AngleAxis
Where you provide an angle and an axis
Honestly quaternions are going to confuse you too much right now. I would really just say experiment with plugging in random vectors to see where the raycast ends up.
side view btw
ok
Like when you say at an angle, do you really need it at a specific angle or do you want it just angled down
yea just go for random values, look at quaternions after you actually understand vectors
how do i put in thos random values?
print("Found an object - distance: " + hit.distance);
Debug.DrawRay(car.transform.position + offset, car.transform.TransformDirection(Vector3.forward) * hit.distance, Color.yellow);```
Think of random values and put them into a vector
thats my code for forward raycast how would i make it go down
just pot me in the right direction
idk if you saw but someone corrected my code i provided, you can just use car.transform.forward instead of what i wrote
For the vectors, the docs say
Vector3.forward
Shorthand for writing Vector3(0, 0, 1).```
Vector3.up
Shorthand for writing Vector3(0, 1, 0).
Really, just look at vector math already itll make sense
_rotation = Quaternion.Euler(car.transform.rotation.x, car.transform.rotation.y-1, car.transform.rotation.z);
_rotation * car.transform.TransformDirection(Vector3.forward)```
does this work?
car.transform.rotation is not a euler angles. Use localEuler.
What are you trying to do here? Why not just cam.transform.forward?
Here I got ChatGPT to answer it for you
If you want to get the resulting forward direction without actually rotating the object, you can simply multiply the current forward direction of the object by the rotation quaternion that you calculated. Here's an example code snippet:
// Get the current forward direction of the object
Vector3 currentForward = transform.forward;
// Calculate the new rotation by rotating the forward vector 60 degrees to the right
Quaternion newRotation = Quaternion.Euler(0f, 60f, 0f);
// Calculate the resulting forward direction by multiplying the current forward direction by the new rotation
Vector3 resultingForward = newRotation * currentForward;```
In this example, we first get the current forward direction of the object using transform.forward. We then calculate the new rotation quaternion using Quaternion.Euler, just as we did in the previous example. Finally, we calculate the resulting forward direction by multiplying the current forward direction by the new rotation quaternion using the * operator. Note that this operation does not actually rotate the object - it just calculates the resulting forward direction as if the object had been rotated.
i already asked chagpt and it answered my q
my fault for that last part ๐, i got that from online awhile ago and never realized theres a .forward
Anyone got a solution for excluding all shaders from a build when firing UnityEditor.BuildPipeline.Build()?
How would I stop my camera from inverting when going upside-down? I'm setting the transform.forward to a vector pointing at another object to look at it, and I want to allow the camera to go upside-down.
This doesn't seem to happen with other objects when I use transform.forward = dir, so it leads me to believe it's something built into the camera component doing this.
When you want it to be upside down, without rotation, where is the camera in relation to the player?
at a fixed point
Consider using Vector instead of transform. E.g. Vector3.forward.
(So as long as your camera doesn't rotate ๐ )
what do you mean? can you give me an example?
Vector3.forward returns a value of (0,0,1)
I don't think you understand what I'm doing.
I'm setting transform.forward to a direction vector.
Are you changing only the x or z axis?
because y value would cause it to invert, x going 180 would be upside down
I'm literally doing transform.forward = direction;
yes exactly. As the x rotation approaches and passes 180, Y rotation gets set to 180.
when it goes back, Y gets set back to 0
I'm not doing this in my code and transform.forward doesn't do this on other objects, so it leads me to believe it's some built in thing in unity's camera component doing this to prevent cameras from going upside-down when rotating, which I want to allow.
When you say that your camera "inverted", what do you mean by that?
this
I'm not sure if inverted is the right word.
You're facing a gimbal lock.
well, why doesn't that happen with other objects!?
What does your direction value looks like?
I dont think its a gimbal lock, i could be wrong but i think thats camera specific
Are you using a cinemachine camera?
no it's gimbal lock I'm a dumbass.
๐ค howd u manage that
because that's what happens when you get gimbal lock and i thought it wasn't happening on other objects because I was like I TESTED IT but I literally had a script on that object that was setting the y value rotation to 0 every frame, so ofc it wouldn't change to 180
