#💻┃code-beginner
1 messages · Page 216 of 1
so you think thats an essential feature to have ?
No idea. Tried it and didn't like it
Pretty sure it's FOSS though?
All of this is very googleable though
Still unclear what you're asking on what the problem is tbh
The themes are what the editor looks like. Like themes for Google Chrome or Firefox, where the background and buttons looks slightly different.
It's a big nothing-burger
Gotcha
- The position of the transform
- How many elements the vector has
Oh, I was scroll locked and we've all moved on, nevermind
happens to me all the time, i hate it . . .
Oh 0 dollar u will pay , tbh thats really good
does .equals in java for two objects not just compare their members? It seems like its doing something else
java?
yeah, for a server
wrong server?
perhaps ask in java server lol
you're in Unity, C# server mate
well its for unity kind of
Im using Microsoft's version of Java
I have a database server for my unity pvp game
its a simple question iwas looking for a quick answer thats all
then ask in a java server?
There's not too many people who know java here
oh ok, thanks
i found a answer to your question
in google
in 10 seconds
But I'm pretty sure it's a full reference-equality unless you override it
it'll return true if two objects are literally the same object
I looked that up but they all say that .equals compares contents vs == compares reference but I dont think thats true
i mean i proved its not true
you broke java? 🤯
equals is a custom implementation, it can compare whatever
== does a ref equals
or so I'd assume
loading two small classes into pastebin ill show
This is probably a question for a java server
why not just make your server in c#..
if it's going to require looking at code
ik some people sounded curious thats all
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
== compares by reference in Java. For strings, you use .equals() to compare the value. C# has no such restrictions because, unlike with Java, operator overloading is allowed
So each type could implement its own behavior for most operators
So are you saying when you call .equals() on two objects it's using the == operator on each member indiviudally?
@crisp token Make a thread, this topic isn't related to this channel.
why not just make the server in c# lols
i’m prettt sure C# lets you == with strings pretty well
strings are not a reference type in C#
I found a tutorial that explains the system in great detail but ima need to still learn alot other stuth so thank you for all the feedback and I am going to reconsider jumping straight into my dream game @rich adder
are they not?
They are
i cant figure out how to do the layer thing correctly, my animations are being weird
what. i thought they were value type jn C#
negative
Strings?
Nah they're immutable reference types.
immutable types
Trust you do NOT want value type strings.
what's an immutable type?
Can't be changed. Immutable.
so what would be a mutable type
As opposed to Mutable, wich can be changed.
Let's check the docs
a type that can be changed?
you can'd modify the string in place only replace it, but its a reference
what do you mean when u say changing a type. Like reassigning their value vs replacing w/ new object?
i feel like i’ve been lied to
string can't be a value because well that would be a lot to pass around, and also its length is not knowen
Strings are normally allocated on the heap in most languages?
string str = "Hello";
str[0] = 'h'; ```
example you cannot do this
Nah. Imagine how bad that'd be if they were a value type. Every time you'd pass it into a function you'd generate a copy. Considering how MASSIVE strings can get, it's asking for trouble.
you have to replace the whole string
the bigger issues is sizing
Equality check for strings in C# does the following, in order:
- Do they point to the same area in memory?
- Is either of them null, or do they have a different length?
- Each character is converted to a
byteand efficiently compared withSpanHelpers.SequenceEquals()(which does not allocate)
Source
that’s why I would try to exclusively use stringbuilder for big strings. I thought they were value type 😂
still good practice to do so
Agreed
Yeah everyone says use StringBuilder or the Span<> type
stringbuilder for building larger strings is mostly about allocations
but yeah would use it if building a large string out over time
ref type does make more sense. i just thought the people who made C# had the same stroke of genius as the guy who made Mathf a struct
Actually stringbuilder is for babies. Real men don't need some so called "builder" and just do raw +.
lol
Galaxy brains use String Interpolation
was supprised it was a struct and not a static class
not that it matters, think it only has constants and methods
and also decided it would be okay for arrays to implement IList, despite arrays lacking the major things that make a list not an array lol
StringBuilder sb = new StringBuilder();
sb.Append("Hello");
sb[0] = 'h'; // mutable```
Mathf has a lot of static methods and fields I wonder why it isn't a static class?
I'm gonna ask again my question, because I think I explained it the wrong way. What I want is to be able to do something over x amounts of time. Example, over 10 seconds I want to be able to move, during these 10 seconds I can move but after the 10 seconds I can't. How can I achieve that ?
because the guy who wrote it was drunk
hello. does doing this only remove the reference from the array? so if i want to delete a dog i should use Destroy()?
dogArray.RemoveAt(0)
Wait it... isn't.
a quick look at it, everything is const or static
Waaaat?
two different things
this only removes it from list not destroy it ( the item)
he envisioned a world where you want to have a couple of different instances of Mathf 
so i need to remove it from the array and then destroy?
yeah, Mathf is a struct
destroy obj first then remove from list
RemoveAt simply removes a thing from the collection
otherwise you have no reference valid
Same guy who made Random static decided to make Mathf a struct.
thank you
Random isn’t static tho
System.Random is not static
Unity's Random is
The Unity namespace has a Random class to
the Unity version . . .
I get that fucking conflict all the time
idk, I only use System.Random lol
Are they not the exact same thing?
i like the system one when i need to control the seed
but the unity one has very useful stuff for games on it
like unit vector values
Hello ChatGPT has assured me that this function will loop until fishCaught is true based off of coroutine functionality, but its not working for me rn so I just wanted to double check cause im doubtful
public IEnumerator StartFishing()
{
bool fishCaught = false;
if (UnityEngine.Random.Range(1, 101) <= 10)
fishCaught = true;
while (!fishCaught)
{
yield return null;
}
GameController.Instance.StartBattle(BattleTrigger.Water);
}
insideUnitCircle and insideUnitSphere for example
Can someone help me on this please ?
we should have a rule, do not fix broken gpt code 🙄
well the loop part is doing nothing
ChatGPT is not the end all of stuff being certain
and did ChatGPT write it for you?
essentially it tries to catch fish once and if that fails it loops doing nothing forever
then why are you asking ChatGPT a question about something which it does not understand
Nah. I don't exactly know if the actual implementation of the random number generation is different, but Unity's has a lot of extra methods that're more "game dev" appropriate.
That code will result in an infinite loop
Right yeah let me go check what ChatGPT does and doesnt understand before I run it by it
also, this is definitely an infinite loop
luckily not the one that crashes, the function will just run forever
you have to learn how to program GPT will not do that for you
wasn't there somebody in here before saying how chatgpt was amazing for code comprehension, and good for juniors or s/t?
ChatGPT doesn’t understand anything. It works by a syntax-based language model
feels like it happens almost 1-5 people
it cannot explain, as it does not know
anyone with a bit of experience can look at that code and see its broken and not working to intent in half a second
So the bit I was curious about is how I can get it to generate a random value until it gets one that sets the fishCaught bool to true is my only option to use Update?
It's good at explaining things. You can't make an entire game from chatGPT if u don't understand how the unity editor works and C# on a deeper level
you put it inside the while loop with a sort of Time Between tries.
Ok so next time just say dont use ChatGPT cause I dont like it
it’s good at making convincing explanations. as to whether or not the explanation is true, that is a different story
just think about what the code is doing line by line
it can be done in many many ways including a coroutine
I like chatGPT. But not for coding lmao
If you want it to generate in the loop, it'd probably make sense to generate it in the loop
Ah yeah im an idiot
my lovely secretary 😈
Stick your random number generation inside of the loop. Then you can yield some time between checking if you don't want it to be instant.
also whole thing can be simplified if you are just wanting to wait till you catch a fish
since then its really just about a random wait duration no loop needed
Good idea, So just to check whilst im on the subject yield returning a coroutine starts it over from the beginning it doesnt return to the point it stopped at last time?
var time = new WaitForSecondss(timeBetweenChecks);
while (!fishCaught)
{
if (Random.Range(1, 101) <= 10)
fishCaught = true;
yield return time;
}```
yeah, you just generate a random wait time, and yield return new WaitForSeconds(thatTime);
no while loop involved
yield return new WaitForSeconds(Random.Range(minWait, maxWait));
It doesn't start it from the beginning. It just waits that amount of time before going to the next line. In your case, the next line would be at the top of the loop.
much better for gameplay with some rng
Hahah yeah I never even thought about that
Ok thanks for your help everyone
I have make a RocketGame , i can move up and i can move down , the problem is i dont have collider for the map and i can go out of map, do you can help me how i can make a collider for my window in android
Add Component > Collider
No... pls read again
@buoyant knot https://docs.unity3d.com/ScriptReference/Mathf.html
No instance methods.
Doomed.
wdym "make a collider" ?
you not a smart peopel
no sorry 😔
i mean a collider for my window on my phone that i can not go out of map
Position the colliders in the world according to viewport points:
Vector3 top = cam.ViewportToScreenPoint(new Vector3(0.5f, 1, distance));
Vector3 left = cam.ViewportToScreenPoint(new Vector3(0, 0.5f, distance));
Vector3 right = cam.ViewportToScreenPoint(new Vector3(1, 0.5f, distance));
Vector3 bottom = cam.ViewportToScreenPoint(new Vector3(0.5f, 0, distance));```
rude
we only have tiny brains meant for the beginner of concepts. please show us the way . . .
teach me oh great one
@wintry quarry thanks for the script do you have a tutorial for me that i can see what i must do
no I don't have a tutorial
Hes chosen a smart man
just my recommendation and simple example code
The f.
Don't
if i .RemoveAt(0) an array will a .Add insert into 0?
no
the docs tells you how add works
Insert()
you cannot add to an array . . .
also assuming you mean List
if you add to a list, it goes on the end . . .
thank you
you can google the method name and the language to get the documentation that gives you a description and an example . . .
if (other.CompareTag("GreenObjectCapsule"))
{
IncreaseScore();
Destroy(other.gameObject); // Remove the green object upon collision
PlaySound(capsuleSound);
}
else if (other.CompareTag("RedObjectCapsule"))
{
DecreaseScore();
Destroy(other.gameObject); // Remove the red object upon collision
PlaySound(capsuleSound);
}
}
private void IncreaseScore()
{
score += 1;
UpdateScoreUI();
}
private void DecreaseScore()
{
score -= 1;
UpdateScoreUI();
}
private void UpdateScoreUI()
{
scoreText.text = "Score: " + score.ToString();
// Update UI to display the current score
// You can use UI Text component or any other UI element to display the score
}
private void PlaySound(AudioClip clip)
{
audioSource.PlayOneShot(clip);
}
Getting this;-
ArgumentNullException: Value cannot be null.
Parameter name: source
already assign clip in inspector..any suggestions?
how do you assign capsuleSound
!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.
drag it through in the inspector
use link site and post the entire class
a powerful website for storing and sharing text and code snippets. completely free and open source.
If you are dragging it in via the inspector, do not do GetComponent
That overrides the reference
Is the audio source on the SAME object as that script?
If not, it is returning null
you might be passing null to the AudioSource, if issue was with AudiSource it would give NRE (or log the error from awake actually)
grab layer is a layer mask and I aint sure why it always gets my playwer which is on the default layer
The error is a bit misleading for this one, it's the audio source that's null. In other conditions this would report a NullReferenceException, but due to how AudioSource is made internally, it's the ArgumentNullException that is thrown.
what would be the best alternative? i m a beginner so i couldn't understand
A layermask is not a layer
Remove GetComponent completely
what about this though
private void Awake()
{
audioSource = GetComponent<AudioSource>();
if (audioSource == null)
{
Debug.LogError("AudioSource component not found on the player GameObject.");
}```
tried this i m getting log error
Not related, the error occurs on line 450+
before I had just a RaycastHit2D with a layermask but it always got my player
it made no sense
Show what you set the layermask to
But your layer == grabLayer makes no sense if it is a layermask
its useful but ONLY in very small doses
it can give you 100% accurate help with 1 or 2 lines of code
if you ask it to do a lot of the work it's going to make mistakes or do it in a weird way
The arguments are not correct. You're passing the mask in lieu of the distance. It's origin, direction, distance, mask
so its logging error ?
I don't see an overload where layermask is third
Edit: ah yeah, as spr2 said
but do I need a distance?
NullReferenceException: Object reference not set to an instance of an object
StarterAssets.ThirdPersonController.PlaySound (UnityEngine.AudioClip clip) (at Assets/StarterAssets/ThirdPersonController/Scripts/ThirdPersonController.cs:477)
removed get component still getting this
You NEED to use the correct parameters in the correct order
its Mathf.Infinity
It defaults to Mathf.Infinity. So pass that, or use a named argument to just pass the mask
If you use something past an optional parameter, it becomes required
OHHHHHHH
why would you remove get component if you did not assign it anywhere else ? including inspector
Unless- yep spr2 beat me to it
never knew that
if you dont care about order, use named parameters
.Raycast(transform.position, Vector2.right, layerMask: grabLayer)
You said you drag in the source via the inspector
You need to do that if you are removing getcomponent
thank you guys!
if(Physics.Raycast(direction:mydirection etc.
you can put them in any order this way
appreciate it
how to get assenbly CSharp?
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
Does anyone know how to get rid of this
What is "this"?
Graphics on this texture is buggy
Graphics is a bit jagged when player move
its honestly barely visible
On a larger screen its more visible
Video compression will mangle it pretty badly.
Are you talking about the patterns towards the end of the walkway?
@polar ermine Enable mip map generation on the texture, with trilinear filtering if it still looks bad
yeah, trilinear filtering will blend between mipmaps
Weird code question
Trilinear filtring is on ill try with mip mapping
it is, indeed, a weird code question!
In unity, is one Canvas gameobj usually how UI/images are added, or should I have multiple canvas for each item, examples: Timer, Boss Health bar, player mana bar, etc
Whenever one element on a canvas needs to be redrawn, the entire canvas needs to be redrawn. You should try to find a balance between having too many things on one canvas such that redrawing becomes slow, and having too many canvases which makes for a lot of object overhead
If you can find decent ways to compartmentalize it, go for it. Just don't go nuts
no need to ping me personally, i was just showing you the correct room. also !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.
Oh alright, mb
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BallWallx20Mover : MonoBehaviour
{
public Transform Ball;
public float Orientation = 0;
public int Speed = 10;
float Mover = 0;
void Start()
{
Ball.transform.Rotate(0, Orientation, 0);
}
void Update()
{
Mover = Speed * Time.deltaTime;
Ball.transform.Translate(Mover, 0, 0);
}
void OnCollisionEnter()
{
for (int counter = 0; counter < 40; counter++)
{
Orientation = Orientation + 180;
Ball.transform.Rotate(0, Orientation, 0);
Debug.Log(counter);
}
}
}
Does the object with this script have a rigidbody?
Or the wall?
The object does
Put a debug.log just inside the OnCollisionEnter enter to make sure that is being called
Wait
Each time it collides you do that for ENTIRE loop
Also why the for loop? It's going to be executed in one go so you won't see anything happening
Frame gets rendered -> 40 loop iterations execute -> next frame gets rendered
How can I move something towards a position without verticality?
It's for a exam, they want it move between the walls exactly 20 times, so I thought 20 for each wall i.e. 40
That is not how you would do that at all
Remove the for loop
That's not how it works yeah
Increment a class variable
You need to keep track of the count in some variable
private counter = 40
OnCollisionEnter()
if (--counter > 0)
Your orientation thing
Else { end }
is there a different type i can use instead of float because for 0.10 I get Subtracting 0.09999999 from score when I use Debug.Log
int
int will work with 0.10 ? 🤔
You'll most likely want to keep the value as a float, but format it if you plan on displaying it to the user
eg. Debug.Log($"Subtracting {score:F2} from score") - "F2": format string for a float with 2 decimals. Adjust the number after the "F" to show more or less. The number is automatically rounded.
eg.2 someText.text = score.ToString("F2")
it's just that i have a conditional that compares previous balance/score with the new one and I get something like Score changed to 9936.7 from 9936.701 but in reality nothing changed
it's because when i subtract .10 its actually subtracting 0.0999999999 or w/e i think
Yes because of floating point precision errors. In that case you can subtract the two numbers and compare them to some other small value to see if they're roughly identical
if (Mathf.Abs(a - b) < 0.01)
isnt there also mathf.approx
oh that's pretty smart thanks i didn't know about that
Try to write a number in here and note it often cannot be represented https://float.exposed/0x461b42cd
Floating point format explorer – binary representations of common floating point formats.
So I've tested around, it works with a variable and also the code Aethenosity sent, but now it gets stuck on the other wall (-x) instead 
finally a site that lets you link to a specific number!
oh there is , thanks i'll try that too
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
because ' ' is for char
Wait a Ohh i see now
why it accept the second one
and not the first one
different symbols do different things
I thought its like python
this aint js
Because the second one is correct
or py lol
The first one isn't
Sad i like python
Make sure your IDE is configured before you go down any other python-esque rabbitholes
ok ok we starting i ll make snake game 
Ok 
should i learn C# and unity at the same time or should i start learning C# first
and if the latter, to what extent should i know C# before starting unity
You can do both
If you want to do C# specific learning, just start with the basics really.
you can do both, easier to probably do c# first alone with Console apps because its no extra APIs and compiles quick
i ended up making a little helper method like this based on some more google searching:
private float RoundedFloat(float value)
{
return Mathf.Round(value * 100f) / 100f;
}
I'm not sure what you're hoping to accomplish with this
that's probably just gonna introduce more imprecision
so far it works , but now i'm paranoid from your comment and gonna keep testing it until it doesnt lol
It's important to realize that something like 0.01 isn't becoming 0.00999999, it is 0.00999999. That's just how that particular value is represented in floating point. If a value can't be represented exactly in float, then you're not going to "trick" the code into being able to represent it
Hey guys half AI half general coding question here
How would I approach a system where if you alert one enemy, all enemy classes/types also become alert of the player
so the other one that isn't 9367.701 is wrong 🤔
As far as floating points are concerned, yes
invoke a static event
Have something that holds a reference to every enemy, and that every enemy has a reference to. Have that enemy tell that central object "I saw this guy" and have that object push out the notification to all the other enemies
A good way to accomplish this is with an event listener.
great thank you
will look into it
need to start digging into events, been avoiding them for no reason but procrastination
Once you learn how to do them you'll start putting them everywhere
how can i increase the gap which the header attribute makes in the editor
is it possible through like preferences in the editor?
if I'm trying to sync rotation with another object but with a offset is adding that rotation directly workable or should I grab the axis information the first object rotated on
if you want bigger gaps just put [Space(amount)]
[Header("Hello"), Space(30)]
i mean yeah but i was wondering if i can change the amount of space header makes
@old ibex
!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.
Not without doing what Nav said
if you find out let me know, don't think so unless you try to mess with original code for the attribute
void LateUpdate () {
transform.position = new Vector3(target.position.x, target.position.y, transform.position.z); //this is line 37
//keep the camera inside the bounds
transform.position = new Vector3(Mathf.Clamp(transform.position.x, bottomLeftLimit.x, topRightLimit.x), Mathf.Clamp(transform.position.y, bottomLeftLimit.y, topRightLimit.y), transform.position.z);
if(!musicStarted)
{
musicStarted = true;
AudioManager.instance.PlayBGM(musicToPlay);
}
}
alright thanks
I just sent a snippet I can also send the full script
which line is 37
although I doubt it will help
Since it's lateUpdate, it may just be happening after the scene is unloaded. You could do what the error suggest and just check if it is null first
transform.position = new Vector3(target.position.x, target.position.y, transform.position.z);
The first one, there is a comment
so inside lateupdate I would check if the transform is null, and if it is then do the same line of code again?
your code must be running while obj got destroyed for scene change
yeah and I tried DontDestroyOnLoad(gameObject); but it didnt work
top of the LateUpdate
if(target == null) return;
let me try that real quick
Hello everyone! Please, can someone tell me why there is a error in the array? Thank you.
just use cinemachine and u get a better camera and not worry 😛
jesus christ
ever heard of an array
oh you did since you're using it on the line that errors..
thats not how you init an array
Ok. How can I do it then?
just make your Modulos a SerializeField array and assign them in inspector
if you are using numbers for variables, you need an array.
ok so by adding the line of code you told me, the error went away, but now the issue is that I added a fadeScreen which fades when there is a scene change. That fadeScreen is fading into the scene, but it does not fade out, so I am stuck on a black screen
Ok, thank you very much 🙂
I can't guess , you have to provide proper context like the code and setup
[SerializeField] private GameObject[] ModuloList;``` (Actually you dont want to new it, just add them on the inspector)
Can just serialize the array and add more entries on the inspector
so basically I have an image in the canvas and its alpha value changes via a script I made:
if (shouldFadeToBlack)
{
fadeScreen.color = new Color(fadeScreen.color.r, fadeScreen.color.g, fadeScreen.color.b, Mathf.MoveTowards(fadeScreen.color.a, 1f, fadeSpeed * Time.deltaTime));
if(fadeScreen.color.a == 1f)
{
shouldFadeToBlack = false;
}
}
if (shouldFadeFromBlack)
{
fadeScreen.color = new Color(fadeScreen.color.r, fadeScreen.color.g, fadeScreen.color.b, Mathf.MoveTowards(fadeScreen.color.a, 0f, fadeSpeed * Time.deltaTime));
if (fadeScreen.color.a == 0f)
{
shouldFadeFromBlack = false;
}
}
}
public void FadeToBlack()
{
shouldFadeToBlack = true;
shouldFadeFromBlack = false;
}
public void FadeFromBlack()
{
shouldFadeToBlack = false;
shouldFadeFromBlack = true;
}
The script is called whenever there is a scene change
so now when the scene changes, it fades to black, but doesnt fade back from black
I have an area entrance and exit system
In which I manage the scene changes and which scene to change to etc
Area Exit:
void Update () {
if(shouldLoadAfterFade)
{
waitToLoad -= Time.deltaTime;
if(waitToLoad <= 0)
{
shouldLoadAfterFade = false;
SceneManager.LoadScene(areaToLoad);
}
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if(other.tag == "Player")
{
//SceneManager.LoadScene(areaToLoad);
shouldLoadAfterFade = true;
GameManager.instance.fadingBetweenAreas = true;
UIFade.instance.FadeToBlack();
PlayerController.instance.areaTransitionName = areaTransitionName;
}
}
Area Entrance:
void Start () {
if(transitionName == PlayerController.instance.areaTransitionName)
{
PlayerController.instance.transform.position = transform.position;
}
UIFade.instance.FadeFromBlack();
GameManager.instance.fadingBetweenAreas = false;
}
do you know for sure this script is actually running after it fades into black
yes
I have tested it out before and it works, nothing breaking
Now its giving me an issue for some reason
before what ?
Before I had the other issue of the Transform being destroyed
i'm trying to make it so my spikes in my game are placed in a grid-like way (easily). can I achieve this using a gridmap? whenever I try to set the pixels per unit, it doesn't work as the image's x and y scale isn't the same. how can i do this?
do you have any other errors in console?
I am getting a warning over and over, which says that There are 2 event systems in the scene
im not sure how to fix it, and its probably why everything else is not working
dont think this warning would affect the code you have
but still you should fix it, delete one of them
you mention DDOL somewhere earlier, its probably causing multiple issue if you have no disposed the other properly
Im not sure what an Event System even is, would you be able to tell me how to get rid of it?
Oh my bad sorry
I just realized it is one of my prefabs
Can anyone assist me
so heres my issue
im creating a 3d game but using some 2D Sprites as char and monsters ect..
im following a guide and so i had everything all good
but now when i move "WASD"
i get these errors
and i added so when i click to attack it would target specific monsters
Sorry to ask, but would you be able to get on a discord call so I could screen share my issue, I think you would be able to help me better if you could see exactly what I am saying. If you dont mind that is, you wouldnt have to talk.
I'm at work I cannot
Ok, thanks for helping
I would suggest first debugging make sure the code is running there
put Debug.log inside your FadeOut method
Ok I will try that out
Something on that line is null but you're trying to use it anyway
you have to show code for anyone to help
Find out what's null and make it not be that
config your editor first
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
do i download that
what you sent just now
im like a very beginner with this
You need to configure your IDE
So it shows errors and highlights syntax
Hey! Is this script okay for rotating towards an object on the y axis?
the lerp is wrong
how can I fix it?
also why are you making a quaternion like that
so its only on the y axis
what
if I rotate on other axises, this happens
The axes of a Quaternion are not the same as the axes in 3D space
I would go for the Coroutine option for lerp
That wouldn't be how you do that
Basically never make your own quaternion
sorry for screenshot, but how do i acces this exact line of code in a different script?
well I know, so I tried to make up for that by using the slerped rotation in the 4th dimension
you need to serialize it or make an instance of it
most probably make an instance
hey im having some issue here: Im trying to get the health var thats in the healthBar Script to match the bosses script health var, so im trying to get 2 files to access each other. This is how im trying to instantiate this and the Debug.Log prints out the Canvas name. This is how im trying to do the health reduction per hit on the oncollision (which has worked so far btw except without a UI),
if (other.gameObject.CompareTag("Bullet"))
{
health--;
healthScript.UpdateHealth(1);
healthScript.currentHealth = health;
but i keep getting the error object reference not set on the UpdateHealth(1); line.
I have a door here that i want to play sounds when it starts moving and stop playing when it stops however im getting that reference error in the console and im not sure what to do.
The 4th value isn't just some magic number you need to provide to make the compiler happy and XYZ are unchanged. A quaternion fundamentally does not have anything to do with 3D space
but isnt making it an instance going to make it a different script?
The components are called x, y, z, w purely out of convention
Reference this object, then do .currentGameStage on it
public class DragDoor : MonoBehaviour
{
AudioSource doorSound;
public AudioClip[] doorClips;
[SerializeField] Transform playerCamera;
[SerializeField] Transform distanceCheck;
[SerializeField] Transform hinge;
[SerializeField] float moveSpeed;
[SerializeField] Vector2 rotationContraints;
bool movingDoor;
float rotation;
Vector3 targetPosition;
// Start is called before the first frame update
void Start()
{
targetPosition = distanceCheck.position;
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(playerCamera.position, playerCamera.forward, out RaycastHit hit, 3f))
{
Debug.Log("pressed at door");
if (hit.collider.CompareTag("Door"))
{
movingDoor = true;
}
}
if (movingDoor = true)
{
doorSound.Play();
if (movingDoor = false)
{
doorSound.Pause();
}
}
}
if (movingDoor)
{
if (Input.GetMouseButtonUp(0))
{
movingDoor = false;
}
targetPosition = playerCamera.position + playerCamera.forward * 2f;
}
rotation += Mathf.Clamp(-GetRotation() * 5000 * Time.deltaTime, -moveSpeed, moveSpeed);
rotation = Mathf.Clamp(rotation, rotationContraints.x, rotationContraints.y);
hinge.localRotation = Quaternion.Euler(0, rotation, 0);
}
float GetRotation()
{
float firstDistance = (distanceCheck.position - targetPosition).sqrMagnitude;
hinge.Rotate(Vector3.up);
float secondDistance = (distanceCheck.position - targetPosition).sqrMagnitude;
hinge.Rotate(-Vector3.up);
return secondDistance - firstDistance;
}
}
then how should I create rotation towards an object
Which line is throwing the error
tutorials tell you to use this hacky solution
like I looked into 4
and all 4 told me the same thing
to use this
I realized that the lerp approaches a value but never reaches it
If you want the object to rotate along a plane, instead of getting the direction to a target point, get a direction to that point but on this object's y position
but I never found a specific issue with that
Then you can just Slerp between them
like this?
how 😦
Reference the instance of whatever script this variable is on
and what if I make it so it rotates to an object but I put a constraint on it so it can only ever rotate on the y axis?
This is how you put constraints on it
I meant like a constraint monobehaviour
I don't know what you mean by this
theres a
i completely forgot about get component, thx lad, helped me out
sry ive been working at this for like 30 min and 3 minutes after I asked I figured it out lol
the global healthScript was not the one being set to during start
im on #3 i dont see add button
That is not a 4th dimension. It affects the values of the previous three values
It is the colinear rotation magnitude of the xyz vector
looking in the wrong place
oh right my bad
I knew that im just stupid
its for bypassing the gimbal lock
right?
No
I thought thats why quaternions are used
I am trying to run a script on a mesh, but am getting the error that the mesh isReadable is false. It says to enable Read/Write on the import settings. I can do this, but then I have to redo a bunch of other stuff. Is there a way to enable Read/Write other than at import?
to fix gimbal lock issues
It is a benefit of them, yes
But 1, that is not what the W component is for
ig its not for bypassing the gimbal lock it just helps with it while doing other stuff
while messing around with constructing that quaternion I did stumble upon some atrocities
It's just a mathematical concept. You should not use it directly at all
and it usually was because of the w axis
Again, w is not an axis. But I get what you mean
so ill get back to this, how can I do this?
it says its Under Add Modules
but you already have VS you have to check if you have the workload
w parameter, sorry
No worries. You got it, just wanted to make it clear
im just used to calling everything axis at this point
like its stupid how Vector3s already use xyz
even if you dont use it only for coordinates
tho tbf you do the same in maths soo
but when I think of a Vector I think of an Array kinda
i know its not the same but it heavily reminds me of it
I suppose I can try using MoveTowards
I just don't quite get how it works yet
Must be having a C++ mindset...
yeahhh
in school we do c++
and it can mess me up so bad
also, if I set maxDistanceDelta to 0, does that mean that the object would rotate to target without moving?
i am completely new to unity, is transform written as a class? i see it like transform.rotate and im wondering if it has the same capabilities as a normal class
Transform is a field
its the situational values of something
i cant say position actually
more like coordinates and such
oh alr
where it is, how its rotated, what scale it has
wait
are we talking about Transform or transform
Transform is a class, yes
https://docs.unity3d.com/ScriptReference/Transform.html
^ updated code, still doesnt work
{
AudioSource doorSound;
public AudioClip[] doorClips;
[SerializeField] Transform playerCamera;
[SerializeField] Transform distanceCheck;
[SerializeField] Transform hinge;
[SerializeField] float moveSpeed;
[SerializeField] Vector2 rotationContraints;
bool movingDoor;
float rotation;
Vector3 targetPosition;
void Start()
{
targetPosition = distanceCheck.position;
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
if (Physics.Raycast(playerCamera.position, playerCamera.forward, out RaycastHit hit, 3f))
{
Debug.Log("pressed at door");
if (hit.collider.CompareTag("Door"))
{
movingDoor = true;
PlaySound();
}
}
}
if (movingDoor)
{
if (Input.GetMouseButtonUp(0))
{
movingDoor = false;
}
targetPosition = playerCamera.position + playerCamera.forward * 2f;
}
rotation += Mathf.Clamp(-GetRotation() * 5000 * Time.deltaTime, -moveSpeed, moveSpeed);
rotation = Mathf.Clamp(rotation, rotationContraints.x, rotationContraints.y);
hinge.localRotation = Quaternion.Euler(0, rotation, 0);
}
float GetRotation()
{
float firstDistance = (distanceCheck.position - targetPosition).sqrMagnitude;
hinge.Rotate(Vector3.up);
float secondDistance = (distanceCheck.position - targetPosition).sqrMagnitude;
hinge.Rotate(-Vector3.up);
return secondDistance - firstDistance;
}
void PlaySound()
{
if (movingDoor = true)
{
doorSound.Play();
if (movingDoor = false)
{
doorSound.Pause();
}
}
}
}
did you install the workload?
also @teal viper what if I use LookAt?
No. This has nothing to do with movement or rotation at all. It just "moves" the value. Moves as in adds to or subtracts from.
then do the other part of the guide..
setup unity external tools, click regen project files there if you have set it already
What about it?
it seems to work
ohhh
okay
I misunderstood it
large code should be sent via code sharing links
its Vector3 not transform
yes, but I can instance a Mathf
then I can instance a second Mathf
Yes sir of course sir.
and then I can check if the first Mathf .Equals the second
and then put them in a big List<Mathf>
Of course it does. It would be an outrage if such a core function wasn't working.😬
It's for backwards compatibility when they finally find the end of PI.
i meant that its doing what I wanted
but not quite
And then define extension methods as
public static Mathf CombineMath(this Mathf first, Mathf second)
ill try using movetowards
Well, that I don't know. Share the new code.
then at some point, I can make a List<Tuple<Mathf, float>>, so i can effectively store a list of floats, with the relevant Mathf instance I should use for it
i can make the most cursed code ever
public class RotateToPlayer : MonoBehaviour
{
public Transform target;
public float RotationSpeed;
private Vector3 _direction;
void Update()
{
_direction = (target.position - transform.position).normalized;
transform.rotation = Vector3.MoveTowards(transform.rotation, _direction, RotationSpeed);
}
}```
I wanted something like this
but idk how to turn transform.rotation into a vector3
Why vector in the first place? Rotation is a Quarternion.
you said I should use MoveTowards
MoveTowards is a vector3
Euler angles is what ur wanting i think
MoveTowards is not a vector3
i thought of it but it doesnt work
i meant this
It's a method in Vector3. But there is a similar method in quaternion too
Check the docs.
Not that
then?
Read through the available methods
FromToRotation?
Yes
how do i detect inputs on unity code
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
Input class probably?
you gotta use an inputsystem
idk
vector3 is not a quaternion
public class RotateToPlayer : MonoBehaviour
{
public Transform target;
public float RotationSpeed;
private Vector3 _direction;
void Update()
{
_direction = (target.position - transform.position).normalized;
transform.rotation = Quaternion.RotateTowards(transform.rotation, _direction, RotationSpeed);
}
}```
Hi, so currently im following brackey's first Person Movement tutorial and i hit a problem when trying to implement camera rotation on the x axis it simply blocks rotation on y axis ( the problem may be due to me using the Input System and the tutorial using the legacy input system but i am not sure )
here is the code im using:
public void look(InputAction.CallbackContext context)
{
if (CanMoveCamera)
{
xRot -= context.ReadValue<Vector2>().y * mouseSensitivity * Time.deltaTime;
xRot = Mathf.Clamp(xRot, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRot, 0f, 0f);
transform.Rotate(Vector3.up * context.ReadValue<Vector2>().x * mouseSensitivity * Time.deltaTime);
}
}
note: context.ReadValue<Vector2>() returns current pointer delta movement.
the problem is _direction
I need to turn it into a rotation/quaternion
Quaternion.Euler maybe?
is mouse1 lmb?
Mouse1 is rmb
i dont see it anywhere
What is that?
Guys did everything here but still ide doesn't work
is it bc of the 0, 1, 2 index notation on c#?
apparently unity has a free built in course
In programming yes
alr
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
"did everything" doubt..
Yeah, it's right here
Lua >.>
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
show that you configured it in Exernal Tools in unity
ok not exactly Lua but some extension of it counts from 1 instead of 0
Yeah, I have made myself stop saying that is only a scripting language, but it IS still an obfuscation of what the computer is doing
Sure
using UnityEngine;
public class RotateToPlayer : MonoBehaviour
{
public Transform target;
public float RotationSpeed;
private Vector3 _direction;
void Update()
{
_direction = (target.position - transform.position).normalized;
transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(_direction), RotationSpeed);
}
}```
Shouldn't say internal
also I dont have time for this rn sorry
How
: )
You find the program and set it to it
As it says in the guide
Look at the quaternion docs again. There's a method to create a quaternion from a direction.
isnt it Quaternion.Euler?
if its showing Internal A. you did not remove the VSCode editor package and B. did not update Visual Studio Editor package
No. That's from an angle not a direction@quick pollen
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
FromToRotation?
No
Well idk which package u talking about so ill try again
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
LookRotation maybe?
stopspamming the fucking commad and scroll up..
its a quaternion, and it uses a direction.
will it work for ur use-case?
Yes
except FromToRotation says this Usually you use this to rotate a transform so that one of its axes eg. the y-axis - follows a target direction toDirection in world space.
is Visual Studio Editor what i needed? for !ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
• Visual Studio (Installed via Unity Hub)
• Visual Studio (Installed manually)
• VS Code
• JetBrains Rider
• Other/None
Stop saying the command
And yes
What's the problem with it?
jesus christ people today
Remove the Visual Studio Code Editor package
STOP BEING MAD EMO 
Don't
why dont you learn how to keep a web page open instead of being a forgetful ant
there is no need to spam the command when you can just scroll up and keep link open..
I thought its meant to be the one
you just said thats what i needed for i.d.e so i delete it tho?
No, you need the Visual Studio package. Remove the Visual Studio CODE package though
Ah, Yeah I miswrote it earlier. Sorry
now I need to find a way to lock the rotation to the y axis
so im set with i.d.e?
after i delete that code one
How should I know? That is one step
There are others
lol
maybe I can create a new direction which is just _direction without the x and z?
how do you know if ur not even following it properly lmao
It's like a couple steps. It's dead simple
What have you done so far?
bruh you struggle with this, making a game aint gonna be easier
Yep. I think you were given that solution by someone some 30 min ago.
yeah it was digiholic
rome wasnt built in a day
😞
somethings still messed up
its rotated wrong
like its facing the ground
not me
So do not try to offer educational courses or help others if you are quick to anger and disrespectful to beginners
Share code
Why are you doing this? Stop
I expect some level of comprehension
public class RotateToPlayer : MonoBehaviour
{
public Transform target;
public float RotationSpeed;
private Vector3 _direction;
private Quaternion _rotation;
void Update()
{
_direction = (target.position - transform.position).normalized;
_rotation = Quaternion.LookRotation(new Vector3(0f, _direction.y, 0f));
transform.rotation = Quaternion.RotateTowards(transform.rotation, _rotation, RotationSpeed);
}
}```
actually
do I need to do the exact opposite
have x and z but not y
"stopspamming the fucking commad and scroll up.." your friend said that bec i wrote a code
A bunch of times. Yeah.
But still, stop
It's over
you keep spamming bot command instead of keeping a link open?
anyway i have no time to bicker with you
goodluck to ya
reading a step by step guide with screenshots isnt exactly coding or some sort of special science
it works!
yeah I was stupid
I meant to freeze the Y rotation
get ur axis' straight! 😛
not unlock the Y rotation
Don't expect me to be respectful to anyone who disrespects me
I am here to learn
If you are a very angry person
He curses in his words
So don't talk to others and go develop your own game
Just learning, you're all good!
fr lol I always fuck up these things
it gets ezier
You are spamming, and disrespecting the whole community. Stop
@summer stump i followed all the steps how do i know if i got .i.d.e to go correctly
Talk with your friend sir
but I mess it up so often when I have to rotate around them
Which steps have you done?
If you misspell something it should give you a red underline
Maybe show a screenshot of the ide
<@&502884371011731486>
Whatever that thing in Look rotation, it doesn't look correct
tysm @teal viper @rocky canyon @summer stump and whoever else who helped :)
<@&502884371011731486>
yes I meant to freeze the y rotation and unfreeze the others but instead I unfreezed the y rotation and freezed everything else
using UnityEngine;
public class RotateToPlayer : MonoBehaviour
{
public Transform target;
public float RotationSpeed;
private Vector3 _direction;
private Quaternion _rotation;
void Update()
{
_direction = (target.position - transform.position).normalized;
_rotation = Quaternion.LookRotation(new Vector3(_direction.x, 0f, _direction.z));
transform.rotation = Quaternion.RotateTowards(transform.rotation, _rotation, RotationSpeed);
}
}
final thing
and thank u @teal viper especially for giving me hints and not an exact solution
did take more time but at least I'll (hopefully) make shitty mistakes like this less often
its like 3 am
its especially hard to think right rn
@quartz grove Stop yabbering. If someone tells you to stop spamming the command, respond nicely instead of arguing. It's not hard to scroll up or reopen a webpage, and that's all that's being asked of you.
Why do I respond politely to someone who asked me something in an impolite way?
I see that there is bias in the administration
@rich adder don't swear at people when you want them to stop. You can keep things polite too.
You're right . My Apologies
because are trying to instigate things, it looks like the kid "yelling i am not touching you" with there hands up in someone's face
Good my apologies as well
because we should at least try to pretend to be mature adults lol
No, it's unfortunately not configured
O'Brother
Believe me, I was very hurt because I tried to ignore bad manners
(i say that but im immature anyway lol)
Try clicking "regenerate project files" in external tools
not saying you should ignore them forever
but especially when ur receiving help
and people are spending their time on u
anyways good luck
Believe me, I don't need help from anyone who doesn't know how to talk
The topic is over now, let's not reopen it
you have the "right" to be impolite in return, but its better to walk away
sure, just keep an eye out for things like these
hey y'all
hi
currently working on a couple projects for various beginner level understanding, and I'm wondering if there's any websites for learning unity.
I've already found docs.unity.com and learn.unity.com, but I'm curious about other websites, just to know the different options
There are pins in this channel
sweet, thanks
Code: https://pastebin.com/EeP4H6Xy, I have a question on positioning. Basically ive almost solved my issue and im almost done. I have a turret which operates on a spaceship, and only moves left and right (well rotates left and right), and it took me a while but i got it running. Which is fine when the ship is moving forward and backwards, or left and right, but for up and down, the ship stays at its rotation and doesnt rotate up, so it glitches into the cockpit and looks a little odd. Any workaround for this?
once this is done i can call it a day and finally rest easy.
You should be using localRotation/localEulerAngles and convert any world space positions to local positions
That will easily let you enforce limitations on the object's rotation relative to the parent (the ship)
It will take some fiddling
so would i have to also change the Move towards angle also
I mean yeah just do everything in local space
Also recommend maintaining your own variable for the rotation rather than reading the euler angles from the transform
If anyone can help i cant get i.d.e because im not sure if i need to buy VS or what but some options are missing. anyways in my game i use WASD to move and when i move i get these errors
thats the code on the right it pulls me to when i double click the errors
did you regen project files like Aethenosity said
wheres that option at i couldnt find it
Edit -> Preferences -> External Tools
You do not need to buy anything
Your error is because the attackRoutine isn't set to anything when you call StopCoroutine
IDE setup is not working for me
What have you done so far?
Also, ALL these IDE questions should be in #💻┃unity-talk
mb
@summer stump @rich adder sorry for asking so much this is very new to me so again sorry lol
No worries, it's fine!
double check https://unity.huh.how/ide-configuration/visual-studio-code these steps
seems you dont have the SDK but only runtimes
*thread prob
did you do the step ?
Yeah, I'm never sure honestly. It's good in this channel? I guess it IS usually where it is asked
not sure tbh lol but I think so since it kinda code topics
In Unity, did you not follow the steps in the guide its part of it.
well there is your answer
Visual Studio isnt even selected!
It would have been the step in the guide where you set the tool used by unity
^ make sure you regen after that
swear i had it switched lol but ig not but
regen
ok
do i select any other boxes on that?
or good to go
should be fine
make sure u close vs though when u regen
yes You are not referencing this script anywhere
peek-a-boo
^^ these are runtime errors and do not show up in IDE @heady wyvern
btw Update is a Unity callback so it gets autocalled so no References there
yeah the ide will tell you about compile errors
NRE is runtime error, not knowen till that code that casues it executes
assuming player is null, and not assinged in the inspector
but the error in the console will have a stack trace to show you where
so as in a "Refrencing" the script thats like adding a component - script onto a object?
like my "Target"
or referencing it in the script itself
if you say public GameManager myGameManager; and put that script onto an object
u have to fill in the newly made slot for a GameManager
if u go to run that script and its not referenced.. theres ur error
No, that would not be a reference
You have to "point" to that component. Not just add it
And the thing you do in the script itself is declare a variable, then you reference it, either with the = sign, or like spawn camp is showing
Think of referencing like bookmarking a page in a book
You know which book and which page you want to find specific info
think of it like a pointer..
public GameManager gameManager
^ this is a declaration, NOT a reference until you actually fill the variable with something.
It is "null" by default
to which specific Instance of that class ur trying to reference
also valid 😛 i tried a simpler more relatable analogy
he may have figured it out by now 😅
https://unity.huh.how/references
This shows multiple methods to reference things. Serialized References is what SpawnCamp was showing
oh bam, there u go ^
two of the same 😄
Sorry for the overload haha.
Let us know if that was too much
he's already building the menu by now
Probably already looking for publishers
game already has 20k steam wishlisting
i got whats the coders version of writers block? or it could be just procrastination
not sure where to go on my project
lmfao
i usually try to learn something new and give the mind a break from the same thing
eg if you're constantly working on gameplay features, work on the menus? music? the artwork ? or maybe some unrelated (kinda)
its just procrastination
yeah there is always something to do, but games covers alot of domains so its easy to change things up
or easy to working on something a little more mindless if your head is not in it
yup, ur private Player.. is visible in the inspector b/c of the [SerializedField] attribute u used..
You have successfully referenced an instance of the player script
so in that case you pull in the gameobject that has the Player script on it
step 1/2
step 2# make sure its assigned
and when u run any code referencing that player.. it'll know which gameobject has that player script
👍
i have lots more faith in you than some i see around here 🙂
It's a wiiiide screen. It's assigned on the right
ahh wops looked on it from phone lol
yea, it looks good.. no console errors.. it has a reference.. the player script has a MyTarget variable..
yeah its assigned, though in the code i would null check the collider on the hit, to make sure you got a hit
btw you I think you could get a null ref if hit.collider is null since you're accessing a tag on collider
if that variable is public (can be accessed in ur GameManager script) ur solid
like Debug.Log?
Debug.Log just prints the result
if x == null
i deleted the .tag on the end of that one and that error went away when i clicked the "Target" now
ok
because thats the proper way to check the collider is null first
no not like this lol
.tag is trying to access collider and if no collider is found, it will throw NRE anyway. You cannot run .tag on a null object
You wanna check hit.collider
Not hit.collider.tag
..and wrap ur raycast in an if statement and then u wont have to worry about null tags when theres no hit variable
ohh
don't think 2D has it
i meant like this.. but ur right.. i know nothing about 2d raycasts
thats odd that u cant
https://docs.unity3d.com/ScriptReference/Physics2D.Raycast.html
Yeah I dont see it here
weird.. why not i wonder.. im sure its been ticketed/requested
or maybe im tripping
im creating 3D
then why are you using a physics2D function
i put 3d and it doesnt work lol
i tried both 3d and 2d
You only write 2d for things. You just don't write either for 3d
stuck t one thing...
So Physics or Physics2D
and dont randomly change stuff without knowing why
Collider or Collider2D
i mean colliders
anyone good at c# sharp?
i tried both regular collider and 2d
im making a game with some people we need coders lol
👓 #
!collab
We do not accept job or collab posts on discord.
Please use the forums:
• Commercial Job Seeking
• Commercial Job Offering
• Non Commercial Collaboration
boohoo
No 3d at the end
show current code
There is nothing that ends in 3d afaik
first result
Unity is a 3D engine, usually everything 2D has suffix
Light2D or w/e
etc
Random note, RaycastHit2D has an implicit cast to bool that checks the collider
hi, how do you rotate a gameobject to face towards a cube's corner?
(the screenshot shows an invisible capsule outlined in green, which i am trying to rotate to face the corner)
i have script attempting this, but i just want to know how to do it in general:
using System.Collections.Generic;
using UnityEngine;
public class raycastMove : MonoBehaviour
{
public GameObject bigCube;
public GameObject playerCapsule;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//draw ray in playercapsule's forward direction
Debug.DrawRay(playerCapsule.transform.position, transform.forward, Color.white);
//draw ray that collides with the cube's corner
Debug.DrawRay(bigCube.transform.position - (transform.forward - transform.right).normalized,
(transform.forward - transform.right).normalized,
Color.blue);
RaycastHit outCornerAngleHit;
if (Physics.Raycast(bigCube.transform.position - (transform.forward - transform.right).normalized,
(transform.forward - transform.right).normalized,
out outCornerAngleHit,
30f))
{
//Move playercapsule to cube's corner
playerCapsule.transform.position = outCornerAngleHit.point;
//Rotate playercapsule towards where cube's corner was hit
playerCapsule.transform.rotation = Quaternion.RotateTowards(playerCapsule.transform.rotation, Quaternion.LookRotation(-outCornerAngleHit.normal), 3600);
}
}
}```
plz shup up :I
oh wellOP is using 3D colliders anyway
don't be toxic
idrc
rebel
i was just asking a question he didnt have to link that
your question wasn't clear on why you are asking who can code..
its perfect fit , did you even read it?
It is a common thing to link here. It has helpful information
You are welcome
this server is annoying af
bigCube.transform.position - (transform.forward - transform.right).normalized this reads like a nonsense position to use, what kind of logic is this trying to achieve?
Just ignore him
blocked already
Seriously, I just cautioned you for this kind of thing earlier today, please stop the hostility.
Sorry ok
Oh, to get a 45 degree angle to make a raycast ultimately shoot towards the cube's corner. with this script I was trying to get the Capsule to face where that raycast hits
but I just want to get the capsule to rotate to face* the corner in any way possible lol