#💻┃code-beginner
1 messages · Page 473 of 1
ya but its doing what i want like when it colliders with a 2d collider the hit is true and circle collider of the banana is disabled
i was gonna add gameObject.SetActive(false); but like its doing the flicker thing i think cuz of the monkey problem
i will use an if statment to remove the monkey
ITS WORKING LETS GO
thank mr dig
hello guys
I want to make an active ragdoll character, I want it to be like human fall flat
should I make it move the hips and legs follow the hip, taking steps if hip is too far from the leg
or should I blend animated and physical characters
or something else
I do active ragdolls by having an invisible, animated character, and then the actual character that uses configurable joints to try and replicate the animated character
Not a beginner subject though... Unless you find some really handy asset for it
active ragdolls are tricky, you would get a lot out of this video
https://www.youtube.com/watch?v=HF-cp6yW3Iw
This is all I learned while making active ragdolls in Unity. I hope you find it useful or, at least, interesting :D
The actual tutorial: https://bit.ly/3lKsfk2
Github repository: https://bit.ly/2VxnU98
----- Social -----
Twitter: https://twitter.com/sergioabreu_g
Ambient Generative Music by Alex Bainter [generative.fm]
-...
So I have method to crouch and when you crouch it makes player local scale half, howcan I avoid to scale items player holds when he crouches, items are added to a hand transform which is a child of player
Avoid scaling the parent. Maybe only scale a separate child that has the character's visuals, if necessary
i guess i could just move the camera down as i dont need him to like go trough spaces
its mostly for ease of access to items on ground
instead of scaling the parent you can adjust the size of the collider and adjust playermodel via animations or scaling (if its a primitive shape)
so it wont scale your items
how can i check if an object is colliding with the ground
so far i have this
if (Input.GetMouseButtonDown(0))
{
if (displacement.magnitude < maxDistance)
{
power = displacement.magnitude / maxPower;
rb.velocity = -Camera.main.ScreenToWorldPoint(Input.mousePosition) * power;
}
else
{
rb.velocity = -Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
}```
but it doesnt seem to be working
the radius of the object is 0.16
guys i hv one final little issue with the banana throw when my monkey faces right the banana moves right however when i turn the monkey left the banana only flips but does not change direction
public void SetDirection(float _direction)
{
broke = 0;
direction = _direction;
hit = false;
circleCollider.enabled = true;
gameObject.SetActive(true);
float localScaleX = transform.localScale.x;
if (Mathf.Sign(localScaleX) != direction)
transform.localScale = new Vector3(-localScaleX, transform.localScale.y, transform.localScale.z);
}
you would have to show the banana throwing code
alr gimme a moment
you do not want a while loop here, it will freeze your game/editor
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BananaThrow : MonoBehaviour
{
[SerializeField] private float speed;
private bool hit;
[SerializeField] private CircleCollider2D circleCollider;
private float direction;
private float broke;
private void Awake()
{
circleCollider = GetComponent<CircleCollider2D>();
}
private void Update()
{
if (hit) return;
float movementSpeed = speed * Time.deltaTime;
transform.Translate(movementSpeed, 0, 0);
broke += Time.deltaTime;
if (broke > 100) gameObject.SetActive(false);
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
Debug.Log("Banana hit the monkey, continuing movement.");
return;
}
hit = true;
circleCollider.enabled = false;
gameObject.SetActive(false);
Debug.Log($"Banana hit: {collision.gameObject.name}");
}
public void SetDirection(float _direction)
{
broke = 0;
direction = _direction;
hit = false;
circleCollider.enabled = true;
gameObject.SetActive(true);
float localScaleX = transform.localScale.x;
if (Mathf.Sign(localScaleX) != direction)
transform.localScale = new Vector3(-localScaleX, transform.localScale.y, transform.localScale.z);
}
private void Deactivate()
{
gameObject.SetActive(false);
}
}
it's unclear which object this script is on, or where the banana throwing is happening
is this script on the banana prefab or something?
I don't understand
seems like its just 1 gameobject in the scene
its just an object with 10 clones of it hidden in the hieracrhy no prefab
object pooling
ive made it if but for some reason the raycast just doesnt return true when the object is on the ground even tho its just down with a value of 1
Well first off are you in 2D or 3D?
Because you're using a 3D raycast here
2d
you should probably convert that to a prefab and instantiate it
just to be cleaner
changing the scale of the banana wont change its direction, you would have to modify the transform.translate
keep in mind transform.translate ignores collisions as well
Well Translate works in local space by default
so I think inverting the scale should actually do it
my raycast is still returning true even tho my gameobject is up in the air
try altering movementSpeed in the translate
just a test
{
Vector2 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
displacement = Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position;
if (Physics2D.Raycast(transform.position, Vector2.down, 0.1f)) {
Debug.Log("true");
if (Input.GetMouseButtonDown(0))
{
if (displacement.magnitude < maxDistance)
{
power = displacement.magnitude / maxPower;
rb.velocity = -Camera.main.ScreenToWorldPoint(Input.mousePosition) * power;
}
else
{
rb.velocity = -Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
}
} else
{
Debug.Log("false");
}
}```
do you have a layermask for the ground?
right now the raycast is just hitting whatever
i looked it up and changed a setting and now it returns true for first 3 frames then returns false
no i dont
add a layermask in the raycast script
how?
so if i set the ground to the ground layer
then add a layermask for that in the raycast
it will only hit ground
ok ill try
if (Physics2D.Raycast(transform.position, Vector2.down, LayerMask.GetMask("Ground")))
ive done this
try it
You put layerMask where it expects distance
i did you are correct
i would make distance a float
problem solved?
yes thank you
neato burrito
if you would want to !learn more about unity and its quirks you can click the link below to start
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Okay, so I'm making a 8-directional character controller
problem is that the diagonal movement is off
here's the simple code im using currently
as a visual example, the character starts up here
describe 'off'. Also why fixedDeltaTime in Update?
and then he winds up here when moving diagonally, which is not lined up with the tiles at all
off course not, do you know Pythagoras?
as for the fixedDeltaTime - I've got no clue. I followed a tutorial
Yes, I've watched those videos on how to fix the diagonal in theory but I have no idea how to apply it practically
do normalized work in this one?
Vector2.normalized
give me a second, I'll try
Vector2.normalize is a property, and Vector2.Normalize() a method
okay
Can't you just half your y movement?
public class GameUIHandler : MonoBehaviour
{
[SerializeField] private Sprite[] _healthBarSprites;
private Sprite _currentHealthBarSprite;
[SerializeField] private CharacterManager _characterManager;
private int _playerHealth;
[SerializeField] private float _scaleChange;
[SerializeField] private int _sizeChangeDelay;
public Slider _staminaBar;
[SerializeField] private CharacterMovement _characterMovement;
#region HealthBar Sprite
public void ChangeHealthBarSprite()
{
_playerHealth = _characterManager._playerHealth;
Debug.Log(_playerHealth);
for (int i = 0; i < _healthBarSprites.Length; i++)
{
if (i == _playerHealth)
{
_currentHealthBarSprite = _healthBarSprites[i];
gameObject.GetComponent<Image>().sprite = _currentHealthBarSprite;
}
}
if (_playerHealth == 0)
{
SceneManager.LoadScene("DeathScene");
}
}
#endregion
#region Stamina Bar
private void Start()
{
_characterMovement._currentStamina = _characterMovement._maxStamina;
_staminaBar.maxValue = _characterMovement._maxStamina;
_staminaBar.value = _characterMovement._maxStamina;
}
public void UseStamina()
{
if(_characterMovement._currentStamina - _characterMovement._staminaUse >= 0)
{
_characterMovement._currentStamina -= _characterMovement._staminaUse;
_staminaBar.value = _characterMovement._currentStamina;
}
else
{
Debug.Log("Not Enough Stamina");
}
}```
Can someone help me i have this error:
Your tile width seems twice higher than the height
Line 50 is _characterMovement._currentStamina = _characterMovement._maxStamina;
You just have to normalize the your direction Vector, since moving diagonally gives the distance of sqrt(2)
Had you used a paste site, like you are supposed to, we would know what line 50 was
obviously then _characterMovement is null
i said what line 50 was
The only reference type on that line is _characterMovement, so that has to be null
Aight, I'll try it out
i have it set in the inspector tho
Just get Vector2.normalized
Perhaps you have another object with this script then
Type t:charactermovement in the scene hierarchy search bar to search by type
I've put a normalized on the rb.velocity line but I suppose that's not how one does that
is there a way to raycast in all directions but one
there is always a way
velocity is speed, not direction
Well, "All directions minus one" is still infinity directions
put the directions you want in an array and loop through them
And ruin your performance, assuming you want to iteract through infinity directions minus one
What are you trying to do
the PlayerInput line then? get both axis inputs and then normalize them?
You have to, first of all, configure your !ide. And then get Vector2.normalized of PlayerInput
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
• :question: Other/None
I don't think their issue is the normalization/clamping, although that should be fixed too (so you don't walk faster diagonally)
looks configured , just old VS theme
White methods?
there was an old VS 2019 theme like that
but the missing "References" headers looks sus
The tiles are twice wider than their height. So I think you should just * 0.5f your vertical velocity @flat fossil
They have said their issue is walking faster diagonally
Oh shit
so ive made ball
but with rigidbodies it doesnt bounce off walls
so that is my next venture
Not sure where they said that
i thought of doing raycasts left right and down and if velocity is not equal to zero it bounces up with 87% of the original velocity
I think they are moving along the red line now, while it should be the blue line
Yes!
Ambiguous
So, you should not move diagonally at all?
The blue line in the image I posted does go diagonally, but not 45 degrees
Regardless, this fixed the problem!! Thank you so much Osmal
so far ive tried this if (Physics2D.Raycast(transform.position, Vector2.right, 0.2f, LayerMask.GetMask("Ground")) || rb.velocity.magnitude != 0) { rb.velocity *= 0.87f; }
but it just doesnt act how i want it to
i also tried seperately to change the velocity by multiplying the x by -0.87 but that also didnt work
Check what it's colliding with. Probably the player itself since you're not using a layermask
I have a problem, I created an inventory system and an add item button for a test that adds an item to the inventory, I tried to code it that way that if another item from the same type enters the inventory the items should stuck, but instead I can only add 1 item and when I press the button again nothing happens, any help?
help how? we don't even see the !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.
item slot script: https://gdl.space/deguyazise.cpp
inventory manager script: https://gdl.space/itanihuhus.cpp
item script: https://gdl.space/ihurebugux.cs
my bad, I was in the process of sending it while u send the message
any help? Im pretty much lost
start adding some logs and debug it
tbh I dont know how to debug
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
that should've been one of the first things to learn before doing an Inventory
how else would you double check your values without debugging, its essential to doing anything
hmm I guess thats right
isnt that one of the if not the first things you learn while coding in unity?
and its the most important
If you want to take debugging to the next level
https://unity.com/how-to/debugging-with-microsoft-visual-studio-2022
https://unity.com/how-to/debugging-with-microsoft-visual-studio-code
should be pinned tbh
@lapis frigate A few days ago you asked why getComponent didn't work. I am not sure whether I've sent you [this link](#💻┃code-beginner message) that time, but you really should have a look at it
just for organization should you apply components urself in the editor or in script directly with getcomponent?
you could do either
I like my scripts to be clear on what references they have assigned etc. I prefer Serialize inspector when possible
depends on how you arrange it
I was getting this message for no reason after i deleted a canvas every time I Jumped, i fixed it by changing canvas to a game object, but i still would like to know why that happened
pretty clear, that component depends on another and can't be removed
yeah but i got the message every time I Jumped after it was removed
well it was trying to remove it but didn't
so stuck in a loop ig , try remove, can't , jump try to remove can't etc
I mean after i deleted the canvas every time i Jumped it told me that I cant remove the canvas but Jumping and removing are not connected in any way and the script that deletes the canvas was also part of the canvas, so a removed script told me that cant remove a already removed Canvas every time i did something completely un related
If they weren't connected in any way, then you wouldn't be getting that error whenever you jump
So, more likely, you never intended to connect them, but did
You still have referenced Canvas anyway, deleted or not
so its probably an internal message
can u theoretically make a game with only 1 script?
like have EVERYTHING in just one massive script
yes
yes ofc
you can't use Two monobehaviour in one script though
Making a game in a single line of code be like.
Hire me: https://www.fiverr.com/n8dev_yt/edit-your-youtube-video
/// SOCIALS
▸ Twitch: https://twitch.tv/n8dev
▸ Patreon: https://www.patreon.com/n8dev
▸ Discord: https://discord.gg/f8B6WW7YrD
▸ Twitter: https://twitter.com/n8dev_yt
/// GEAR ///
▸ Microphone: https://amzn.to/42mqD6K
▸ Laptop: htt...
brain rot
LMAO
the video has 2.5m views so if you upload a video of you doing a game in just one script you will get (2500000 / x lines of code) views
yeah, but you can put the same script on multiple objects and have the logic filtered by Tag and/or Layer
might be fun for shits n gigs, but what a nightmare lol
the windows build doesn't throw this exception, only webgl
are you trying to run the webgl from windows?
did you do Build n Run
absolutely, you'd have to be an idiot to try it because it has no pros only cons
Yeah is that bad? Also the issue persisted on itch.io
lol yea clickbait videos
oh just checking , cause it needs a server but yeah if happens in itch there is issue. Did you check console ?
In my case it was because of Visual Effect Assets. Just when I switched to the WebGL target build, Unity threw some warnings at me that I ignored at first. When I switched to using particle system instead, everything was working.
check your unity if anything like that came up when you switched to webgl
try another browser or incognito mode
Chrome cache will sometimes cause a mismatch when loading the wasm of a project build. Clearing your cache often fixes the issue, and is why it worked in Incogneto mode.
tbf though, most of the old arcade games are easy to make as a one script game, that is, after all, how we made them originally
true true. Reminds me when i first learned unity i pretty much wrote monoliths lol
C# Console apps also teach you to cram everything in Program.cs at first
absolutely, any Unity game should be able to run as a Console App, bar the rendering, of course
Yeah console apps reminds how nice it is to have a GUI or engine to make stuff go pow pow 🤩
rebuilding the game to see if any error comes in the unity console window
running in incognito did not help
not sure maybe try #🌐┃web
doesnt seem code related
did you try
The first thing to do when getting a cryptic error that has those “wasm-function[xxyy]” lines on it is to change in the Project Build Settings “Debug Symbols: Embedded”, and then repro the error again.
That will give a human-readable call stack that can then help point towards the source of the exception.
hmm will try that now, is that in player settings
Hey guys i need some help
I have this monkey throwing bananas and well when the monkey if facing right the banana is thrown normally however i want the monkey to throw the banana left when it faces the left side however the banana itself just flips over and continues moving in the right direction any help to fix this?
start debugging which values you are passing to the banana etc
How do you use OOP in unity?
the same way you use it in any other frameworks
Do I just delete mono behavior and type the other script in it?
well the tricky part, unity is component based
so you have to also think about that
monobehaviour is a component
decide when your object should be just a POCO or a Gameobject MB
A better question would be what do you want to achieve
so yeah delete MB if you dont need to be a component
@rich adder I'm not sure if this is helpful but
in the console window, the error seems to start
right when I try to post data to a php server
(the leaderboard)
does maybe webgl not mesh well with that sort of thing?
typically you would get a CORS issue but doesn't seem like it, seems like something might be going wrong on your code itself ? are are you using a UnityWebRequest ?
Nothing should be wrong with the code, the windows build works perfectly
however I did get an interesting message just now
whats the stacktrace on that
is ScriptableSingleton your thing ? I never heard of it
oh nvm its a unity class, hmm its a Editor only class so no idea what happen there
yes, but it's editor only, should not be in a build
This error only seems to happen in the build where I try to post to my php server
what happens in code after "attempt"
what about the windows build ? did you check the player-log file
tbh, that error looks like a code stripping problem
Just tried the windows build again, it works fine. Where is the player-log file?
in the code, the game is supposed to be over but it never even reaches that point in the webgl build
it just crashes
Oh? What does that mean
!logs
ops they dont have player log here, click the link
so basically it's stripping away the code needed for the http stuff?
possible but not necessarily, generaly it tends to over strip code using generics
but it can also be if you use Invoke or a coroutine with a string argument
But why would that not be an issue in the windows build? Unless webgl specifically can't work with those
because WebGL builds use a more aggressive code stripping algorithm
hmm fair just trying to find that optimization section the article spoke about
best bet, look at the Preserve attribute in that link and apply it to your code
how do i check the names of gameobjects thru code?
im using a raycast for interactable gameobjects and i was thinking to check the gameobjects name
a gameObject has a name property
i can check for tags but idk if thats the best way
yeah gameobject.name
but i cant do if(gameObject.name = ("smth"));
no because that is not valid C#
yeah so how do i do ti
look at what is wrong with the code you just posted
theres no CompareName
i know its wrong, ofc its wrong its just an example
nvm
im a braindead person and im ok with it
i was right i just needed the extra = and rto remove the brackets
not my fault i was dropped as a baby
if (gameObject.name == "smith") {}
yep 🙂
you should not be using gameobject names for any logic tbh
I use tags tbh
better but still bad imo
strings are not very good
Not sure what the better unity-way is to do it
they are not type-safe
if(collision.collider.TryGetComponent(out Player player))
player.DoSomething() or Destroy(collision.gameObject)
etc..
trygets all the way
If that's invoking a try-catch inside it, seems rather expensive for a simple compare check
eh? ive been told for 3 years now.. thats the beetter way than to compare strings
Invoke a try catch wdym
try-catch makes a copy of your entire call stack. I tend to avoid it unless I think the app will crash due to it
Oh
its like wiriting
var player = collision.collider.GetComponent<Player>()
if(player != null)
and get component is relatively performant
if(hit.collider.transform.TryGetComponent(out IInteractable interactable))
{
cachedInteractable = hit.collider.gameObject;``` u can use it different ways too.. i like to use em for Interfaces
Every method with Try assigns the internal method to the out parameter and returns true is it's not null, as was shown above
Lowering stripping level didn't work. This is such a weirddddd error. I mean I guess webgl isn't totally necessary but would have been nice to have it on itch.io
maybe I'll focus on windows for now
wat is the code doing can you show the function that posts to leaderboard
So you should really use UnityWebRequest (I thought you had been asked ths already) HttpClient does not work on WebGL
no reason it shouldn't, it's just a .NET lib like anything else. I wonder why webgl hates it though
Sure, for standalone and Mobile, not for WebGL
because it's async
wait so if I just made it not async, it would fix it?
no
the whole library is async, not just the bit you use
Hmm, okay, kinda lame. I'll keep that in mind for future builds if I want to keep supporting webgl
thanks for the help
actually, when unity supports Wasm2 you should be ok, that supports async
Oh? Is that coming soon? It's not too big a deal right now as my primary target platform is windows and eventually macos
webgl was just a nice to have
public const string PlayerTag = "Player";
Also if you wan't to compare tags, you can define const string in a related class. If you need to change it, you can change from one place.
a bit better with using consts , but I would still opt for components
consts are good where strings can't be avoided
good example is
Animator.StringToHash you still need the animation to be a String.
why not?
i have some shop keepers and i tought using their names would be better then tags
Why not just have different data on the different shopkeeper objects, then you don't need to check anything at all
huh
^ ShopKeeper should be a component
then it doesnt matter which one you grab cause they all have their own stuff
component?
yes , anything that sits on a gameobject is a component..
yeah i know but i was thinking of just checking the names of the gameobjects that my raycast is hitting
then if u press E it opens up their shop i already implimented that
anyways so im having an issue with the raycast lol
thats why you would check the component directly
it isnt following the player it just stands at the spawn locaiton of the player
if(hit.collider.TryGetComponent(out ShopKeep shopKeeper)
shopeKeeper.Interact()
wdym component check if it has a collider? a script?
its just like 3 buttons anyways
a script on a gameobject is a component yes
show !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.
yeah but then i need to make a script for each shop keeper why do that when i just check the tag
its like 3 lines of code
why would you make a script for each shop keeper/
they all have the same script "ShopKeeper"
how would it know the differnt beetween shopkeepers
based on the data on them?
idk its alot easier to check the tags
easier doesnt mean good
its not like i have 10, i barely have 3
you could even put a "ShopKeeperName" string if you really wanted to print a name or something, but why would a name change anything in the logic.
whats the differene beetween me doing that and just checking the tag or name
how is that "better"
i mean yeah, it would be better if i have alot of shop keepers sure but i have 3 and its all simple
the last method i was using it was thru colliders lol
because you're adhering to the proper OOP principles
if im a trigger colllider with that tag then it does this etc, but i need to make it easier for smth
OOP principles?
use a component designed to be a shop keeper is a lot better than checking a name then doing what?
object oriented programming
(class for example is an Object)
then just enabling a text that says press e to interact and once u do it just opens a UI
and where does the shopkeeper keep stats? money it has etc
the money is stored on the player
and so are the variables
well thats why i was suggesting better but you seem to think its better cause its easier to check names on each shopkeepr 🤷♂️
everything is just a bool or a float, if i press a button it enables a bool that then lets me have a gun active
or a button that increases my health count
etc
its cause i already got a system i just need to change smth
il look into it later, now why is my ray cast not following the player?
if (Physics.Raycast(RayCastGameObject.transform.localPosition, transform.forward, out RaycastHit Hit, 100, Interactable))
"my boat already floats with duct tape covering the holes, I dont need a new raft"
exactly
No, you'd make a ShopKeeper component and read data from it to know which shopkeeper you're using
ok
what is RayCastGameObject and why is the direction another object
oh its the location from where the raycast starts
For example:
Debug.Log($"Hello, I am {shopKeeper.name}, and I sell {shopKeeper.inventory} for {shopKeeper.prices}");
and does that object follow the player?
show where do you see its not following
did u use the Physics Debugger to check where the ray is
nah im just using gizmos.drawline
show the line
the line of code or the gizmo line
drawline is wrong usually if you're doing ray
gizmos.drawline should be drawray but show code anyway
Gizmos.DrawLine(RayCastGameObject.transform.localPosition, transform.forward * 20);
the second spot expect a position, you're passing a direction
Gizmos.DrawRay(RayCastGameObject.transform.localPosition, transform.forward * 20);
yep thats the line i sent
except it isnt
yeah u just changed it from drawline to drawray
yes now you should be able to see the proper debug
yep still same issue
show the issue
red line is the gizmo
Turns out that when you change what function you use, it changes which function is used. Who knew?
show inspector for the RaycastGameobjectObject
that beatiful model is the player it should be where the arrows are at
also we have no idea if this is Local or Global mode
the gizmos are they in Local or Global
i have no clue
so check?
how
topleft corner scene view
Change your inspector gizmo to "Local", select the object that has your Gizmo code on it, then show the transform gizmo that appears for it
oh im on local
Okay, that's good. Now, select the object that has your draw gizmo code on it, and show where the arrows are
also can you show the hierarchy ?
how would I make a rigidbody rotate around the centre of another rigidbody instead of the centre of itself?
Yeah, that line looks pretty aligned
kinda wierd on how the line goes a lil bit behind
yeah until i move
Well, you're starting it at the position of a different object
Okay, move, then show the line and gizmo
RotateAround function.. idk how that would work on RB tbh actually
it looks like it draws a line from the middle to the player
Yes, it draws a line from RayCastGameObject in the direction the player is facing
you're passing localPosition
noshit
Does rotatearound use momentum like torque does?
thats cool
ok
neat that fixed it
I made a ui and on the ui there is a text loop lik a news thing which is at the bottom but whn the second loop comes it spawnes like faw back idk whats wrong and also when i change cameras to the ui the loop stops
show setup + scripts
we have 25% of the problem here
!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.
'''cs
oh wait mb
wait bro can i ask a huge favour can i just call you
I'm new to pc
use links
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Does anyone know how to manipulate two Unity UI elements on Vector2 without something weird happening? I'm trying to place a UI element next to another by first puttin it in the middle of it and then sutracting it's x placement by half the width, but instead it goes like -1000 on the x axis
AI code is bad
but you should reset the position too
For this
brother that aint ai code that was actually my own i just got emo and ask Chat gtp to help
idk wth I'm doing worng
I can recognize ai code when Is see it lol
ok but it is not but like pllllllsssss do you see what is wrong
all you need is to track 2 positions
which one is the moving text
man you should use proper names like NewsCanvas NewsText so you can tell whats what
has the script
if you actually wrote that code, you would know how to fix it 
what is doing it rn? can you show a vid
how do i show i vid
record with OBS or something, then send it over as mp4. or use streamable.com
o0o00o0o sussy baka i fixed i forgot the GetComm
but the other one still does not work where i chage the cameres it stop
i will send vid
can you not just use the canvas to do so?
My game is build but crashes when it connects to multiplayer through photon. its a android game for quest 2 so i have the logs
(i have reinstall unity and rebuilt the libary folder)
java_vm_ext.cc:579] JNI DETECTED ERROR IN APPLICATION: JNI GetStringUTFChars called with pending exception java.lang.StackOverflowError: stack size 1038KB
java_vm_ext.cc:579] at java.lang.Class java.lang.Object.getClass() (Object.java:74)
java_vm_ext.cc:579] at java.lang.String java.lang.Throwable.toString() (Throwable.java:491)
java_vm_ext.cc:579] at boolean com.unity3d.player.UnityPlayer.nativeRender() ((null):-2)
java_vm_ext.cc:579] at boolean com.unity3d.player.UnityPlayer.-$$Nest$mnativeRender(com.unity3d.player.UnityPlayer) ((null):-1)
java_vm_ext.cc:579] at boolean com.unity3d.player.UnityPlayer$D$a.handleMessage(android.os.Message) ((null):-1)
java_vm_ext.cc:579] at void android.os.Handler.dispatchMessage(android.os.Message) (Handler.java:102)
java_vm_ext.cc:579] at boolean android.os.Looper.loopOnce(android.os.Looper, long, int) (Looper.java:214)
java_vm_ext.cc:579] at void android.os.Looper.loop() (Looper.java:304)
java_vm_ext.cc:579] at void com.unity3d.player.UnityPlayer$D.run() ((null):-1)
java_vm_ext.cc:579]
java_vm_ext.cc:579] in call to GetStringUTFChars
java_vm_ext.cc:579] from boolean com.unity3d.player.UnityPlayer.nativeRender()```
Explain
seems like a photon problem
Baka
it was working fine until randomly it just didnt
until i chagned cameras
you have UI on a Canvas, and you can move said UI on the Canvas.
I'm trying to do it via script. I have a cursor that I want to appear next to a UI element
randomly it just didnt work? explain what you did before it did this so you can configure it
why dont you use the UI's position and then add an offset vector2 to it
i just dont want to loose you
Since I'm stupid, could you show me how you would go about doing that?
I have an idea of how that would go, but I don't want to jump into it without knowing exactly how to do it
well thats how u learn..
here, this should help you figure it out: add == +
BOXXXXX
help me please i send a vid idk whats wrong
.... dont leave me now ........
• @’ing or replying to people who aren’t in the conversation.
heheh sorry
== + offset of UI object?
i'm saying that to add an offset you literally just use the + operator. if that is too much for you, then perhaps you should start smaller and do the beginner courses in the pins
were in the operator
why does the box push me off so weirdly even though it has a normal box collider
I've done a few of those but working with UI is a different case. I was confused about how to implement offsets in unity because there is one in the inspector and another way via code
its slippery
how do i change that
wdym "there is one in the inspector and another way via code"?
this is a code channel. perhaps you want #⚛️┃physics ?
oh, wrong channel
There's some offset option that I've seen in UI. But I'll figure it out, thanks
u would suggest you !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
but a hint would be +, adding an position by a vector2
I figured out why this was happening, no need to answer now
You mean something like this?
yup!
cameraUI.position = OtherUI.position + new vector2(X,Y);, X and Y are floats to adjust in the inspector.
that is 2 floats. the problem is they need to use a Vector3 not a Vector2 for the offset
I see
because transform.position is a Vector3 which means only a Vector3 can be added to it
is OnCollisionStay(Collision collision) better in this situation?
void OnCollisionEnter(Collision collision)
{
if (Physics.Raycast(transform.position, Vector3.down, out hit, 1.5f))
{
is_jumping = false;
}
}
why even put that into a collision message? why not in Update or FixedUpdate
won't that slow the game down?
lol no
ok ig
raycasts are incredibly cheap
Sadly, this still happens. I'm just confused why the x value is such a high number if the width is something like 100, meaning that the float value for x should be like -50
try using floats like in my original message and adjust via inspector
in playmode then copy the position back in scene mode
Yeah...
My issue is that it's turning the position into some crazy number
what object is the first photo?
looks fine?
So, in the beginning, it sits at about Position X of -60. But if I tell it to do that in code, it goes to Pos X of 14400 As shown here:
hmmmm 🤔
ive never seen this bug before
rectTransform.anchoredPosition = new Vector2(-63.4, 26f); try
so it's ANCHORED position, gotchya, thanks.
I knew the fix was probably simple, but I was so confused
yea rect transforms a bit odd
So why does it do that with regular position of rect transform?
well that works
Thanks for all of your help still
b/c its using world coordinates

soo - 144400 or w/e is how far the UI element is from the origin of the world
note that the position you see in the inspector of a rectTransform is its anchoredPosition
(placed on the big ole canvas gizmo thats offcenter of the gameworld)
I thought if I made the canvas set to world view or world space, that means that the world space works in code for the vector
i guess use anchor position for UI stuff 😅
rectTransform.anchoredPosition: This property sets the position of the UI element relative to its parent’s anchor points.
I see now
Okay, so this SHOULD work when I try placing it next to another UI element
Lets try it
should sure 👍
Works better than before. Now my only issue is that the play button and the cursor rect position are different for some reason
what is the issue with this?
I actually figured out another way to go around this, but I'm just confused why the rect transform position between the cursor and the play button are different
Like, they're both in the middle, but their rect transform positions are completely different
the buttons are a child of a different object entirely
you can add the mouseUI with it to make them the same
if you want
Alright, but it's okay since I got my main problem solved. Thank you all 
the rectTrasform is affected by the canvas and its scaling
yeah, but the scaling shouldn't really effect it's position. And they both share the same canvas
well normally canvasScaler does affect the positioning sometimes
True indeed, but these two objects are on the same canvas
im making a vr game and i added a computer with a mouse to it, but right now im doing it by hard coding the position the mouse has to be on the canvas to click on a certain object is there a way to find out what element the mouse is pressing on without this horrible trash
use a website !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.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
kinda just wanna know if there is a name for like an approach to this problem i dont know of
and yes i know the code is bad thats why im trying to clean it
why the manual position check
these magic numbers look like implosion waiting to happen
are you using a world canvas?
yes
but also
uh the worst way
i have a seperate camera
rendering ui only
just so i can put it on the screen with a render texture
so that it gives that curved crt screen effect
but whats wrong with the cursor rn
no it works im just asking what the better way to do it is instead of hard coding the positions of things on screen
from my understanding VR doesnt have overlay canvases ?
Is there any way to organize variables "separating " them in the inspector via code?
if its a virtual cursor it should be ok
just dont use magic numbers, create actual variables with meaning to those numbers
Header attribute
so just make them varibles?
theres no way to tell what the fake cursor is on?
there are some methods for UI elements sure
like i think with a real cursor theres like a screen to world thing
Thanks!
use event systems raycast, it tells you which UI elements it hits
ok, never tryed that before, will try now
idk the virtual cursor thing makes it tricky
since your'e not moving the hardware cursor, I think EventSystem.RaycastAll relies on that
array length is Array.Length right?
I would test it myself but launching unready unity script is painful
yes arrays have Length, they are fixed size collections. Hence length not count
extra info incase that gives any ideas
is cursor a canvas element?
think so
maybe you can Modify the InputModule to use the virtual cursors position
also uncheck Raycast target on it
ok
you dont want ur cursor to be a raycast target blocking other UI
any suggestions on how to make my character’s legs not move at the same time (im trying out procedural animation)
uh... how i use clamp?
C for clamp
sorry but, wym? where i put this C
capital C instead of the lowercase c
oh, thank you
yeah, just saw it is different the F being capitalized or not
yeah MathF is a system class, it doesn't have Clamp
one thing i like about gamemaker and im not finding in unity is: when i click with the middle mouse button on a function or whatever it is, is opens the documentation of that thing on the browser, there is any button i can do something like that? it would be soo good
(im coming from gamemaker, so im a bit confused)
nah thats reliant on the IDE you use. I think Rider does that
there is any extension or something on visual studio that allows that?
you can try CTRL+ALT+M, then CTRL H
yeah sorry that thread is old, it should tell you if you go under Environment -> Keyboard search for Unity
I'm not sure, for checking rigidbody I should use if (hitColliders[i].TryGetComponent<Rigidbody>() == item1) or what?
checking what?
basically this
ah
I thought it would be used to attempt to get component
yes but it returns a bool, the out is the component if its not null
if I use getcomponent rigidbody on a collider that doesn't have rigidbody will it fail?
shouldn't
why not just use try get tho
ok
why is it gray?
because it can infer its type already from the type you passed to out itemToAttach
also you're comparing a bool to a rigidbody ?
idk how thats not erroring
why it wouldn't assign to the itemtoattach above? (since it's gray it wouldn't be assigned I assume)
how would I make my character float in water
nah item1 is a rigidbody
wdym that?
Its gray meaning you can remove it , it already knows the type from the itemToAttach declared above
It would assign
TryGetComponent returns a bool though
I personally prefer early return patterns, I would usually do
if(!collider.TryGetComponent(out itemToAttach) continue; //continue skips the rest of loop
if(itemToAttach != item1) continue ;
//do other stuff
nesting so many if braces gets unreadable sometimes
thanks
how do i make a random item generator from a list
instead of doing a random number index
or is that not possible?
get random number, select that from list, what's the problem with that?
i want to know if there is a better way to do it
not really
alright, I did it that way
k thanks
bool item1_is_touching = false;
for (int i = 0; i < hitColliders.Length; i++)
{
if (!item1.TryGetComponent(out Rigidbody hasRigidbody)) continue;
Rigidbody hitRb = hitColliders[i].GetComponent<Rigidbody>();
if(hitRb != item1) continue;
item1_is_touching = true;
}
why you doing another get component lol
hasRigidbody is the result
you told me trygetcomponent gives bool
the out returns something
yes but if its true, meaning it found the component, it puts it into out
pretty sure I mentioned it before
bool item1_is_touching = false;
for (int i = 0; i < hitColliders.Length; i++)
{
if (!item1.TryGetComponent(out Rigidbody hitRb)) continue;
if(hitRb != item1) continue;
item1_is_touching = true;
}
so I just do it like that
how do i compare 2 different Vector3s
==
well depends ig what you comparing
i want to compare 2 transform.positions
How are you intending to compare them? What "question" do you want to ask them?
their value
yes but how close they are or
What about their value
imma send the code
this.transform.position == that.transform.position;
if ((Mathf.Abs(transform.position - player1.transform.position)) > (Mathf.Max(transform.position - player2.transform.position, transform.position - player3.transform.position)))
{
nearest_player = "Player1";
}
approximately
I can't make heads or tails of what you're trying to do here. What is the actual thing you're checking for?
this line is comparing the distances of the transform.position and the player1.transform.position with the other distances
Okay, so why not use Distance?
https://docs.unity3d.com/ScriptReference/Vector3.Distance.html
I dont see how it gets you nearest here
oh I forgot
i didn't know that existed, but will it output a float or Vector3
Man if only there were a sort of "Docs" page you could look at that someone had linked to you that you replied to that you could check
out outputs the Distance.. (1) number
thx
if that number is < than a threshold u supply u could basically assume its in the same spot
i'm gonna make it so that if the distances are close enough, it will choose a random one
Transform GetNearestPlayer(Vector3 point)
{
Transform nearestPlayer = null;
float minDistance = Mathf.Infinity;
foreach (Transform player in players)
{
float distance = Vector3.Distance(point, player.position);
if (distance < minDistance)
{
minDistance = distance;
nearestPlayer = player;
}
}
return nearestPlayer;
}```
`[SerializeField] Transform[] players`
i don't understand this
which part?
almost all of it
pretty basic c# code, with a sprinkling of math
lets say you want the nearest player from some other object, you just do
Transform nearestPlayer = GetNearestPlayer(targetPoint.position);
the rest of the code is simple maths
i don't understand the math part of it
set nearest player to nulll make sure its not assigned to any other
set minDistance to infinity
each player run distance setting the newest lowest value to minDistance..
finally return the lowest player / b/c of lowest distance
each time a player is calculated the min changes if its smaller (closer)
its basically a get lowest number loop
oh
foreach is looping through all players (checking each one as player)
is foreach a for loop, (i haven't used for loops yet in C#)
its basically for loop w/ the length already set
its similiar to forloop but you loop through the objects instead of using iterator, and its not mutable
new int[] myIntArray[3] <--- foreach will run 3 times
k thanks, but what does [SerializeField] do
exposes a private variable in the inspector
just makes private items appear in the inspector
k thanks
similiar to how public shows everything in the inspector
but keeps it nice and private 🕵️
then why not use public
maybe at some later point you accidentally access it from another script and change it from there when in reality it shouldn't
self protect (or if you're with a team , its like saying dont change this from anywhere else but this script)
Please how do I fix this:
Your advertising ID declaration in Play Console says that your app uses advertising ID. A manifest file in one of your active artifacts doesn't include the com.google.android.gms.permission.AD_ID permission.
If you don't include this permission in your manifest file, your advertising identifier will be zeroed out. This may break your advertising and analytics use cases, and cause loss of revenue. Learn more
You can remove these errors by updating your advertising ID declaration
Apps that target Android 13 (API 33) without the AD_ID permission will have their advertising identifier zeroed out. This may impact advertising and analytics use-cases. Learn more
ok
it gives these errors when I implemented it into my code
this is the code for the script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Enemies : MonoBehaviour
{
public int enemy_health = 100;
public GameObject player1;
public GameObject player2;
public GameObject player3;
public Transform[] characters_selected_list_Vector3 = { player1 , player2, player3 };
public string nearest_player = "Player1";
private int random_number = Random.Range(0, 3);
void Start()
{
}
void Update()
{
if (enemy_health <= 0)
{
Destroy(gameObject);
}
}
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "Bullet")
{
enemy_health -= 10;
}
}
Transform GetNearestPlayer(Vector3 point)
{
Transform nearestPlayer = null;
float minDistance = Mathf.Infinity;
foreach (Transform player in characters_selected_list_Vector3)
{
float distance = Vector3.Distance(point, player.position);
if (distance < minDistance)
{
minDistance = distance;
nearestPlayer = player;
}
}
return nearestPlayer;
}
}
you cannot access/reference other fields when initializing a field variable . . .
wdym, i don't understand
did you read/google the errors? its really quite clear in its description
you have to initialize or assign the field characters_selected_list_Vector3 in a method . . .
you can populate the array in Awake
what does Awake do
you should really try googling stuff https://docs.unity3d.com/ScriptReference/MonoBehaviour.Awake.html
when you receive an error, it's best to search it to learn and understand why the error occured: https://learn.microsoft.com/en-us/dotnet/csharp/misc/cs0236. all of these are called fields. they are class-level variables cs public int enemy_health = 100; public GameObject player1; public GameObject player2; public GameObject player3; public Transform[] characters_selected_list_Vector3
you cannot initialize a variable outside of a method . . .
everytime i search up my error, i get a confusing stackoverflow answer that i don't understand, so i just stopped searching errors up
why does it tell me that i need to put a closing bracket even though i put it
this is the error: Assets\Scripts\People\Enemies.cs(16,6): error CS1513: } expected
this is the Awake part
void Awake()
{
public Transform[] characters_selected_list_Vector3 = { player1 , player2, player3 };
}
is that the first error in your console, shouldnt be. also do some c# basics you'll get a lot further
there are 3 errors scattered around the code, this is the earliest one tho
is your IDE not configured ?
also this variable name is crazy characters_selected_list_Vector3
wdym by configured, also, i'm using vs code
do these errors appear in red squiggly lines in your IDE? they should . . .
if not, then you need to configure your !ide . . .
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
nope
it should be underlining red in the editor
also that array was meant to replace player1, player2, player3
lemme configure it rq
i can't find Unity Preferences
Edit -> Preferences
or Unity -> Preferences if you're on mac
Visual Studio Editor has been updating for 5 minutes
finally done
done what? is it underlining now?
nope, but i'm done configuring
if its not working then you're not done lol
it has unity on the side
I have no clue what that means
this
if its showing you the meta then you did not do it correctly
what's meta?
should look like this
.meta files are meta files unity uses to keep track of assets so all the connected objects and their component etc
what do i do
first of all , did you do the part about package manager, did you verify the version of Visual Studio Editor package, and screenshot your external tools page
close vscode in the meantime
not if you double clicked the script from unity editor
it should not affect other windows
i did
i have 3 different vscode with diff languages
Different vs code profiles?
no they are just separate windows, they are counted as standalone instances
ok now show externaltools in unity
yeah that aint correct
what's the problem
did you read the guide at all or skimmed through it?
it told me to pick visual studio code, so i did
oh.. wait
you have compile errors
its probably why it can't refresh
so what do i do
temporarily comment out the script
public class YourScriptWithError : MonoBehaviour
{
/*
//codee etc.
*/
}```
use /* to start the comment portion and */ closes it
i already did // for every line xd
i selected the new one in external tools and re-opened vs code by double clicking on the script and i got this
and i looks the same as before
also it gave this warning
Project path contains special characters, which can be an issue when opening Visual Studio
UnityEngine.Debug:LogWarning (object)
so what does choose to open do
well does it ? thats no good not just for visual studio
no go back to unity regenerate project files
how
External tools, close vsc (all the windows)
make sure it shows the vscode version, Regen, open script from unity
this appeared again
did the vscode version and regen button appear in external tools
check the Output window in vscode does it say anything about SDK missing & and what does Terminal window say
btw the unity project name has a hashtag, so that might be making the warning message
probably
where is the output window
should be in VScode at the bottom, or View -> Output
which language do i pick here
it was at .NET
IdeBenefitsSource: Failed to fetch entitlements. Error: 'Error: Request to https://api.subscriptions.visualstudio.microsoft.com/Me/Entitlements/IDEBenefits?api-version=2023-03-26&caller=vscode failed with status code: 401 and response ""'
this is what it says
nah this is probably related to not logging into devkit
try the c# one, close Vsc and open script again if you must, it will reset
or .net install tool, one of this
waiting for named pipe information from server...
[stdout] {"pipeName":"\\\\.\\pipe\\1eb67383"}
received named pipe information from server
attempting to connect client to server...
client has connected to server
[Info - 4:19:30 AM] [Program] Language server initialized```
don't mind the 4:20 am xd
nope, this is my vs code
why does your project have multiple solutions.. close vscode, delete all .sln and .proj files in your root project
Regen project files again
.. and u got a notification on ur extensions panel
should also say Assembly at the bottom + Devkit logo with C#in hexagon
yeah delete everything .sln / .proj like i said
do i move to recycle bin
lets make a thread maybe so we dont flood this
Hey, how can I use Dictionary TryToGetValue out and parse it at the same time?
int w, h, x, y, z;
if(properties.TryGetValue("w", out Int32.Parse())
Before I moved it to dictionary, I used a list:
int w = Int32.Parse(properties[0]);
Is that possible? Is there a way to include a default value?
just put an &&
Whats &&?
if (properties.TryGetValue("w", out string wValue) && int.TryParse(wValue, out w))
Is there a way to negate this whole statement? I.e. if there is no value in dictionary then I would assign a default value or do nothing?
Ideally I'd not even use if statement here
int w = 100;
int h = 100;
//try parse
you mean like a ternary ?
int w = properties.TryGetValue("w", out string wValue) && int.TryParse(wValue, out int parsedW) ? parsedW : 100;
Thanks, that works too 😄
Hey, I'm having a very weird issue with a script I've written just... not running. I can't seem to figure out why it's happening. I've written a script called "Inspect" that takes in an animator and two textures. Using OnMouseEnter the script is supposed to play an animation state called "Inspect" on the animator and then change the cursor to a different design. It works only on one object in the scene... Like, only one object and nothing else that I apply the script to, even if it's the only copy of the script in the scene at any given time.
I've also added a Debug.Log statement in the code but the only time that statement gets fired is when the OnMouseEnter event happens for the one object in the scene where the script works. As far as I can tell, there's nothing that should prevent multiple copies of the script from running in the scene at once.
Am I doing something wrong, or am I going insane?
The first screenshot shows the intended behavior on the object in the scene where it works. The second one shows the Inspector for that object. The third screenshot shows what's happening to the second object along with the inspector. Not sure if there's a particular place I should post the code or if I can just use a Discord code block. It's not super long.
Unity Version: 2022.3.41f1
Platform: Windows
send the !code via link
📃 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.
do the logs print for second object
No.
can I see the collider of the phone in scene view, also the table collider
The table does not have a collider.
i wonder if anything else is blocking it
hmm i don't miss OnMouseEnter at all lol no way to debug it properly like drawing rays, hitinfo
Is there another way I should be doing it? Haven't really touched Unity since like 2014 so most of my knowledge is coming from that and from the docs
The other weird thing is that multiple scripts in the scene are all using OnMouseEnter so it's weird that this is the only thing that's not working.
Do you have a specific docs link for it?
Or a piece of example code?
I'll have to look into that!
[SerializeField] private LayerMask inspectableLayers;
[SerializeField] private float maxDistance = 100;
void Upate()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out var hitInfo, maxDistance, inspectableLayers))
Debug.Log($"Hit {hitInfo.collider.name}!");
}```
Let me see if I can do something with that. Would this auto-populate the list of layers in the project in the inspector?
im optimizing a loading mechanism inside my app , this mechanism is to download game images (as png), store it to local , and then read/use it in code
the flow that i want it to be is like this:
//write
server => png downloaded as bytes (websocket.dlhandler.data) =>
File.WriteAllBytes("TEH PATH", webRequest.downloadHandler.data);
//read
texture.LoadImage(File.ReadAllBytes(filePath));```
only the ones you select
but yeah its the ones from the unity layers
Perfect. Let me modify this code rq to see if I can't at least get more info on what it's hitting.
what is the question?
only thing I would recommend so far is using async File.WriteAllBytesAsync
IO operations are already slow as is :\
this is the "write" function , the write part in my post
the call back here needs the file that i written , as texture2D
because this is an async function with web request stuff, i want to ask if i create a texture here with
new Texture2D(...);
texture2D.loadimage
callback(texture2D);```
will it be expensive?
the callback is actually a function , its the "read" part
loading from filedisk you mean?
if you're coroutine should be ok I guess, i always do my IO /net operations on async
Huh, the Update function isn't running... I'll have to get back to this a bit later after reading the docs a bit further. Maybe I'm doing something else wrong.
it is an async function
how do you know its not running
Noticed it wasn't printing anything so I slapped another Debug.Log statement in there.
oh okay should be fine, you would need to profile it, and maybe with worst case scenarios like slow HDD or slow net
there are tools to simulate such slowdowns
before if statement right ?
is the script on a gameobject?.
Check the Console window, screenshot it in playmode
also if you do it this way you only need 1 script and on the camera / player object with ray
you dont want multiple rays for same thing
-
download from server , as bytes
-
write as file from bytes
-
create a new texture2D() container
-
fill in the data with texture2D.loadImage
-
parse in callbacks
my question is , after optimization, i added step 3 and 4 here, will it be expensive? if this function also need to "download stuff from servers"
i dont want a sudden heap of usage in particular function, should i move 3 and 4 to somewhere else?
its just distribution of workloads
Oh huh okay. I'll keep that in mind. This is literally just a very very early Prototype of the game I'm working on so it's good to figure this stuff out and learn new stuff.
I cant predict what your project will do , every project is different. Should be relatively fast with bytes array. its pretty common for net data
goodluck 🫡
String folder = Path.GetDirectoryName(savePath);
if (!Directory.Exists(folder))
{
DirectoryInfo di = Directory.CreateDirectory(folder);
}
Texture2D convertedResource = new Texture2D(1, 1);
convertedResource.LoadImage(webRequest.downloadHandler.data);
if (!savePath.Contains("blur"))
{
File.WriteAllBytes(savePath, webRequest.downloadHandler.data);
}
else
{
convertedResource = BlurTexture(convertedResource); //warning: pixel data manipulation will cause heavy RAM usage
}
callback(true, convertedResource);```
so its not going to 0.1f in the blend tree?
0.1 means the characater is moving?
idk what values you put for walkback
is -1,0 and 1
so why you write 0.1f for input.x
idk, is wrong...
you want it to animate movement which way when rotating
pass that value
for both sides
yes, but I want it to play when it is rotating
right so thats input.x value
but how can I add this to the code?
if I change y for x the walk animation only plays when rotate
you need both
it worked with this, but now the reverse walk animation is not playing
unrelated, but, when you are pasting code write ``` cs in the begginning
and ``` in the end
i accidentally put a space between them
!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.
better yet use links when its a large code like class
atleast now he knows if he ever wants to write code in discord
"Ai" strikes again..
yeah, sorry for that, but I have no other option rn
I know it can be offensive for real programmers 😂
its just that its only doing you harm since you dont seem to understand what you're pasting in
without using ai /google, do you know what mathf.abs is doing?
I'm like, hit or miss
no idea, but you told something about using math so I thought it could be related hahahah
using AI is fine (only a small part tho)
but you have to understand what the AI wrote
and understand why it works
I understand some little things
you can ask AI to explain it if you don't understand btw
AI is giving some other soutions that don't make too much sense
like, add parameters to the blend tree, but the blend tree only accept one parameter
its never going to be -1
Ai cant explain diddly squat. It just spits out a series of words that have a high statistical probability to be grammatically correct.
from my experiences, AI explains perfectly fine
but to be fair, when i was using AI, it was some really basic stuff
AI is terrible at complex code
I thought making a guy walk around while standing still would be something simple for AI
the "AI" has no concept of what you're doing or know how to apply any logic to it, its not a thinking machine just a fancy searchbox
But it does not explain anything you can literally tell the gpt that what it said is wrong and it will spit out a new series of grammatically correct words that fit the context. You simply got lucky that the series of words you got spit at you were in fact in line with the truth
walk around while standing still?
indeed chance / got lucky
I'm finding this out the hard way
at least it took you 70% quicker than most
like, play the "walk" animation while spinning in the same place