#💻┃code-beginner
1 messages · Page 518 of 1
no one in the official csharp discord knows....
usually it gives you that error when it can't decide which type to use if there are multiple types with the same name. What does it do if you have your IDE try to resolve the error for you? (Not sure what the hotkey is in VSC)
Is the one that works actually resolving to the one you defined? Or maybe UnityEngine.Mathematics?
when I do the f12 goto definition it does go to my own defined Mathematics
and the code that uses it's Tau constant works.
does the code in Units also work? maybe just an IDE error?
changing the name to Unitts does not work either..
getting the error in both Cursor and VScode ides
what about am empty project with just these 3 files?
does work.
so it must be unity
cannot proceed with my project until I get this fixed
just wasting an afternoon for some stupid unity meta file bug
Pls is any free texture download either from browser or asset store safe from copyright can I use it to publish my game
This is a coding channel
And why even crosspost that
#📖┃code-of-conduct crossposting is against the rules, and asking again despite being told this is a coding channel is just spam.
Ohh thanks for telling me
can anyon eplease help?
do you get the same compiler error in unity?
also have you tried reloading the c# server?
yes I have
I'm stupid and blind...
lol
If my question isn't artist related, but code related, would I still go there?
Does it actually throw an error in the unity console too?
when making a game do people first make the different mechanics work before structuring the game, or start from the start screen and go from there?
definitely not from the start screen
usually you should start with the core part of the game, which depends on what kind of game you're making
okay I think im on the right track then
perhaps the story, or designing mechanics
or even a specific system that everything would feed into
how could I lock the movement of the cue around this red line?
so it can't move further or closer than that
currently it follows the mouse when holding mouse click, I was told clamp would work, but not sure how
get the direction between the mouse and the center, normalize that vector and multiply it by the target distance, then rotate it accordingly (using that same vector)
since the end of the cue is the important part, have that be the pivot
multiplying by target distance would make it rotate more no?
I have the pivot at the ball itself though, so it always faces the ball
like in 8 ball pool
...the ball and the cue are the same sprite?
ok, what do you mean by that then
you said have the pivot point at the end of the cue
right, i was assuming 2d graphics
that would mean it can freely rotate by the tip, and wouldn't be locked rotating around the cue ball
"pivot" is basically "origin"
I want it rotating around the cue ball
those are unrelated
having the pivot of the cue on the tip would make setting the distance be between the ball and the cue tip, rather than between the ball and the middle of the cue
it would not
multiplying a vector by a scalar just scales the vector
hmm, I am rotating here by changing transform.forward
I will try it but i dont get the logic
rotating and moving would be 2 separate steps, that both use the direction vector
are you familiar with vector math in general?
i have no idea what you mean by that
direction A to B is the same as subtracting position of a from b
ah, ok.
wow, no ray/overline really breaks that.
anyways, multiplying a vector by a scalar just multiplies each element by that scalar, right?
the ratios of each element are the same, ie it points in the same direction
just the length is different
yh
so i wanna use that for the movement not the rotation
yeah
I googled this but im not entirely sure. Do I need a rigidbody on an object which will hit another item, and make it move. The object itself does not need to act under physics, only user control
(by mouse)
rigidbodies are what handle physics
if it needs to collide with physics rules, it'll need a rigidbody
but you'll have to set position and rotation through the rigidbody instead of through the transform, since the rigidbody will manage the transform
yo i need a code correction can someone help
the goal is for the red block to track the player and only move in the x axis making sure that it falls down normally
the vid is dragged out a bit but the point is that it rotates when the mouse moves around the middle, not around the ball
I used a raycast to capture the mouse's position, so not sure why it captures it only from the middle of the screen
ok what's the issue
nvm i got it
there's a few issues im seeing in that code
rb.velocity = new Vector2(direction.x * moveSpeed, rb.velocity.y); it was this line of code
hmm? like
the distance > 0 check is not reliable
floating points aren't exact, you'll want an epsilon there
the point is inside the player tho, the enemy has to collide with the player
you shouldn't set the rotation of the transform, since the rigidbody manages the transform itself, iirc? (though, why do you need to rotate it to begin with)
that doesn't matter
looks like it's getting the direction between the mouse and the middle of the screen instead of between the mouse and the ball
this enemy needs a direction for the projectile
so when it rotates, the projectile comes out of the other end
idk im an absolute beginner lmao
This line?
dir = new Vector3(ray.GetPoint(enter).x, 0, ray.GetPoint(enter).z);
ok, now think about when you add art
now the enemy has a top and bottom
the top and bottom shouldn't switch when it turns around, right?
if the origin is in the center of the screen, yeah that would get the direction to the center of the screen
remember this?
yeah
you do have a point
you need to subtract the ball position at the beginning, then add it back at the end, to use the ball as the origin for that calculation
44 seconds · Clipped by Snow · Original video "2D Bullet / Projectiles in Unity / 2023" by Distorted Pixel Studios
i just looked at the rotation thing he was doing and it was working
soooo i stuck with it
if anything at the end of the day i can just revert its scale to y = -1
I subtracted the pivot points' x and z coords, which works. Although im confused why adding them didnt work
I assume its something to do with perspective
no that's unrelated
@carmine sierra
adding them did work. it put the cue around the ball
but you need to subtract at the start to get the calculation around the ball as well
was confused what you meant by this
if you subtract the ball position from the ball position, what do you get
ah, right, i was thinking about the wrong axis lmao
zero
yeah rotation like that should work fine
so nvm
rotating the z axis would turn it upside down
and that's the origin, right?
think about stuff that's centered around the ball
subtracting the ball position would make the stuff centered around the origin
now direction stuff, which is inherently based on an origin, works correctly
the direction from a to b, is the position of b, in reference to a
so by subtracting the position of a, you get the direction from (b - a) to the origin, not offset by anything
sorry I gotta understand how the ray.getpoint works first
cause I thought it would find the mouse's position
on the plane
i get what you mean but dont at the same time
the world has an origin
yeah
everything is based on that origin
including the raycast
but the calculation you have needs a different origin
which is around the pivot point
subtracting the ball position from everything involved (the ball, the mouse) gets the ball as a new origin
then you can do everything in that new reference frame
adding the ball position back puts it all back in the reference frame of the world
ohhh ok
hmm but if we want to move the origin to the pivot, that could be a vector O->P (P for pivot). So wouldnt that be pivot.transform.position - origin
ray.GetPoint(enter) is at the origin?
origin is 0
no, it's wherever you clicked
hmm so ray.GetPoint(enter) - pivot.transform would be a vector which goes from the pivot to the mouse's position
that's what I want
okay I get it now
thanks 🙏
How can i reference a script instead of a GameObject that has the script, so that all logic operated in a different script applies to every GameObject by itself instead of just the gameobject i referenced?
All of the cards have the same script and i want them to work independently
why not have the script on the cards handle that
show the CameraInteract script, you likely need to change logic in that to interact with any kind of interactable instead of only with a specific object
I believed that making everything that is interactable managed by the camera is simpler as it shoots the raycast
public class CameraInteract : MonoBehaviour
{
bool selected;
bool clicked;
public InteractableCard card;
void Start()
{
}
private void Update()
{
if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out RaycastHit Hit))
{
//Hovering
if (Hit.collider.tag == "Interactable" && clicked == false)
{
selected = true;
}
else
{
selected = false;
}
//DESELECTION
if ((Hit.collider.tag != "Interactable" && Input.GetKeyDown(KeyCode.Mouse0)) && clicked == true)
{
clicked = false;
}
//Selects and states
if (selected == true)
{
card.OnSelect();
}
else if (!selected && clicked == false)
{
card.IdleState();
}
if (selected == true && Input.GetKeyDown(KeyCode.Mouse0))
{
clicked = true;
card.OnClicked();
}
}
}
}
Excuse my bad coding, im still working on my structure
instead of using a field to refer to the card, use TryGetComponent on the object hit by your raycast. that will also eliminate the need to check the object's tag (which you are doing incorrectly anyway, you should be using CompareTag when checking an object's tag)
right, but then the camera shouldn't have to know what it's looking for, otherwise you'd be shooting out a raycast for each type of iteractable
why not shoot a single raycast, then check if it's interactable?
and then the script on the object can define how to interact
this is a great Idea! Thank you
Chat what is this
not a code question, and did you read it?
Oh where can I ask questions related to this and yes I read it but I don't really understand
Alright thanks
then say that rather than 'what is this'. The answer to your question, as asked is, it's a warning message
I mean like why am I getting this and how can I fix this warning-
that is exactly what the message is telling you
Like it's saying migrate existing api to a the new api how can I migrate?
have you written a scriptable render pass? i'm going to go ahead and guess the answer is "no" considering the absolute lack of substance that your questions have contained. so you need to change the setting that the warning indicates so that whatever asset you've downloaded that includes that render pass will work
I do understand it telling me to disable the compatibility mode but, it's after the migration, how can I migrate though?
Migrate existing ScriptableRenderPasses to the new RenderAPI
https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@17.0/manual/render-graph-system.html
and
https://docs.unity3d.com/6000.0/Documentation/Manual/urp/render-graph-introduction.html
have you actually rewritten your scriptable render pass features to use the render graph?
ScriptableRenderPasses will still work, but in newer versions of unity it will be deprecated
No, I don't even know what that is. I just downloaded some assets and I guess it's probably from there.
because if the answer is no, and you have no idea wtf a scriptable render pass is, then you need to use the compatibility mode for that asset to work
I'll check this thank you.
Okay, I understand now, thanks.
Are 4k textures overkill
this is a code channel
where do i ask that
well it depends on the use case, also this is more of a question for #🔀┃art-asset-workflow
oh alr
Guys I’m new at unity programming I was just wondering why do we use for a variable [SeriatizeField] if we can use directly public ?
it's better to not make everything public, you wouldn't want just any object to be able to modify the state of your script just because you're too lazy to make a variable private. if there is no reason that another object should have access to a variable or other member then it should not be public
Cuz if we put it in private we can’t access the variable from another GameObject script ?
correct
Okay ty
fyi, if you want to be able to read but not write from another script, look into Properties
[SerializedField] on a private variable will make the private variable show itself in the inspector
you can do the opposite for public variables to hide them in the inspector if needed [HideInInspector]
I think this is a bit more useful
no
Why ?
if you do not need to access the variables in other scripts
you should not bandage them
do note that HideInInspector does not do the opposite of SerializeField, the field is still serialized, just not drawn to the inspector. NonSerialized would be the opposite
But if you want to access the variable from another script and u don’t want it to appear in your inspector it’s great ?
oops my bad
yes only if you want to access it from another script and do not want it in the inspector use that
at that point just use a Property. in fact, according to the official c# coding conventions you should be using properties for any variable that needs to be accessed by other objects
public fields should typically be avoided whenever possible in favor of public properties
And also is OOP important in unity ?
yes . . .
Im cooked
how could object oriented programming not be important in an object oriented programming language
OOP is important in anything to do with C#
My bad I’m coming from python idk much about it
you should learn some C# then
https://dotnet.microsoft.com/en-us/learn/csharp
and learn some unity
https://www.youtube.com/watch?v=pwZpJzpE2lQ&t=6765s&ab_channel=Imphenzia
EXPAND for Time Stamp Links -- This is the most basic Unity tutorial I will ever make. If you are brand new to Unity, or if you want to make sure you’ve covered the basics, and if you want to learn how to write your first C# script - this is the video for you!
Over the course of 2 hours, I go through the User Interface, Game Objects, Transforms...
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Im not that newbie in unity 😭
okay
I can’t with courses like this I prefer looking at videos, I found a playlist from someone he explains it well I just didn’t finished yet
He explains C#
this course has videos I believe
Hiya, i'm new to Unity and need to use an integer 3-component vector, is there and IVector3 or something similar? Or do i need to define this myself?
you can fill a normal vector3 with int's if thats all that you need
but nevermind actually there is one in unity 😅
There is . . .
I was looking for IVector3 lmao, thank you
'I' would denote an interface . . .
I have some experience with OpenGL and Bevy, where it's usually defined as ivec3
Hi All, I'm working through the Programmer Pathway on UnityLearn, I'm currently at the stage of adding RigidBody to objects after adding in a small script but when I start the game, the vehicle collides with the crate, flies over it and then veers off the road 🙄 This is completely different to how the video presents where it pushes the crate out the way. Any ideas what I might be doing wrong please or is this just something wrong with this bit of the tutorial?
This is the section of the tutorial: https://learn.unity.com/tutorial/1-2-move-the-vehicle-with-your-first-line-of-c#639946f2edbc2a2fc462dd11
I have the same parameters as the video and there's only one script against the vehicle that includes as per the tutorial:
// Move the vehicle forward.
transform.Translate(Vector3.forward * Time.deltaTime * 20);
Vehicle mass: 1000, 0 drag, 0.05 angular drag with Gravity turned on and discrete collision detection.
Crate mass: 20, 0 drag, 0.05 angular drag with Gravity turned on and discrete collision detection. 😕
you can try locking the rigidbody on vehicle although doubt thats done in the lesson. Always found it cringe they make it move rigidbody with Translate
Why are they using Translate to move a rigidbody? That makes no sense . . .
Definitely an improvement, cheers! Not mentioned so far in the tutorial but I presume this is just where you set it to freeze position for the X and Y Axis under Constraints? or is there another way to do it?
Doesn't go flying and off the road anymore, doesn't throw the crates out as dramatic as the video but it's workable now 👍
yes the constraint is usually how you make rigidbody not be affected by external forces/rigidbodies in specific axis
Got it, Thank you! 🥳
how do i make a gameobject access the sprite of its child?
For movement do yall usually use Input Maps or just if(Input.GetKey(KeyCode.YOUR_KEY));
Input class is now considered legacy, but I still use it
Alr
won't stop me
lol
For me it’s easier and whatever can make my experience easier to create I’ll use it.
I want to set up my damage dealt to player based on distance from source of damage, but I'm not sure how to get the distance between 2 objects while accounting for negative vectors. I was gonna set up a local float and subtract the two vectors but it occurred to me that would return negatives, depending on the position of the objects. Is there a symbol or something I can use to convert the difference between two vectors into a positive?
Vector3.Distance will just give you a positive distance
for future reference, what you're describing is the absolute value, available through Mathf.Abs
thank you, and thank you for the name of it. I knew there was a name but I couldn't remember what it was called
If -- subtracts 1 from a variable, how do I subtract more than that?
-= number to subtract.
This is really very basic knowledge you should have
I got confused when they were explaining it in the tutorials. I've only been working with Unity for a few weeks
so += would just add the numbers then?
then maybe you should do some basic C# courses
I am
yes
I'm working on one of the last projects of the junior programming course through Unity Learn
better to look here
https://dotnet.microsoft.com/en-us/learn/csharp
for basic C# knowledge
x •= y is shorthand for x = x • y for arithmetic and bitwise operators
That also goes for /= for division, -= for subtraction, and %= for modulation
I appreciate the notes
yes that's why i said arithmetic operators
I know. I just wanted to give the specifics.
Dont think modulation is the word you want, modulus is the math term but in c# % is actually called the remainder operator
it's pretty much the same thing. it's not called the modulo operator because modulo isn't an operator, it's more of a context
They are not the same thing, the result can be different in cases
there's no "result" with modular arithmetic
Yes there is
How do u set up an enemy AI NPC?
in code 5 % 2 == 1, 5 != 1 % 2
in math 5 ≡ 1 (mod 2), 1 ≡ 5 (mod 2), 5 ≡ 3 (mod 2)
What? @naive pawn
not directed at you, sorry
You'll have to be more specific as to what you want, this isnt possible to answer just as is. Look up tutorials if you have absolutely no clue where to start
to clarify: there's no "result" from "mod" in modular arithmetic, it's not an operator
Pathfinder is what I mean. It's terrible
The character just disappears randomly
And sometimes it flies in the sky.
It should not do that
I have set up an area for detection of the player, but it doesn't follow the player.
Also my grammar is bad so don't judge me
tf you mean your grammar is perfect
My words might be confusing
What you've shown is like first year uni examples. I know how mod math works. Look up any docs related to it in computing and try to find something that isnt an operator.
in computing
did you miss the part i said i was talking about math
im literally talking about "mod" in pure modular arithmetic being different from the "mod" in computing
Then you're talking about something completely different from my point above. My initial point was saying c# is the remainder operator, where it will give different results from modulus, ex: negative numbers
you brought up "the math term", so i assumed you were talking about, yknow, math
Look at the #854851968446365696 on what to include when asking. Also no one knows what kind of AI you want so this isnt really possible to answer
That was just because they said modulation, which isnt the correct term. Not sure how else I couldve phrased that
fair.
I want to learn csharp, wheres the best place to start?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
there's some stuff specifically for unity there
or you can try microsoft's resources for c# itself
but before you try to learn C#, learn to Google
I want to build AR APP ?
please don't go around pinging random people, just !ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
I thought unity is good choice over godot
Ok
you are not going to build very much if you do not learn how to search for information
depends what you want to do and how the workflow suites you
is slider not a component
are you sure you are requesting the Slider from the UnityEngine.UI ?
I called the slider object as a gameobject
wut ?
I think unity has mich more developer friendly tools. It's way easy to learn unity over other ar tools
well then there you go, you just aswered your own question
Don't worry I will build something 😉
what's the erroring code
[SerializeField]GameObject powerSlider
then I do getcomponent<Slider>
where?
show the current code
again, that doesn't answer if you're using the correct Slider component
show your usings maybe
sent it a bit up
it should be from UI, not UIElements
you're not though
it's probably just ide lag, given the misaligned error highlights
namespaces are like "categories" in which Classes are bundled inside
yeah, thats what UnityEngine.UI is right
yes its a namespace
also why can't I use SerializeField for sliders but I can for gameobjects
the using at the tops are just shortcuts so you don't have to keep preceding the class with its namespace
yeah
those 2 things are unrelated
who says you can't
but maybe you had issues because you were using the wrong slider before
there's different slider types?
no, you were just using the wrong definition
yes ofc there are
UnityEngine.UIElements is the UIToolkit
oh so there's different sliders depending on whether its uielements or ui
which do i want then
hello im trying to make a ribbon for a spear that uses DistanceJoints2D for animating it, but im running into issue where it spreads apart too much, any idea why?
using UnityEngine;
public class ProceduralRibbon : MonoBehaviour
{
public GameObject mainPoint;
public GameObject ribbonSegmentPrefab;
public int segmentCount = 10;
public float segmentSpacing = 0.5f;
public float segmentGravity = 1f;
public float maxSegmentDistance = 1.0f;
private List<Rigidbody2D> ribbonSegments;
void Start()
{
InitRibbon();
}
public void InitRibbon()
{
ribbonSegments = new List<Rigidbody2D>();
for (int i = 0; i < segmentCount; i++)
{
GameObject segment = Instantiate(ribbonSegmentPrefab, transform.position - new Vector3(i * segmentSpacing, 0, 0), Quaternion.identity);
Rigidbody2D rb = segment.GetComponent<Rigidbody2D>();
ribbonSegments.Add(rb);
DistanceJoint2D joint = segment.AddComponent<DistanceJoint2D>();
if (i > 0)
{
joint.connectedBody = ribbonSegments[i - 1];
}
else if (i == 0)
{
joint.connectedBody = mainPoint.GetComponent<Rigidbody2D>();
}
joint.autoConfigureDistance = false;
joint.distance = segmentSpacing;
joint.maxDistanceOnly = true;
}
}
}
told you, the UnityEngine.UI one
thats the Unity UI Package
not UIToolkit (the newer UI) which has no inspector components , just uses an external XML like structure or c# but you can't serialize it
nothing you should worry about for now though
wdym not valid ?
'Cannot access non-static property in a static context'
what's the code now
are you not using the instance of the slider.
why would you do that though
well i guess you're not
you were getting the slider just fine here
why did you remove the part that was correct
just make a reference in the inspector as you did with the GameObject
and then use the instance
[SerializeField] Slider mySlider
cause I was initialising a gameobject and THEN getting the slider, getting the slider directly is quicker
but you're not getting the Slider, you're getting the definition of a class.. Just a blueprint.
you need the **Instance **
the Specific Slider created, the one on the gameobject
oh, but with rigidbody components you can just reference a rigidbody without getting the component right?
If I remember right (havent done this in a few months)
you can but you shouldn't
how's that related ?
So type Slider isnt the same as the component
both components im referencing
Anything on a gameobject is a component mate
exactly
but those are the instances you need to reference
so why does it work with rbs but not sliders
unity has fumbled MB properties
you should just GetComponent like any other component
why i cant reach my camera script to activate
alr
you're gonna need to elaborate
"reach"? wdym
if (Input.GetKeyDown(KeyCode.Space) && !isMovingUp)
{
isMovingUp = true; // Start moving up
// Activate the camera movement when jumping
if (cameraController != null)
{
cameraController.ActivateCamera();
}
}```
i try to activate the script on the camera
so whats wrong?
have you tried debugging at all?
Debug.Log inside ActivateCamera and so on
I realised the name was just incorrect, I didnt need to do getcomponent, so now im more confused as to why you said i should do getcomponent
You don't need GetComponent if you have references already linked in the inspector
you would do GetComponent if you had a GameObject to start, like you did originally
yeah
always Get a specific component when possible, you almost never need to use GameObject field
thats what I did
yes, just saying in the future
you said that what I had before was correct though, which was using the gameobject then referencing the component
if you need a gameobject without specific component , I usually do it as Transform
why?
because its more likely you will use the trasnform than gameobject
any component can access its container gameobject / transform anyway
show the full !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.
why do you need that SerializeField anyways
why not just make it public
making everything public by default is bad design
it's probably just ide lag, given the misaligned error highlights
public sounds dodgy like i could accidentally reference it
idk if im stupid though
for unity fields specifically? 
accidentally changed
n yea you should always make thing privates
yeah it worked
for any fields in a class..
no, i mean, even for unity fields specifically?
intelliJ is bad for unity or smth?
I never use public fields, if something else needs access, I make a property
never had ide lag on vscode
yes. You should be using VS or Rider
i use publics specifically for stuff that goes through unity, i do use properties for access between classes
wdym "through unity"
serialized fields, messages, lifecycle methods
why make everything public thats on MB ? thats just bad design imo
so serializefield is a good idea right? when I just need to locally change an integer easily through the inspector for example
me? Idk what mb is
i don't, i use public specifically for the stuff i want to show up in the editor
yes yes, just keep in mind Public does put it in the inspector too, SerializeField just makes it so its visible in inspector but not changable from other scripts
thats silly lol
Thats literally what SerializeField does for privates
yeah i don't really like it tbh
I'm not even gonna bother asking why, thats nonsense
not in concept, just feels unnecessary when you can just use a much smaller token
smaller token? ?
idk i can't really explain it. nobody gave me a convention so i developed my own and now im just more comfortable with my convention i guess lmao
my brain hurts
to me, SerializeField on a private feels like doing private to hide then SerializeField again to reshow it

can't explain it
to show it only for the inspector..
yeah i get that
but other classes dont accidentally touch any fields in that class
yeah i just don't do that
thats what props and methods are for
i mean to each their own, just saying its bad design and not typical of C#
i was never shown typical C# lmao
encapsulation should be one of your first lessons then lol
oh i know it well, i used to do java
well then why would you break all of that in C#
its literally the same language (almost)
all the unity c# tutorials use public, i found out about SerializeField much later
yeah cause they're shite tutorials
...literally all on the unity learn page
its honestly not a big deal if its just you on the project anyway, but its bad design and you should always encapsulate even just to protect yourself from your future self
that doesn't mean its good
Unity != C# standards
...weren't you the one defending it to me a year ago
"public" to me means accessible outside the "package" (from java), and unity is outside the package, so i use it for stuff that goes to unity 
in what regard? cause I do heavily criticize Unity and their inconsistency
public means anything else can change your score even though its not meant to be public SET etc.
why would you open yourself up to the possibility of accidentally changing something that you shouldn't change
its a thing because then you or your coworkers wont accidentally use that public variable from other classes. otherwise why not make literally everything public then?
because i don't want to see random stuff about state in the inspector?
what state? serializefield private is same as public for the inspector isnt it?
i found the convo, it was much shorter than i remember, so nvm i guess lol
i know what it means lol
orly ? I'd love to see it 😛
you're assuming this preference is rational
this is the only reason for it
it doesn't make sense lol. but im already used to it
at least your self aware of it which what makes it strange willing to choose it over just privatizing it
im very much not used to attributes
its not that much work putting an attribute instead of public
even less so attributes that have effects rather than just validators (like Min or Range)
it is when you have a ton of muscle memory for the latter already
imo, you'll learn/use them when u need em
well hey, when you accidentally change the wrong fields later down the line.. You know why 😅 you do you though
(for access modifiers, not public specifically. java's default access level isn't private)
what is it then?
package-private, aka internal in c#
i hate java lol
yeah internal can be accessed from within the same assembly
not comparible to private
yeah i still have no idea what you mean by this.
i know how encapsulation works, i just don't use it for inspector fields
nah only used them a few times when i needed to compartmentalize everything
it makes a chore using assembly definitions tbh
If I wanna detect if the mouse is down on a slider, should I give the gameobject a button component? or is there a way using the slider
they both are exposed in the editor.. only difference is one is public (accessable from any class within that assemb) ooor private.. (only th class that contains it)
its good if you're making an asset though but might confuse your users
there dozens of ways
...are you trying to make the slider work yourself?
it already has drag and hover/click colors built-in
not really a need for it to be a button unless thats the way u wanna do it
ya, i make my own sliders
i think unitys sliders are gross
wdyn "down on a slider"
oh slider has OnChanged event you can listenn to
damn, that link sends u thru the entire internet to get to the landing page
affiliation much?
lol
you can however get OnPointerDown for example by using Ipointer interface
or event Trigger component
no it's through a browser's search iirc
ya, duckduckgo
i seen it flash in my browser for a second
as long as they know if the mouse is down on it or up thats all i need from now
but how do I access those states
its the setup/ margins/ and all that i dont like
https ://justlink.to/mdn/mousedown redirects to mdn directly but not really used to typing it
u need to redo the entire slider to make it work like i feel it should
do you need to?
yes, yk 8 ball pool, how the slider snaps back after firing
I need to detect when the mouse releases
now my question is, should you be using a slider for that lmao
look at the events I sent you
eh i guess that makes sense
The script I want to detect the mouse's state on the slider, is not on the slider
it's on the cue control script
on the cue
so i couldn't use the pointer method could I?
you could have the slider be a child of the cue
doesnt make sense in the game
why wouldn't it
no its needs to be on the slider gameobject
but you can use an EventTrigger component instead of script
weird layout in the hierarchy
having the controls for the cue, within the cue?
true, but its UI
I can child UI in a gameobject?
i think they want to use the Slider to give "power" to the cue
yeah
yeah, just needs a canvas and then have the slider in the that canvas
ohh right, forgot about those
why not just use the OnValueChanged ?
thats how i do it when i do use sliders
oh nvm i lied..
mine update w/ Update()
cause the value changes while the player is choosing the fire power
yea? isn't that what you want so you know how much force to apply?
if theres visuals u may need to update during the drag tho
or are you gonna launch after the slider was released? this is tricky
and then when release set ur final value
yeah, its not tricky dw, the event trigger makes it work as intended
not too hard
it could be totally seperate
when mouse release (check on what happened w/ the slider)
no need to use weird hover crap on teh slider
yeah but everyone does it different lol I never used a slider on mine but the Cue itself as the "slider"
further from ball = smack the ball harder lol
who hasnt played 8ball? (Pool, Billiards, Etc)
to me if ur making a pool game sliders dont even make sense to me
i'd track mouse positions
click -> get position
release -> get position
then do the math.. get the direction/distance etc
oh god, does golf count as a cue sport
use mins and max to calculate power
u dont hit golf balls w/ cue sticks
but its similar lol
Yeah that makes sense. I was doing that initially but I think 8 ball pool's mechanism allows for way more accuracy (even without the ez guidelines)
they are pretty similar, was thinking if you could bend the definitions but i don't think so
many pool games lets choose the power but there is another view usually for applying specific spin
let me ask a question since we're on the topic..
if ur making a power meter w/ one u prefer(or is more fun)
click and have the power meter ping pong from 0 - max until u release
or
click and have the power meter go to max and then back to min.. and if u miss the click u get min power?
one is more forgiving ofc
yh 8 ball pool has that too
first one
me too minus the small town thing hehe i'm in the city of rats.. i mean nyc
ohh dear
I live in London and pool is still up there for fun things to do
i thought yall played snooker or something
isnt that a specific type of spin?
i thought it was all types of spin
i'll have to check hang on
yea its all spins
SIDE spins i guess
I was just talking ab this yesterday. I thought snooker/pool were the same thing. Snooker is a diff game they just use red balls and one pink
no one plays snooker
casually
snooker is like pinball + pool
side spin seems impossible
like doesnt that mess up the whole aim if you flop it
nah. its pretty easy once u play a bit
well thats the point
get good lol
top spin is ez
using top / bottom spin causes alot of ppl to launch the cue ball off the table
lmao
random question what floor could look better than this
Not a code related question
true
make it darker
use a texture, also pool tables are cloth and not really that reflective
but yeah this should go in #💻┃unity-talk at most
good idea
After I release firing, I need the cue to hit the ball and apply a force. Is the best way to do this to be applying a force to the cue and let it hit the ball that way
this is entirely up to you, and some can workout better than the other..
relying on unity physics has its pros and cons
maybe if the masses are the same and it's an elastic collision?
but idk if you can guarantee that
if it's inelastic, the cue would follow the ball a bit after the impact, unless you specifically stop it
maybe you can do that by setting the materials appropriately, but if not, you could apply an impulse force on the ball when the cue hits it
im thinkin you'll def have to manipulate the ball a bit urself
yes i usually nudge these types of physics with Reflect, the bounce material can help a bit but its unreliable
I am building somewhat of a studio application in Unity for windows.
Users will be able to import large files. (audio, images, and video) and the game needs to persist them.
Users will be reading and writing to the folder that stores these files often.
Can I use Application.persistentDataPath ? Or is there a better directory?
sure, or use assetbundle/addressables
So i tried the addforce method, but to get enough force in to move the balls as intended, the cue seems to move so fast that it clips through the cue ball
should I just do the annoying thing of downscaling the mass
or is there a better method
It worked O_O but how
https://docs.unity3d.com/ScriptReference/CollisionDetectionMode.ContinuousDynamic.html
do note this is probably the most expensive computations out of all the modes
if you can get away with it pick continuous only , but dynamic helps if both bodies move pretty fast
considering its just one hit movement it should be fine
whats the other body?
the thing it hits?
might be overkill here , might be able to just get away with the regular continuous
so both should be continouous
ball is rigidbody no? cue is rigidbody no ?
it worked with just the cue being continouous
mhm continuous should be okay since they're not moving so fast
but it does exactly what it says, thats why those are generally more expensive but its okay in such smal usecases
only dynamic works
so discrete is like fixedupdate and continouous update
no its just doing many "sweeps" as oppose to estimations
yes like based on how fast this thing is moving will it hit this thing
discrete uses the discrete algorithm to check for collisions and check on the physics steps so for fast and quick collisions it might fail
https://docs.unity3d.com/6000.0/Documentation/Manual/discrete-collision-detection.html
also keep in mind there is a limit of speed for when collisions will just never not be wonky
like a max cap of speed, but you should theoretically never go that fast with a pool ball
and if it's too fast, then the other option is raycasting between where the object was and where it is now
yes, it may be more expensive to do to so, so this is why people fake speed with effects
like speed lines if that makes sense or FOV changes
rigidbodies should really handle a lot of clipping itself assuming you use forces
but it's far from 100% proof. I do think my own interpolation via character controller is better ;)
One thing though that we don't really think about is objects traveling at quick speeds at an intersection. Rigidbodies will actually try to account for that
what, like a car intersection?
continuous rigidbody can fail and go through walls too
Right, you can't easily raycast forward in that situation
I have a small problem where in my script it is not recognising the PlayerController class? Any ideas?
you can calculate the new direction
but then that would be even more computationally expensive
It probably some some calculations for intersecting some shape casts in those scenarios, but it only will detect others via continuous
Does anyone know why..
You've posted nothing and we can't read your mind.
What do you mean not recognising?
Did youi create a class with that name?
classes should be in PascalCase
where did you create this playerController
your original message says it was PascalCase
so have you tried referencing it using PascalCase
Yes
capitalization matters
prove it
also when you have a red squiggle it means there's an error
Is PlayerController not a built in class
you need to read the error message
show where you defined this class
it is not
of course not
are you confusing it with CharacterController?
I'm trying to make a GameObject transparent at changing the GameObjects color alpha, but it's not working.
I'm using a basic Sphere.
you're confusing with CharacterController maybe ?
the default material is not transparent
you need to use a transparent material
I see
Is their a built-in material I can use, or do I need to find something in the asset store?
yes you just need to make one using the standard or Lit shader and set it to Transparent
creating a new material usually defaults it to the pipeline's lit
hello, im new to unity and im doing a little horror game for my personal experience. I have a problem with an interaction with colliders. The trigger does not detect my object... Could someone help me fixing my issue ?
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
noone can help if you don't provide details
The trigger does not detect my object
You would have to explain how you set everything up.
have you checked the layers to make sure they can detect each other to begin with?
can anyone come to speak so i can explain it?
no, you can share a few screenshots
but basically if it's not working you didn't set it up correctly
you need:
- Both objects must have colliders
- At least one collider must be a trigger
- At least one object must have a Rigidbody
!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.
I am making a full body fps controller and I have these camera positions set up so when I am jumping walking or running the positions will change. When I jump and as I fall and touch the ground you can see briefly the camera will go to idle position then the landing position which I don't want. Here is a video: https://streamable.com/op77wu
CameraPosition script: https://paste.ofcode.org/bpNjJqeAHTxrihctzhEmPj
Watch "Game Idea - SampleScene - Windows, Mac, Linux - Unity 2022.3.26f1 DX11 2024-11-02 19-26-24" on Streamable.
we would need to see the playermovement script and to show us what you use to identify "landing"
does the your animator have any exit time to it when playing the landing animation?
no
Its not the animator/transitions or the animations it's most likely the camera position script but I don't know what I did wrong
I was just getting more information to check boxes is all
I think the problem is the idle position when I remove it that problem is gone
Your right theres nothing wrong with my script it was the animator
sorry I didn't respond, it works as you expect it to now?
hmm kind of but I don't know what I did but the problem is still there but when you are playing you cant notice it lol
Can anyone help me make an inventory system or give me a link to a tutorial? Been looking for a while and all these tutorials haven't really worked and I just end up back at square one
there is no such thing
inventory you're better off making your own system
what you see on youtube is just how different people solved their own way, you essentially will be copying someone elses system and in turn when something break you probably wont know how to fix it, or add onto
much better you build from the ground up the way you want / need it
That is what i was thinking
A lot of these tutorials arent what im going for
My only problem is I have no idea how to code it
of course , every project is different with specific needs
start small, build up as with anything else
you won't learn what's best for you until you experiment multiple times , it will probably not be good the first few times but as you keep doing it you realize what you do or don't do on the next iteration
Yeah this project is definitely biting off a little bit more than i can chew in terms of programming so maybe ill go ahead and make something smaller for now. Thanks
you should start with beginner c# courses, like the ones pinned in this channel. then when you have some idea of how to use the language, you can break down what you want to do into smaller steps that you can find individual tutorials for and combine that knowledge together to make your stuff
Thank you very much will do
Can I not reference a static class directly?
what issue are you encountering when trying?
I'm trying to reference the static method IFFT2D from static class ComputeFFT but getting a "the type or name space IFFT2D does not exists with ComputeFFT" error
have you imported the namespace
do you happen to have a namespace and a type called ComputeFFT
I have it as a class within the same folder
and is that class in a namespace
yeah i had two thanks
Sorry. Can you give me some advice on what I need to know about Unity C# to get started working in studios?
What do you mean by "studios"? Unity just uses normal C# and unitys API with it which is on the !docs
If you mean actual job applications then you would want to learn C# inside and out and use unitys documentation as well
I mean studios that work on games (indie studios)
Learn C#, then learn Unity API . . .
<#💻┃code-beginner message>
How do I add a debug log?
Nvm
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
can someone help me with this code?
for (int i = 0; i < 5; i++)
{
SliceEffects.emitting = false;
float x = Random.Range(-100, 100);
float y = Random.Range(-100, 100);
yield return new WaitForSeconds(0.2f);
this.transform.position = ems[0].transform.position + new Vector3(x, y, 0);
Debug.Log(SliceEffects.emitting);
Vector3 direction = transform.position + 2 * (ems[0].transform.position - this.transform.position);
yield return new WaitForSeconds(0.5f);
SliceEffects.emitting = true;
this.transform.position = direction;
//while(Mathf.Abs(transform.position.x - direction.x) > 1)
//{
// transform.position += direction.normalized;
//}
//this.GetComponent<Rigidbody2D>().AddForce(direction);
yield return new WaitForSeconds(0.2f);
}
slice effects is a trail renderer
anyone know why the trail is still showing when emitting is supposed to be false?
it stops emitting more trail parts, but the existing ones continue to exist
I want to move a GameObject based on the rotation (Forward and Right) of the players camera, but if I'm looking downwards and move forward, My GameObject will move forward and downwards. How do I make it just move forward, no matter if my camera is looking up or down?
Get forward vector, set y to 0, normalize
You would get your forward vector from the camera, including the downward angle, then use ProjectOnPlane with a plane aligned with your ground
https://docs.unity3d.com/ScriptReference/Vector3.ProjectOnPlane.html
Thanks
issue is it doesn't stop emitting more, it just continues to emit
Im using a tileset with 0.5 cell size and when i use
Tilemap.GetTile(Vector3Int.FloorToInt(transform.position));
it looks for the tile on a grid of cell size 1. If i scale transform.position by 2 it almost works but its still off very slightly. is there a better way to do this or should i just add a slight offset to the x and y of transform.position's vector as a woorkaround
!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 Transform.position is in world space, which is not the space your Tilemap uses. You have to convert it with the Tilemap.WorldToCell(Vector3) method.
Tilemap.GetTile(Tilemap.WorldToCell(transform.position))
oh i see. thank you
Hey is there any courses on the Photon API for servers and networking that I could take?
What makes you think you would be able to get an answer to that question in a unity server code beginner channel?
it makes me think that because i am a beginner with photon and i want to see if there are any courses. 👍
and im new here so idk anything about this place
Ugh... Nvm... Read Photon as Python for some reason...
Anyways, there are plenty of tutorials online as well as the documentation, so basically just google.
Yeah I've looked around and most of them are from a couple years ago so I thought they might have been outdated.
Ill look on the Photon documentation and see whats there
Even if they are outdated, a lot of it is probably still applicable to the modern API.
At the very least the design principles and the concepts behind the API stay the same. There might be changes to method and property names, but these are trivial to fix.
FYI if a (static) class is highlighted like this, then it's definitely known
The error occured due to confusion by the compiler as it used the wrong class, not containing the method they tried using
classes can have namespaces?
Classes can't have namespaces. They can be declared inside nespaces.
that's what i thought, so the error is saying that ComputeFFT is a namespace then
it's a known symbol, not a known class
like stated originally, there was a class in a namespace of the same name
No, it's saying that the identifier is not defined. It doesn't know whether the user meant namespace or class, but there is neither.
they're talking abouut ComputeFFT itself
Yeah, if the error is as they quoted, then the issue is with what comes after that.
Hi, my player don't collide with the ground sombody know how to fix it ?
i think the confusion (in this convo) is just lack of context, so let me clarify so we can be done here
- namespaces and types are highlighted in the same green color.
- the context here is that there is a class named
ComputeFFTinside a namespace, also calledComputeFFT - the namespace was not imported, so
ComputeFFThere refers to the namespace, hence the error about looking for a type/namespace.
that's whyComputeFFTwas found, but not the static method. because it's a known symbol for a namespace, not because it's referring to a different class.
your player does not have a collider
add a collider
he have !
where
why do you have it separated
post your !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.
📃 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.
use a paste site
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
screenshot the inspector of your Ground object
i do somting and it work i don't know why but it work
sorry for the inconvenience
might be a good idea to think about that 'someting' (sic) so you dont make the same mistake again
yes !
That wasn't my point
You mentioned that they might have forgotten to import the namespace
and they did
The compiler knows that the symbol exists, so it's not a matter of importing the namespace
that was the issue
it was lmao. the symbol was the namespace
@burnt vapor
the fully qualified access would be ComputeFFT.ComputeFFT.IFFT2D(...)
So the issue was ambiguity, not a lack of importing
Or in other words, don't name these things the same
it was a lack of importing lol
was someone else's package 🤷
it's on the asset store
can we be done with that issue now?
thanks.
Here you go, this was likely the issue: https://dotnetfiddle.net/dBd4Aa
Test your C# code online with .NET Fiddle code editor.
As I tried explaining, the compiler was well aware of the class existing, but it picked a different one.
Judging by the short conversation, they indeed had two classes of a similar name added, one having the method.
"the type or name space IFFT2D does not exists with ComputeFFT"
does that look likeComputeFFTis a class to you
here, try this
namespace Foo
{
internal static class Foo
{
public static void Bar()
{
}
}
}
internal static class Main
{
public static void Z()
{
Foo.Bar();
}
}
```notice the similar error message?
can we *finally* be done here?
no, that thinks ComputeFFT is a namespace and it's looking for a class or sub namespace IFFT2D within it
You're not required to answer if it's too much trouble 😉
But yes, it's clear. Things like this can be avoided if we just named things properly
you're the one trying to convince me about something that isn't true lmao
Indeed, but I see the exception is in fact different. I was confused by the syntax highlighting
so did you miss my clarification message
the one i wrote specifically to clarify the situation
- namespaces and types are highlighted in the same green color.
It doesn't really matter when it's unclear what the code would actually have to be like for such an obscure thing to happen
Also no, I didn't. Wasn't my convo you replied on
I think this is settled then 👍
i pinged you. #💻┃code-beginner message
I have a grid/turn based game, and I've some buttons on screen, so the problem is that the buttons didn't block the raycast, so when you click on a button the unit will get also the command to move on the cell that sit below the button 🙄
I'm trying to stop the action before by raycasting but isn't working.
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out RaycastHit raycastHit, float.MaxValue))
{
if (raycastHit.transform.GetComponent<UnityEngine.UI.Button>() != null) return;
}
also, by using EventSystem blocks everything so I can't use it neighter.
void Update()
{
isPointerOverUI = EventSystem.current.IsPointerOverGameObject();
}
private void OnMouseClick(InputAction.CallbackContext context)
{
if (isPointerOverUI) return;
Because on this way the canvas cover the entire screen so I can't click on the objects in the scene 🤔
Why would the canvas objects cover the whole screen?
Is this script on every object or just your input manager etc?
Because ScreenSpace Overlay 🤔
No but only raycast target elements inside the canvas should count for IsPointerOverGameObject
Looks like Unity 6 EventSystem consider the canvas UI too 🤔
the canvas has always been UI. It is the base of it
Ok.. nice to know, at least I know it's not a U6 issue. 😁
ive tried setting up player collisions over and over and i cant seem to get it to work my character is just always passing through the objects
so do you have a 2D Collider on both objects and a Rigidbody2D on at least one of them?
yeah
show
be helpful to actually see ALL of the information about the colliders
oh yeah sorry
to start with your Rigidbodies are both Kinematic, so that wont work
do you know what Kinematic means?
like it wont move? doesnt have acctual mass
so should i use static for my object
but i dont want my character to have any mass?
then create a physics material for it
Hi, I need help. When I load another scene my all textures will appear black
for no reason
any sollution
Check that the scene you are loading has its lighting setup
also, not a code question
oh
Use #archived-lighting next time, also check this https://discussions.unity.com/t/loading-scene-additively-causes-change-in-lighting/687635/13
But if I play the scene separately there is no need for light
but yeah
It was the problem 💀
then set mass to 0 on the rb
Hey, what is the expected way of sharing variables between classes in C#/ Gamedev? I'm taking a course on udemy, and what infuriates me is that while SpawnManager, Player and it's movement limiting, and Enemy and their movement limiting are using exactly the same area bounds, I don't know how to share that one array between these classes
In React I'd have just exported a constant and called it a day, but I guess there's other way of doing that here 😄
You'll get a lot of answers. I think that, especially starting out, it's reasonable to have one central 'store' that holds most of your game state (to put it in react terms)
for constants, you probably want to use ScriptableObjects
(but it could also be, like, one big SO with most of your 'content configuration' in it)
also, the answer differs for unity vs if you're freewheeling it, so keep that in mind
how can i make my player flip on the y Vector3 localScale = transform.localScale; localScale.y *= -1; transform.localScale = localScale;
I see, I guess I'm too early into the trip then, as I'm yet to start learning ScriptableObjects, feels like either I'll get that later, or will do that later by myself. Thank you for the answer o/
if you only want one instance of a class, you would have a public static Instance property, which allows you to manage the state from anywhere
that will flip them, but it won't rotate them
yeah, the thing is that you'll get a lot of bad answers because most people don't actually ship anything and what you're making matters a lot in terms of how you want to store/manage your state
yes that what i want revert direction
so my advice is to
- don't get caught up doing things 'the unity' way, because it's bad. do what makes sense to your programming brain
- make what you're making and solve your real problems
I was about to ask, as I can see that ScriptableObject is relatively new addition, and Unity 2019 which I'm at right now doesn't support it yet. I guess I'd have to either find a way, or use 2022
you can use quaternion.lookrotation to build a new rotation that points towards your transform's -y
I would just download Unity 6
not sure where that info is from? SOs are old and have been supported for ages
me trying to find it and failing, but that might be a mistake on my end
they've been around forever
You can think of SOs as object instances which you create in unity (at 'design time'), versus in a scene/prefab or at runtime. They exist independent of all of that, so you can reference them within/across scenes
they allow you to create an instance of a class and storing it as an asset. It's useful for, e.g. a weapon system, where you want more than one weapon of a specific type
so if what you want is 'data that you can read/write from multiple scripts', they're a good solution
functionally the same, but different inputs
!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.
i dont get it my plater 2d not moving towards the new y pos when rotated
are you moving them relative to their transform.forward?
yes i noticed first it moved on global
i using localpos now
but still moves forward
or up in this takes
Vector2 newPosition = (Vector2)transform.localPosition + (moveSpeed * Time.deltaTime * Vector2.up);
well that is what you are telling it to do
yes but up i mean on the new y-as
not literally up
so if i face with y to the left
i should move up but moving the left ofcourse
transform.up
i try to flip it
i tried rotation on the x-as
which makes sense
but its kind of buggy
i dont get it
{
// Invert the local scale on the y-axis to flip the player
Vector3 localScale = transform.localScale;
// Flip the player on the y-axis
localScale.x = -localScale.x; // Simple flip
// Apply the new local scale
transform.localScale = localScale;
// Log message for debugging
Debug.Log("Player flipped: New scale = " + transform.localScale);
}```
i tried x and y flips
do you mean you want to flip the player left and right? if you flipped its Y axis you would flip it up and down
there's nothing in this code that cares about the scale of the object
isn't up up?
It also depends what you're doing with this newPosition vector
i already fixed it
but uhh... up is upo
i talking about flipping my player
you were asking about movement here
thats old
when i hit a sphere i want my player which is the orang sphere to flip outwards
flip the green axis
i tried to flip green axis
you want to rotate around the x axis OR change the y scale to -1 to change that green axis
yo how we get our axis widget back?
if you solely want to move the orange ball move it to the opposing side of your character or flip the parent which in this case is the magenta ball
how do we open that overla menu?
press the ~/` button to get that menu
thanks
rotating would probably be a better option like Praetor said
got the name right this time
I always mix up the A and E
lol 🙂
It should really be this https://en.wikipedia.org/wiki/Æ#:~:text=Æ (lowercase%3A æ) is,before being changed to ä.
I'm so used to typing fast so I kind of just mix them up
dont we all.
I do not have that on my keyboard I don't think
PrÆtor
surely you know how to type unicode characters from your keyboard
alt and numpad
I do not
since I never use them
Alt+255 is Invisible character, had to use that alot back in the days of old HTML
why this 2d object moves on the z-as? when i say flip on the y-as. ```// Get the current local scale
Vector2 localScale = transform.localScale;
// Invert the Y-axis scale
localScale.y *= -1; // This will flip the player sprite along the Y-axis
// Apply the updated local scale back to the transform
transform.localScale = localScale;```
That depends entirely on your code that does the movement.
(not pictured here)
oh you're asking about rotation not movement
yes
that also depends entirely on your code that does rotation, also not pictured here.
also are you flipping the orange circle solely? If so you will not really see a difference, If you want it to be on the other side of your character you need to either scale the parent, rotate the parent, or move the orange ball via transform