#💻┃code-beginner
1 messages · Page 618 of 1
new (-1, 1)
new (-1, 1), actually
not sure if its what ur after.. but u can expand a sprite sheet and select just the sprites u need /want animated from it (Ctrl + Click) and drag into the scene.. (no need to drag the entire sprite-sheet) unless u need the entire sprite sheet
Thanks
took me a minute to realize that myself..
new Vector2(-1,1), actually
oh neat..
I am trying to make a 3D Breakout/Arkanoid game for a uni project right. The one thing I cant do is the ball movement making it bounce around the playarea using Rigidbodies. Internet is no help at all and I'm about to give up and fail this can someone help
Sure i dont know how to make the ball interact and bounce around the playing area like how it does in for example pong or the 2d version of breakout
But this is for a 3d version of breakout
this is my current code for the ball it starts to work then pushes itself to the left side and stays there pushing against it
using UnityEngine;
public class Ball : MonoBehaviour
{
Rigidbody Rigidbody;
void Start()
{
Rigidbody = GetComponent<Rigidbody>();
Rigidbody.maxAngularVelocity = 1000;
StartCoroutine(ChangeRotation());
}
private IEnumerator ChangeRotation()
{
while (true)
{
Rigidbody.AddTorque(new Vector3(10 * UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range(0, 1f), UnityEngine.Random.Range(0, 1f)), ForceMode.Impulse);
yield return new WaitForSeconds(1);
}
}
void Update()
{
}
}
When it collides with a wall, reflect its velocity
u could even add a bit of randomness then..
the torque feels unecessary.. but then again.. im not a pong expert
It'd make the ball change its heading every second
stuff like this should also be in fixed update, assuming you even need this in the first place
which I suppose is a way to do a twist on Breakout
Impulse is fine to do outside of FixedUpdate, it's applied all at once
thats not the issue with it, the current code depends on frame rate
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
there is a WaitForSeconds
frame-based issues would arise if frames take more than a second
honestly i completely missed that line
idk what other tests there are but
these are editor
idk if thats the reason dotnet test doenst work?
So I'm not if there's a better way to do this (Probably is but I'm having problems with anyways). So I am trying to put a collision on this enemy when it dashes but when it does. The collision is compressed and smaller then what it should be and I ain't sure why.
(This has both code I'm using for it.)
https://scriptbin.xyz/ujejezicec.cpp
Use Scriptbin to share your code with others quickly and easily.
you scale it by 0.5 on all axes when dashing?
try changing ur collision detection method on ur rigidbody
That's what I tried doing but it didn't fix it
(btw, those yield return new WaitForSeconds(0);s aren't doing anything)
yeah i mean that sounds like it's part of the issue?
I know, I have plenty in there that need to go
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float speed;
private float startPosX;
private Rigidbody rb;
private void Start()
{
rb = GetComponent<Rigidbody>();
}
// Update is called once per frame
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began)
{
startPosX = touch.position.x;
}
else if (touch.phase == TouchPhase.Moved)
{
float movePosX = touch.position.x;
float direction = (movePosX - startPosX) / 5;
rb.linearVelocity = new Vector3(direction * speed, rb.linearVelocity.y, rb.linearVelocity.z);
startPosX = movePosX;
}
}
}
}
I am trying to make some basic movement on the x-axis for mobile, this so far works great but the movement is really choppy and i don't know how to fix it.
To what?
Well nothing change with it and if I remove it, nothing still as it still compacks
also. not sure of ur setup..
but u need to keep graphics seperate from the root object and its logic..
esp when dealing with colliders and physics and stuff (want to keep them as close to 1:1:1 as possible)
What you mean but graphics? What graphics I'm messing with?
question: I have code that manipulates the position of my player in unity using the line transform.position += moveDir * moveSpeed * Time.deltaTime;
when that line references transform.position I am assuming its directly referencing the "Transform" tab/class on the left side of the picture that holds the x,y,z position of my character.
my question is how does transform.position reference those values? when it says transform, it doesn't seem to be referencing an object of the transform class, which is strange cus usually the notation is Object.aVariableOfThisObject. On top of that, I see a public position variable in the Transform class with some get and set code that I don't really understand, but either way, how does the line of code transform.position even reference position if the transform. part isn't even and object? what is lowercase transform even referencing?
when it says transform, it doesn't seem to be referencing an object of the transform class
What? That's literally exactly what it does
transform is a variable of type Transform
sorry im a beginner here, are objects named with camelCase
im stupid, i thought they were named with PascalCase when created
Variables would start with a lower case letter. Classes start with a capital
in typical c# standards, public properties should be PascalCase, however unity decided they would rather use camelCase for that. types should always be PascalCase
how does the Player class access this transform object if its not instantiated in the Player class? Where's it coming from? when I look at the definition, it says its coming from the Component class, but how is Player related to Component, i don't see any inheritance there
MonoBehaviour
MonoBehaviour is a Component
and Player is a MonoBehaviour
UnityEngine.Object > Component > Behaviour > MonoBehaviour
heroes, all of you
im trying to follow this guide to get my unity tests working with github actions but im doing something wrong and i dont know what
im not really sure this counts as a code question, but workflow_dispatch is not supposed to be an object
use on: workflow_dispatch, one line
Does anyone know how í could make a particle System work in an UI Canvas ("Screen Space Overlay").
I have these zones and want them to glow... also an "ember" like effect from the sides...
you'd probably just render them on a different camera and then put the render texture into the canvas. i dont think you can make particle systems work directly on a canvas
Oh jesus... I Dont know how do that at all (combining cameras) :/
make a new camera. make sure its only rendering the PS's layer. make a new render texture. put the render texture onto the cameras output. put the render texture into a raw image on the canvas
could just make it an image and animte it
if u dont u'll probably need to do extra camera work render/texture.. or use a screen-space shader
Render/erFeature if URP
I kinda wanna flow them over the whole screen... im not entirely sure, but in my head thats more work^^*
slap a particle system in front of the camera and fine-tune it til it works
PS's layer. what does that mean?^^*
ParticleSystem
ah, thanks
On this Unity tutorial we are going to see how to apply effects to the entire screen! Quite useful technique to create a low-life warning for example, or any other status effect (on fire, frozen, shielded, etc).
Hope you guys like it, enjoy!
Download the Blit Render Feature Script: https://github.com/Cyanilux/URP_BlitRenderFeature
00:00 Intr...
this is cool 🙂
from what i remember i think ShaderGraph works in all pipelines now.. id need to confirm that
nope.. nvm says it can but its limited when used in the regular built-in renderer
okay i really cant figure this out https://game.ci/docs/github/test-runner
Running your test suite in an automated workflow helps increase certainty when merging.
i dont get what path/to/your/project is supposed to be
everytime i clicked "attach to Unity" in Visual Studio, this pops up in unity and i just click "cancel" each time and it lets me keep using unity and run my code. can i just click "enable debugging for all projects" so this doesnt pop up anymore or would that be bad some how?
that's not really something people here would be able to help with. but scrolling down on that page reveals they have a discord you can probably ask for help on
ah okay
i thoguht cuz its a unity thing
if you want to actually attach visual studio to unity for debugging then you will need to enable debugging.
for some reason sometimes simply saving my code with CTRL+S doesnt implement the new changes over to unity in real time like its supposed to, but ive found when i click this, it always implements it in real time. is this different than clicking CTRL+S? (other than simply saving my code)
So i can't figure out why is item in my game going to coords 0 0 0 and not to the point where i would like it to be, also it doesn't follow the players movement only the rotation
here's the code:
item.transform.SetParent(centre.transform, false);
item.transform.localScale = new Vector3(7f, 7f, 7f);
heldItem = item;
Debug.Log("item picked up!");
.
i also tried to add this in update but it also doesn't work:
heldItem.transform.position = centre.transform.position;
Debug.Log("pos updated");
.
pls help 🙏
could it that the item has no rigidbody?
i mean yes, it is different than saving because it does more than just save the code, it attaches the debugger to debug play mode. but if you find that simply saving the code and tabbing into unity is not causing it to compile changes then make sure you didn't do something silly like disable the auto refresh for assets, or that some asset (like a Hot Reload asset) isn't fucking with compilation
Is it going to world 0,0,0 or local 0,0,0? Because from the looks of things, local 0,0,0 is exactly what you would expect from being set to the same position as its parent
world
And what is the position of centre?
whats the most simplier and efficient way to display sound?
Doesn't look like anything's a child of the center object
like, an easy way to make an object emit a sound
what does it mean to "display sound"
play it
use an audiosource
the sword is suposed to become the child of centre
thanks :3
next time you should google it, because that would surely be the first result
Show a screenshot of the hierarchy after that object spawns, and show what the Transforms are of each
Which object is the first transform? Which one is the second?
1st is centre 2nd is the sword
So, from the looks of it, the sword is at the position of centre
there's some rounding errors because of the scale, but that object is at its parent's position
ok
If that's at world 0,0,0, then so is centrum and you'll need to find out why that is there
ok, how i can make that my enemies (in my 2d game) get pushed to the other side of the damage? like a proyectile or a meele
i checked and centrum is at the wrong pos, thanks for help!
i found the problem, it got repositioned after scaling the sword. again thanku very much for help! @polar acorn
Hi all, could I ask for help with a problem? I have a Gameobject that I want to prefab. The Gameobject has a script called AbilitySystem which as an array of Abilities . Ability is an abstract class wth concrete subclasses like RangeAttack etc. If I populate the array on my gameobject, make a prefab and then instantiate the prefab the array on the new object is empty. Do I have do serialize something more here? Thank you
did you assign prefabs to the array? because if they were scene objects then naturally they would have been removed on the prefab because assets like prefabs cannot reference scene objects
oh, yes they were scene objects. Will try again with prefabs. Thank you so much for the link and the advice
note that the link that was provided would not be useful if you are referencing monobehaviours
nvm the link lol i misunderstood your q
btw might want to check ScriptableObjects though
yeah, I will check that option as well. Thanks to both of you
short update: Prefabs worked:)
Im doing a car sim and the car needs a mass. Do I have to just select some arbitruary value or is there a way to use a realistic mass for the car
so i can take the gameobject itself and maybe utilize density of its volume to find its mass.
iirc the Mass is in kg
sounds more like a #⚛️┃physics question than a programming question
when I use wheel collider is not uncommon to use about 3000 to 4000 mass on main rigidbody , which makes sense for a vehicle
yeah but like I was curious if there was a way it devised mass using denisty and volume or smth
if its js picking something ill prolly do 1.5k seems fair for a regular car
ok ty
What does it mean transform.transformpoint is affected by scale?
A local position of 1 is 2 units away from you in world space if your scale is 2
For example
so the larger the scale, the greater the world distance for any given local distance?
thats kinda strange
so, how could i make it so the distance is consistent?
M = D * V? Is this what your are looking for?
yes but i dont have the volume or density
at least i dont think
as in the volume in space a collider takes up?
Not strange. Just think about it. Imagine a ruler at 1:1:1 scale. The centimeter mark is exactly 1 centimeter away from the start of the ruler.
Now scale it up to double size. The centimeter mark is now 2 centimeters from the start of the ruler
What do you mean by keep it consistent
Yes you can set the density and it will automatically set the mass based on the volume
oh 2d lol oops
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class CombatUI : MonoBehaviour
{
public GameObject enemyUIPrefab;
public Camera mainCamera;
public Canvas canvas;
private Dictionary<GameObject, RectTransform> enemyUIMap = new Dictionary<GameObject, RectTransform>();
void Update()
{
GameObject[] allEnemies = GameObject.FindGameObjectsWithTag("Player");
foreach (GameObject enemy in allEnemies)
{
if (enemy == gameObject) continue;
if (!enemyUIMap.ContainsKey(enemy))
{
GameObject uiElementPrefab = Instantiate(enemyUIPrefab, canvas.transform);
Debug.Log($"Instantiated UI for {enemy.name}");
enemyUIMap[enemy] = uiElementPrefab.GetComponent<RectTransform>();
}
RectTransform enemyUI = enemyUIMap[enemy];
Vector3 screenPos = mainCamera.WorldToScreenPoint(enemy.transform.position);
if (screenPos.z > 0)
{
enemyUI.gameObject.SetActive(true);
enemyUI.position = screenPos;
Debug.Log("updated ui position");
}
else
{
enemyUI.gameObject.SetActive(false);
Debug.Log("UI is hidden");
}
}
List<GameObject> enemiesToRemove = new List<GameObject>();
foreach (var entry in enemyUIMap)
{
if (entry.Key == null)
{
enemiesToRemove.Add(entry.Key);
}
}
foreach (GameObject enemy in enemiesToRemove)
{
Destroy(enemyUIMap[enemy].gameObject);
enemyUIMap.Remove(enemy);
}
}
}
Above here, i have a script to display a crosshair over other players. However, when the players are too far away, it doesnt work?
Can you be more specific about "it doesn't work"? In what way does it not work
when the other players are too far away the ui disappears
so what debugging steps have you taken?
ive tried debug.log in the if else statements for toggling the ui but somehow both are being executed?
well presumably there's more than one enemy
yes
Possible you have multiple copies of this script?
Also maybe you have more than one copy of this script as well
So you should log more infomration
such as:
- which enemy
- which object this script is on
oh yeah forgot about that
it is tracking the right enemy, just when the position of that enemy goes too far the ui disappears
the rect transform of the crosshair also seems to be right
it is enabled as well
it just doesn't show when the other player is too far. However, if they move closer, it appears again
at what distance is that happening?
and have you tried setting the z of the returned vector to 0?
WorldToScreenPoint uses the distance from the camera as the z coord it returns
it most likely doesn't make much sense for setting the UI, and it might be putting it out of the renderer's bounds
hey friendz, does anyone know of resources of how I'd implement "customer AI" for a coffee shop simulator game?
..that depends on so many different things
I figured 🫠
AI in generally something you do once you have some type of system in place already
I know it's an extraordinarily vague question but I have 0 idea where I'd begin
Make the system work first without the concept of AI . Eg do transactions manually via UI buttons and such
The first step is designing it conceptually. Write down how you'd like the customers to work. What you'd like them to do. How they should behave
e.g.
- first they arrive at the store and queue up at the counter
- once it's their turn, they randomly pick a set of items to order
- They wait for the player to fulfill the order
- when the order is fullfilled they pay and leave
something like that
come up with a system
when you have designed a system you can think about implementation
The implementation of these things can also vary, a ton. An AI could be as simple as a bunch of if statements, or using a state machine, or GOAP (which is a big setup)
worked on something like this for a sim, I can share some of the line que stuff if you'd like
ill try this
I appreciate all the answers – @rich adder that would be supremely appreciated
gotcha. one sec I'll pull it up. ofc there are millions of ways to do too
you will want look into behaviour trees, just a state machine will probably not be enough (or cumbersome) depending on how serious your game is.
behaviour trees def overkill
i know it's kinda been mentioned before but also keep in mind that you are asking this to a room of programmers. depending on your game and what it actually needs you could end up needing something that's like 95% less complex than anything someone here is gonna offer (doesn't make those options any less valid ofc)
I guess with new behavior tool unity has might be easier to do actually
dude, a behaviour tree is like the simplest thing ever, it doesn't have to have a visual editor
ya for some its just easier to do with an actual UI tool too
i wouldn't call a behaviour tree "the simplest thing ever" considering the average post made in this channel, no offense to anyone
GameObject[] allEnemies = GameObject.FindGameObjectsWithTag("Player"); 
What about it?
When your thinking about it, what aspect of it comes to mind that worries you?
there are many players its multiplayer
thank you so much, that worked
primarily "balance" – but this may just be me overcomplicating it in my head such that I give up early
so basically the yellow dots are points
public class QueuePositions
{
public AI_Brain Queuer;
public Transform Position;
public bool Occupied;
so its just a list you can keep track and move the line with the Next on the array.
I am trying to use Vector3.Dot to detect when the hand of this clock hand thingy gets to the 45 degree position. I can do it for the 12/6 oclock positions using transform.up and -transform.up, but having trouble with in between positions. How would you get a 1:30p vector, for example, originating from the center of the clock? (It's a 3D object but just rotating around one axis)
Maybe find an angle instead of dot product.
Hey. Trying to find how to add others to my Unity Project. Can anyone help?
oh i see what ur saying. that makes sense
well, in the suspension im designing, I have the max height for the top of the tire (where the x is). and that is basically the chassis + a little offset. and wherever the car is , I always want that offset to be the same relative to the car. so i thought to do transform.TransformPoint(car.localposition + transform.up * maxWheelHeight) to get that position, but because of scaling it isnt actually where its supposed to be.
perfect ty
for some reason, the part of the code with the "roll()" function triggers multiple times after Z is pressed despite the fact that "rolling" is never set back to false (in any part of the code)
{
if (running)
{
if (!rolling && activated)
{
rolling = true;
crank.SetTrigger("Crank");
roll();
}
else
{
if (Input.GetKeyUp(KeyCode.Z))
{
activated = true;
}
}
}
}```
why is this happening?
how have you confirmed any of that
the crank thing is an animator so it tries to trigger the animation in quick succession and results in errors
however the animation still plays once before the error
so that part of the code is triggering multiple times
i think
not even a log to check it prints twice?
you very likely have more than one copy of that component in the scene, because if that crank.SetTrigger line is the one throwing the NRE then it cannot possibly be properly setting the trigger
so the only explanation is another copy where crank is not assigned
yea thanks for some reason there were various copies of that script in elements that were not meant to have them (idk how they got there 🤷♂️ i probably hovered over them by accident or smth) and deleting them fixed the issue
thanks 👍
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Having issues with applying ice physics in my platformer. It's like my player doesn't slide at all even when the function for it is called
you're gonna need to provide more information because you can't just drop nearly 1000 lines of no syntax highlighted, barely formatted, code and expect anyone to want to dig through it to figure out what's wrong with it
That,s the part that baffles me. In it, I call a ApplyIcePhysics function to when I'm on tilemaps tagged ice on the ground layer. The catch is that maybe my calculations for slowing down and gaining speed on ice are wrong, and so it's like my function doesn't even exist even when the log clearly says it does, feeding me the variables.
you gotta use a proper pasting site, for starters
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
thanks!
A tool for sharing your source code with the world!
Here is the code for my player. I wonder if my other methods are part of the issue
trying to make an ammo UI thing
so i just made an image w 10 bullets in a row
and dragged it into an image so i could use fill to make the bullets in the line slowly dissapear
but its only showing one bullet
and its showing each bullet like this
i think i accidentally found out how ppl make animations in unity 2d 💀
but yeah how would i make it just show the whole imagae
- this is a code channel
- if you want it to act as one sprite, then do not set the sprite mode for the texture asset to Mulitple
o i forgor mb
which channel would i put it in normally lol
Anyone know what systems are used to make procedural and non procedural splines that my player can place down. This vid from wilnyl is kinda what im going for with the procedural side. https://x.com/wilnyl/status/1747448534935454112
can you clarify this question a bit more? i dont really understand what you mean by "what systems are used"
uh, are there any like specific unity packages required to make this possible/any main plugins that people use for creating splines or is this possible to do on my own with code if i can figure out how to?
there is a built in splines package, if you arent already aware
ooh ok, is that needed to make procedural splines similar to this? or can that be done without it?
also is that package already in my project by default or do I need to search it in the package manager and install it?
well, you can do anything from scratch as long as youre capable enough
you dont NEED this package
but it'll be a lot easier if you do use it
ok, yea im still learning lol, not too expenienced yet, but I'd like to try and learn how to do it myself if i can since it'll prob be more useful in the long run
are there any hard limitations to doing large scale procedurally generated splines on my own?
just kinda stuck a bit on which way I should go about doing certain things, cause I dont wanna get stuck behind limitations which would have to make me redo the whole system.
when messing around with the built in splines package myself, i notice that it becomes increasingly more resource heavy the more complex a spline is. im not sure if this is something that you can overcome by implementing your own custom system, but it's definitely something to be wary of, at the very least. this is not to mention the complexity of the math that goes into making splines in the first place
unless your main goal is to learn, i would recommend using an existing solution
ooh ok, thanks for the tips
ya, I really just wanna learn and get better at coding in general
eh, i would say that this lies on the side of being more math-heavy than coding. i would recommend attempting to learn general algorithms if that's what you want. splines are pretty specific
main thing I'm struggling with in code rn is that whenever I try and think of something I wanna put in and cant figure out how to do it on my own, i try and lookup a solution and once I find it I feel like there was zero chance I was gonna be able to know how to do that without looking it up
ooh alr
u have any pointers for good spline resources?
whenever i run into this problem, it's usually related to my limited knowledge on algorithms, so i would assume that's the problem you're facing too
Freya Holmer has a ton of good spline tutorials on youtube
- Freya is a unity dev too
yea probably, dont know too much about algorithms
ooh cool thanks! ill check it out
https://paste.ofcode.org/Px3c75ayqJwWdjxWdPbb5V for this code does anybody know how i could look for specific tags in the hits array in the teleport function
use a foreach loop
would i use something like this: foreach(hit in _hits)
i changed it to _for more clairty for me
yes you're on the right track
thank you
using this code to make the bullet UI show how many bullets are left in the gun
but for some reason i keep getting 0
i even checked the values of current and max ammo and got the right numberrs
so why is dividing the two making 0
are currentammo and maxammo integers?
i checked and im an idiot mb
is the best way to get the length between two positions just a^2 + b^2 = c^2
There is a Vector3.Distance function you can use
i often want to clone my projects, is there a good way to do this?=
If you're using version control, which you should, you can just re-clone the repo to a new folder.
Otherwise, if you aren't, just copying the entire project folder. 🤷♂️
thanks
i always copy the folder, and then... there is always script problems
its like the old scene and scripts are still in the memory
I duplicate the entire project, rename it, then add it to unity as its own project
(complete duplicate, no errors in one means no errors in the other)..
then i'll go into project settings/preferences and rename it there too to finalize it
delete the old .sln files n whatnot and let the IDE make a new one w/the new project name
some of em..
.sln file, what does that do?=
if they're regular assets u already have in ur project folder it should be fine..
sometimes i gotta redo a TMPro font or something but thats ez
oh okay
its the solution of ur project (the collection of all the scripts)
oh
when u re-open a script from the new project you'll get a new one generated w/ the new name
if u don't is fine too.. you'll just end up with (2) of em
i think u can do it w/ that button as well ^
actually w/ broken scripts and stuff ur problem might
be w/ the .meta files of those scripts having missing references.
or maybe things renamed.. or moved somewhere.. just guessin
these are def duplicate scripts errors
is it hard to att the project to a git-hub repo?
in fusion 360 u middle click and then it focuses around that point, what is the same command here in unity
Tuple/valueTuple vs KVP are fortunately not the same or even on par
KVP doesnt implement IComparable and IStructuralEquatable. for element wise comparison both tuple and valuetupple surely have more advantages.
Also in terms of hashcode uniqueness tupples are more superior
(hmmm.. why i keep replying old messages here?)
though they did say basically and similar
fair 👍
I used a guide to make this kick hammer recently, also anyone know a good app/program or content creator that has guides on coding C# in unity? (for complete beginners) I want to get better.
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
or, 
for a complete beginner id suggest you start with c# basics outside of unity. the microsoft learn site is pretty decent. Then the learn site linked above is good for learning unity
a lot of the content creators you'll find for unity don't show good practices, and the ones that do usually aren't making niche step by step guides in the first place.
Why Jumping not working? I wanna set jump action within inspector
[SerializeField] private string jumpButton = "<Keyboard>/space";
private InputSystem_Actions _inputSystem;
private InputAction Jump;
void Start()
{
_inputSystem = new InputSystem_Actions();
ChangeBindingButton(jumpButton, "Jump");
}
void ChangeBindingButton(string newButton, string actionToFind)
{
Jump = _inputSystem.FindAction(actionToFind);
Jump.AddBinding(newButton);
Jump.Enable();
}
as in, you can't change the binding? or you aren't jumping?
i didn't know where to put this
WHY DO MY PROJECTS START WITH ALL THIS STUFF???
that's normal
WHY
clam down crabs
but it doesn't help me learn when there's so much stuff unexplained
All (most) of it is documented online if you search
i came here from godot when i learned that the college courses i'm going for are in unity
You can check out !learn to get a headstart
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
yes
and the bot is actively responding to the command osmal used
osmal triggered the bot to link you to unity learn
Most of those packages are things you'll never need to worry about
Keep digging, thats whats learning about. Not learn to repeat what you get told in the first place. You dont understand a word of something explained? Google it, learn how to use the docs. It all is a bigger picture of your learning curve resulting in the tools you need to solve problems instead of always looking for a premade solution. 🙂
I have a simple script that spawns enemies at a number of locations randomly which is done by having an array of empty game objects and choosing a random number from 0 - array.length then selecting the specific empty game object and getting its transform.position then spawning the enemy there. The script seems to work and spawns the enemies but for some reason I get a "IndexOutOfRangeException" everytime a spawn happens even though it works fine. I can't seem to work out what's wrong?
[SerializeField] private GameObject enemy;
[SerializeField] private GameObject[] spawnPositions;
private bool startSpawn = false;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
startSpawn = true;
}
// Update is called once per frame
void Update()
{
if (startSpawn == true)
{
InvokeRepeating("SpawnEnemy", 1, 3);
startSpawn = false;
}
}
private void SpawnEnemy()
{
int randomSpawnPos = Random.Range(0, spawnPositions.Length);
Instantiate(enemy, spawnPositions[randomSpawnPos].transform.position, enemy.transform.rotation);
}
-int randomSpawnPos = Random.Range(0, spawnPositions.Length);
+int randomSpawnPos = Random.Range(0, spawnPositions.Length - 1);
Since arrays are zero indexed, the length must decrement by 1 to avoid overflowing the last index
For example, assuming your array has one entry, you effectively try to get entry index 0 or 1, meaning 1 overflows.
Its still giving me the error and now it doesnt spawn at the last location in the array
no random range int is max exclusive
Then please share your !code and additionally screenshot the error you have
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
No, it's max inclusive
i assume its differently specifically for this kind of usecase where your using a collection index
You have the script attached to two objects (or twice on one)
@last owl nevermind the previous point, decrementing does not solve your issue
is disabling the collider of a certain object before doing a raycast and then enabling it again going to work reliably? Does it have performance impact?
I can't use layers here
Woops, wrong mentioning 😄
Its weird because it works but gives me the error every time
its inconsistent but makes sense i guess
can you log the int its crying about?
i wonder how many games have slightly/not slightly off random rolls because people don't know it's exclusive and are accidently excluding their last entry
IndexOutOfRangeException: Index was outside the bounds of the array.
Game_Manager.SpawnEnemy () (at Assets/Scripts/Game_Manager.cs:29)
It just prints that every spawn
Log it before using it 😄
Then I assume it attempts to enter an empty array
And index 0 will not exist
Sorry im a beginner you're gonna have to explain what you mean by "logging it"
Debug.Log(YourIntHere);
Try changing your code to this @last owl
private void SpawnEnemy()
{
Debug.Log($"Length: {spawnPositions.Length}");
int randomSpawnPos = Random.Range(0, spawnPositions.Length);
Instantiate(enemy, spawnPositions[randomSpawnPos].transform.position, enemy.transform.rotation);
}
There's another component where you haven't put anything in the array. #💻┃code-beginner message
My bad, I think I'm not quite understanding everything that's going on here, what is it exactly that this is trying to do?
My guess is it either logs twice, or once and length is 0
yep it logs twice
well
You have the script on two components
Change the code to this:
private void SpawnEnemy()
{
Debug.Log($"Length: {spawnPositions.Length}", this);
int randomSpawnPos = Random.Range(0, spawnPositions.Length);
Instantiate(enemy, spawnPositions[randomSpawnPos].transform.position, enemy.transform.rotation);
}
Then you can click the log message and find where it is defined
Then just remove the invalid one
They both lead to the same object
Then you have it defined twice
Scroll on the component and it's there twice
Alternatively you somehow manage to empty the array and then the code calls it a second time
Oh my god I have no idea how that happened but the script was on there twice LOL
Good job team
Thanks
Now you know how to easily find stray components
I have learnt something new today
I want to run a method an x amount of seconds after i trigger it, how do i do that? i can only find stuff for repeating and i only want it to happen once after a trigger and then not untill its triggered again
Invoke?
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
I have this script that is responsible for loading my Loading_Scene first then inside starts loading the scene I pass in. When I start my game. It succesfully loads the First scene with loading screen scene. But through my game when I want to load another scene using Loader class. It gets inside the OnLoaderCallback but never starts the coroutine. So basically I cannot use the Loader.LoadScene twice through my game. It only works once.
A tool for sharing your source code with the world!
And this here is where I call LoaderCallback.
A tool for sharing your source code with the world!
And you do not get any errors?
No not at all
I thought maybe I was giving the string wrong but It is the same as my scene
Does your log get fired in the coroutine?
Yes if it succesfully fires the coroutine I see the message. But when I try using the loader class again no. Doesnt call the coroutine
Did you check your gameobject, if its created?
And it never gets destroyed I guess?
I already have it on my Loading Screen scene. Before creating it in the code too
I thought it could be related with how I flag the booleans but I cant wrap my head around
Because it wouldnt get inside the OnLoaderCallback at all if that were the case
So the onloadercallback, that you assign a method to, is called?
When does that log happen. On the first load, right?
Second too
So first is not loaded default scene and second call is the loaded scene?
So my first scene is my menu scene. When I press play I call Loader.LoadScene. It works as its expected to. Then I play my game and have to use the Loader again to load another scene.
Then it does get inside OnLoaderCallback but never unloads the other scenes or loads the next scene. I'm still on the Loading_Screen scene.
When I dont start from my Menu scene and not load. Starting straight from my playable scene. Loader class works cause im using it for the first time.
I have colliders on the island "floor". Is it possible to do something like a ReverseRaycast that will get the position where there is no more land?
rather than making an ocean collider
Where are you unloading it? I see the method but not the call
Inside the LoadSceneAsync method. At the bottom. I'm calling Unload scene. Which checks current scene and some other scene that is not present anymore. And unloads the rest
That naming is misleading 😄 But okay, found it
Yeah sorry about that.
So your code created prefab, is not created after your first scene was loaded correctly?
assuming you're raycasting from the camera, you just keep doing it until null is returned, or a different layermask
I already have a game object with the loader call back script attached to it in my Loading screen scene.
Its not a prefab
yeh, not prefab. GameObject, my bad. But you create it everytime you enter a new scene and your update is called first. And then you try to destroy it right after if its loaded (which it should I assume, as the scene got entered?)
assume the raycast will start from red, to blue
is this a 2d game?
A raycast starting inside that collider will ignore it
Well it goes away as the scene unloads
I dont see it get destroyed
you destroy it in code
Yes I do I was checking if it got destroyed in the hierarchy
I dont get why you'd create and destroy this every load
Well to be fair. I followed a video for this from Code monkey.
This is what he does I mean
I understand
Tbh it is kinda hard to read the code. Not to udnerstand, what its doing but just to follow. Like having your callback setting a loading state to false is wrong, as the callback should never dictate the actual state its waiting for for example. You should really, after understanding the code, clean it up a bit. As Carwash said, no need, to have one MB and GO created all the time, just make it a DDOL and listen for scene changes for example.
I see. Well I do not get why I keep creating and destroying a game object that already exists in the scene either. Also yeah I need to be specific with the names and such sorry. I thought it may be because it destroys the object without even starting the coroutine but yeah. Thanks for the help!
You also seem to be destroying your loading scene with your SceneManager loop, could that also be the case?
ah no, thats happening after the load. phew, yeh, its kinda ping pong in the code going on 😄
Yeah I'm also having hard time navigating. I'm really sorry about that 🙂
What is weird is that why does it work the first time.
Nah, its fine. Its all part of the learning curve 🙂
I guess, your assumption about some boolean or whatever not being correctly reset or soemthing might be the issue. But I 100% bet, rewriting to your own needs and with your own understandable structure and naming is less time consuming then trying to understand the structure the tutorial provided 😄
Yeah that I agree. I could just load my loading screen scene then load the next scene non additively but I just wanted to make this work cos I had a Init scene previously I wanted to keep.
You can of course take parts out of it. But as you said, you know, what you actually need.
I simply refused to accept the defeat but yeah. Thanks for your time I'll find a workaround!
haha, yeh I know that feeling. But you yourself already found out, that the code was not optimal, so you are able to write a better one 🙂
Well I hope so. Haha we'll see!
I was trying to add an AimCamera, turn out I can't move my camera anymore (the aim zoom style running but I can't move anymore)
update to cinemachine v3 if you can (may require removing and re installing the package)
If you are already using v2 a lot it may require some upgrade work.
I have to restart everything ?
What is a good way to truncate positions of a vector? Math.Truncate() seems to be doing funky things for me, with the top value being the Math.Truncate()'d version and the bottom being the world position of the vector
I guess I could also cast it to an integer and then back to a float..?
There's Vector3Int if you want to just use ints
Truncate them to what degree and for what purpose
Just for logging or display? Or what?
Also showing the actual code you did would help us explain why you're seeing weirdness
Use Vector3Int instead. If you cast to an int, the values under 0 will be 0 . . .
Vector3 GetClickedPos(out RaycastHit hit)
{
Vector3 target = Vector3.zero;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray.origin, ray.direction * 10, out hit))
{
if (!IsPointerOverUIObject()) target = hit.point;
}
return target;
}
why does this return a height of 0? shouldnt it be .5 the object im hitting has a transform at 0 and the box collider and scale is 1 thick
it does return the right x and z
i need to round to the nearest integer to 0, so like 21.65 to 21. -17.93 to -17. my actual vector can't be an integer though as I'm adding 0.5 to each component of the vector
I didn't show the code because I wanted a different route, rather than Math.Truncate(), if there was one available
i need negative values too
For what purpose
What are you doing with them
I'm just trying to get a vector, that's literally all I'm doing
To do what with
Sounds so far like you could be using Vector3Int
But truncate would work if used correctly
Or Round
Or Ceil
Or Floor
Depending on the requirements
Use Mathf.Floor then . . .
Or FloorToInt if you want the result to be an int . . .
Cast it to Vector3Int when you need the ints, but keep it as a float for your computational purposes
Okay, thank you.
that worked, thank you
Are you sure the Raycast is hitting this object? Are you sure it's hitting anything at all? Try logging the object you hit and see
yeah i logged it its hitting the ground gameobject which is that one
Did you log that inside or outside of the IsPointerOverUIObject check? If that's true, it won't change target from its default value of 0
But as Praetor suggested, telling us why you need to do this can help you find the appropriate solution . . .
I think you're thinking of the other guy, this one's a different question
i just put it above return target;, the target.x and target.z do get set
So that seems like it's working. That's the value you were expecting, right?
huh it just changed what
alr thanks ig
not sure what changed but if it works it works :)
why wont stick follow the player when moving despite it being a child of playerCapsule? like, what do i need to check?
more information
hi was wondering if anyone can help me here please understand why unity is saying that this private void isnt correct i am doing unitys rollaball course
You're nesting methods which you probably don't want to be doing here
what do you mean sorry
It means don't create methods/functions inside of other methods
how would i go about fixing that ?
playerCapsule has a rb
so does the stick.
nothing changes the position of the stick in the code except for this upon collision:
itemComponent.transform.localPosition = Vector2.zero;
when on ground its gravity is 1, upon collision it gets set to 0.
and this is the method that moves the player:
void OnMove(InputValue value)
{
Vector2 input = value.Get<Vector2>();
// If any horizontal key is pressed, use its sign (1 or -1), otherwise 0.
float horizontalInput = input.x != 0 ? Mathf.Sign(input.x) : 0;
moveInput = new Vector2(horizontalInput, 0f);
}
You should find yourself some tutorials to follow. Sorry, I'm not that great at throwing resources at this stuff, but you're obviously somewhat new at c# and you're just going to run into more issues until you learn it properly, and jumping right into Unity without knowing what's wrong here just going to make your life even more difficult on your path on learning.
and OnMove is in a script attached to the parent PlayerCapsule
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/, https://scriptbin.xyz/
📃 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.
Childing rigidbodies when the parent is also a rigidbody creates problems usually. I think you can probably make the child kinematic perhaps, but otherwise what you're doing isn't straight forward.
does disabling the component when in a picked-up state solve the issue? or does the component need to be removed completely
Disabling is fine, yes. If say you wanted to use the stick as a weapon with physics and a child to the player -> requires some custom logic
Yeah, if it's like an inventory thing where you're storing these objects you can probably just switch kinematic on and off
i was thinking when hitting enable and disable a collider and since enemies will have an rb, the stick attack collider wouldnt need one too?
its sort of both
If you wanted to use the stick as a weapon, stick to kinematic
but if you were to drop it on the floor and want that physics, then you can toggle it like that
ye thats what i was thinking, when picked up its kinematic, and when dropped, goes back to dynamic. but if i have a child object with a trigger collider, it would still work fine with detecting collision when the rb of the stick is kinematic, right?
Usually you use the animator too when it comes to weapon attacks anyway, but I guess you probably manage something through code
there's actually some benefit of using kinematic vs just animation, but that's a pain to really do
wokeup to see my whole project is kinda gone(?) despite it working fine last night and I saved it too when i exited. anyone had this? it asked me to enter safe mode when i opened it btw so i did, but then i closed it and reopened it and clicked ignore the second time
usually trigger colliders and kinematic go hand in hand
but remember that collision isn't handled when it's kinematic, but you will still get callbacks from the OnTrigger methods
it opened a new scene, go find your scene and open it again
not code related btw.
but remember that collision isn't handled when it's kinematic
so the trigger collider wont register anything?
Kinematic doesn't handle any sort of collision. If you added velocity like gravity to it, it'll clip through the ground unless you tell it not to
It will however notify you that "hey, I touched ground just so you know"
i think it may be? i found my scene. its saying line 61 is causing an error. this is strange because the code was working last night and is unchanged from this morning and now its causing a compilation error.
ok that works fine for me, i was thinking, the stick attack hit box would enable when the stick is used, and any enemies that touch this hitbox will perish, so it would still work for that
This is invalid so you should fix it
Usually when you do weapon attacks you have trigger colliders with animation keypoints that move the weapon. You don't actually drive the weapon by any rigidbody methods.
yea no the rigidbody was for when the weapon is in the grounded state, when its an item on the ground, and not as an item picked up by the player, so im still doing it the typical way so to speak
or so i think, its my first inventory that i make
You have an else that is not after an if
i think they got it now
thank you, i put another { after the if statement and fixed it. so weird cus it was workign last night (or atleast seemed to be, i know how crazy that sounds)
another idea too is just destroy the actual item when you pick it up and store it as data if we're talking about a UI representing the items. And, when you drag the UI element out of the inventory to drop it you would instantiate this rigidbody scene element again. But, if you're not making an infinite inventory, it's fine to just stash the monobehaviours
it cant have worked so must have not saved or you remembered wrong
most definitely
yes but there is also the pickedup state is a li lcomplex because i want the itemto be usable as well, that u can see the player holding it etc, so what i did is that once picked up, i disabled all its hitboxes, and as u now know change rb to kinematic, and parented it to the player, i do that will all items, just that the only visible one is the selected item. i assume there are more effecient ways but oh well, i also only have a hotbar in the game no full on inventory, so this works fine i think
whats a good way to make a first person camera script, i made one using lockcursor but it is very choppy and im wondering what the alternatives are
What's should i use to prevents the Chain(-Joints) from breaking, when moving with the Player (The Ball) with WASD. i tried rb.velocity and rb.AddForce. Both break the chain. (More Details in #⚛️┃physics )
im just gonna uh, steal danis first player camera script...
Why don't you configure your editor like I asked?
These questions are so easily solved if you take a few minutes to fix your editor, and it also saves us time
its all sorted now
I really doubt it
well its now working better than it was
i notice when i manipulate objects in unity "scene" section while my game is running that the chnages dont save when i stop the game from running. is there a way to make it save like that or should i avoid that for some reason
Convince me, show me a new screenshot that actually shows proper syntax support
There's not a way in general to do it, no.
you could make a way to do it for some specific use case
one cheeky way also is to copy the object or component values at runtime
and paste in edit mode
there may also be plugins for this
i dont know how it get the syntex support to work as i just opened unity again and i had to set unity up in the setting again so it will open my scripts
if you would like to help me get it all set up properly i would really appriciate that
Well the bot message explains it really well. You'd know it works because the code now properly highlights faulthy areas
yeah i followed it and its still not working
any recomendations to learn it
i mean hes gotta start somewhere, maybe he just wants to make games
look at the pinned messages, there are resources linked in there. there are also a ton of resources out there you can find on google
thank you and going by unitys website i am doing it in order by doing rollaball first then programming
i do recommend learning some c# outside of unity first, so you aren't trying to learn 2 things at once. the microsoft learn site is also pinned (intro to c#)
i will take a look at it i take it thats more bases on just programming and syntex rather than doing it in unity and trying to learn adn make something do something at the same time
if i delete an object in unity like a cube or something, does it go to a "trash" where i can undelete it? or delete it forever?
Undo history
https://docs.unity3d.com/Manual/UndoWindow.html
You could Ctrl+Z it as long as you haven't closed the program
Or done enough stuff that it's out of the undo buffer
yes, imo it'll be a lot easier once you understand how stuff like classes/instances work. at that point im assuming most guides would have covered functions, arrays, loops which is a good enough foundation to at least start in unity. I can't imagine learning unity and also getting stuck with every line of code
yeah definitely i am just following the instruction just now but knowing some stuff before would probably help but i only get a little bit of time on the computer as i have a new born so not a great deal of time to do anything.
this video isn't enough to help with anything
idk ? how about more details on the setup and things like the code.. people shouldnt have to play detective , you should provide everything someone needs to understand the setup
It's because they're using Gorilla Tag's open source locomotion which is raycast based and doesn't account for moving objects
It's something they have to account for themselves
I guess. I have no idea how you deduced that from that video alone
You learn to spot that kind of stuff when the communities you're in are full of people who make low quality monkey games
Retrace your steps then
Did you install the editor through Unity or manually?
yeah im having issues learning becasue half the words that are and arent syntax that is said on overflow sounds like wizardry, is there any like post somewhere that just explains a lot of coding terms because i cant understand a word of what is said
makes sense. would've been useful if they started at least to open with that in the question lol.
i guess they deleted and left idk wasnt that important I suppose
You're not going to learn from reading a "dictionary" of terms. Maybe share something you're confused about and we can help you break it down word by word
the only thing that can really dumb it down enough for me is AI and people dont recommend you to use AI since its really bad
AI can be helpful for understanding terms. As can asking people about those you are confused about
Yeah. Really irritating how instead of innovating people just download that loco and plaster their game on the Meta Store. EVERY new game is a Gorilla Tag clone on the Meta Store
its mainly bad cause you wont know how to distinguish genuine true answer to a plausible sounding hallucination
Because it's so easy to make these they tend to have no understanding of stuff and so they forget to include context
its stuff like quaternion, like i have genuinley no idea what quaternion could mean.l it sounds like my phones CPU
or slerp
Sorry if I'm coming off as harsh you can only see so many of those kinds of games before it drives you up the wall
damp
thats a good thing In a way I guess 🙂 tells me there is a market for more VR no ?
people so hungry for vr they keep playing the same Gorilla tag fangames lol
quaternion is just a data type that holds a rotation. That's all you really need to know
i kinda understand damp but also not in half the scenarios
Honestly if I see someone with a gorilla profile picture I don't answer their questions because I know it's someone who has no idea how anything works and zero desire to learn as much
thank you
In what context? The normal context is damping on a Rigidbody, which is just a factor by which the body slows time over time as if by air resistance or something
"Damping" is a term for just generally "Making something smaller and smaller over time"
it can also be used in the context of smoothing things out
like for cinemachine cameras
It's not really a programming term, it's just a word
i mean like, i know that it stands for dampen but like in what scenarios, dampen down what
depends on the context.
We jus shared some examples
but like damp time, you cant smooth out time?? or can you idk im not the professional here
As I said, that's just a normal english word. That's not a programming concept. It's just part of a sentence
Could be "Time it takes to damp" rather than dampening time itself
You can also adjust the damp time to change how smooth your transition is. This function will also automatically account for player movement mid-lerp.
like this, this comes from a stack overflow post
A stack overflow post about what? Cinemachine?
A specific function?
You need to pay attention to the context
we have no idea what you're talking about
SmoothDamp?
yeah it was just an example on where i found it and why i brought it up. maybe a bad communication on my part
You'd have to show the actual post. They're presumably talking about somes specific function or something. We can have no way of knowing from a vague description.
just in general on how in the hell im supposed to know what all of these "random" words are everywhere in stack overflow
what random words
Manually Microsoft Visual Studio
sorry i didnt mean to send it as a kind of "solve my problem" but more of an example on where and why i used damp time as an example
next time you find a "random word" you don't understand about a Unity concept, show us the post or whatever and we can help.
thanks ill get back to work now
Usually, google
Or just, like, context clues.
Like how you'd learn any new words
Why is my trigger not working? Parent: Rigidbody2D, Collider2D (ex. Rope-Layer, so that it doesn't stick to itself all the time) Child: Colider2D set to Trigger With Script ```cs
public class ropeTrigger : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D other) {
if (other.gameObject.layer == 6) {
Debug.Log("Collision mit Rope");
} else {
Debug.Log("Collision");
}
}
}
Check you have the Unity workload installed
Check VS is the default Unity editor
When neither is the issue, regenerate propject files
triggers would use OnTriggerEnter2D
omg
what does Mathf, ref and just in f in variables mean
thanks hahah
float
oh
2f is two as a float
Mathf is math for floats
ref means to pass the parameter into the function as a reference instead of copying it
You should probably use NameToLayer instead of just a magic 6 there so you can more easily tell which layer you're checking:
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/LayerMask.NameToLayer.html
Addendum: Chances are if you don't know what this means, you probably shouldn't be using ref yet
I have a ledge grab system and the issue is that I want the character to end up at the end of the climb up animation but I would have to have "Apply root motion" enabled but that would break everything else. Anyone know a solution?
If I do:
void Test() {
int x = 5;
Change(x);
print(x); // this will print 5
}
void Change(int num) {
num = 10;
}```
it will print 5.
But if you do:
```cs
void Test() {
int x = 5;
Change(ref x);
print(x); // this will print 10
}
void Change(ref int num) {
num = 10;
}```
It will print 10, because since it's a reference we can change the variable from the caller.
It's a bit of a hack, but you could use AnimationEvents to enable root motion at the start of that animation, and disable it when done?
teleport the character at the end of the animation, or only apply root motion during the animation, or put the visuals on a child object instead of the root
Could you PM me instructions on how to cheek this is installed and how to install it
Are animation events asynchronous?
!ide has a guide on how to do so
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
in what sense?
im actually going insane, does this happen becasue of my bad scripting and or it being not synced with my player movement. ill send the scripts too
upload the video as mp4
so discord can embed
I linked it twice
Check the bot command above
discord doesn't embed mkv, convert it to mp4 online
If I can listen for an end event asynchronously that runs a function to disable root motion when the animation stops
and could you be more specific as to what issue you're having
OBS can convert it
instead of checking it every frame in update()
there's a menu option
i think my discord died for a sec there, sorry
It’s more so because I am out and to have it easy to hand for when I get on my computer again
not sure about the phrase "asynchronously" here but it will call your function at the exact right moment
Well, you have that link
you can look at it when you actually intend to follow it
forward or copy link the bot message somewhere
Okay I think it is what I mean, do you know a docs page I can look for animation events?
Hello, can someone help me with something about camera rotation and change directions? Like, when I rotate my camera, the player direction chage, like if I'm stiff facing noth and walking to the north and I rotate my camera, my player still walking forward (I don't know if it is understanding)
Is there no events for animation ends/stop or do I need to make the logic myself?
I just start learning Unity btw
it's due to your code but not this code
it's whatever code you're using to rotate your player
Also potentially because you haven't enabled interpolation on your player Rigidbody
(if you haven't)
Oh yeah sorry it's this:
playerBody.Rotate(Vector3.up * mouseX);```
You can't rotate a Rigidbody via the Transform
unless you want it to be jitter city
instead do:
myRigidbody.rotation *= Quaternion.Euler(0, mouseX, 0);```
you are a godsend, i hope you win the god damn lottery, thank you 🙏
i watched a video about yandere devs code and it said i should not initialize a module more than once if not necessary right? what do i do instead of that
What do we mean by initializing modules in this context?
What "module" are you initializing right now and when and where are you doing it?
i realize now that it probably isnt the issue but just in general, oh yeah its GetComponent<componentname>(); not initialize component
too much python in my brain
Can anyone explain what component makes this pill hitbox? I need to disable collision temporarily
capsule collider from Character Controller
CharacterController
Is there a property to disable its collisions?
Disable it
what do you mean exsactly though
like other things colliding with it
or it colliding with things when it tries to move?
Yeah when i climb the ledge of a cliff the hitbox is pushing against the terrain
so what do you want to do instead?
you can like Nudge it up or down depending where you want it to go
you mean in an animation or something?
Yes I will show a video clip one moment
Seems to be pushing against the terrain, not sure how else to do this other than to disable collision temporarily
yes disable it during the animation
but no the CC will not "push against" terrain really unless it's moving via Move()
Well I tried but it doesn't disable it. I put
GetComponent<CharacterController>().detectCollisions = false;
Inside Start() and the character should fall through the map, no?
why not just GetComponent<CharacterController>().isEnabled = false
This method does not affect collisions detected during the character controller's movement but rather decides whether an incoming collider will be blocked by the controller's collider. For example, a box collider in the Scene will block the movement of the controller, but the box may still fall through the controller if detectCollisions is false. This property is useful to disable the character controller temporarily. For example, you might want to mount a character into a car and disable collision detection until it exits the car again.
disable it
im confused why its not working then so Id say just disable it lol
GetComponent<CharacterController>().enabled = false; is how you disable it @surreal minnow
Well the issue with that is:
if(cc.enabled == false) return; cc.Move()
But that would disable air strafing, wouldn't it?
of course.
are you supposed to be able to air strafe while doing the climb animation?
No but Id imagine in the future I would want to be able to move left or right while grabbing the ledge
you could always use raycasts so when you move left and right you dont phase through walls while collider is disabled
like everything in development comes with its own compromises for each solution, either have a solid controller and manually deal with offsetting it.. Or disable it but that causes youto not bump into colliders at all which will make you phase through them unless you use a prevention like stopping movement with ray detection
Seems like you might simply not want to use the CharacterController
It really is only meant for incredibly simple movement and it sounds like you want something more granular
You are probably right about that^
CC is still very much easy to use for collision detection and steps / slopes
something you'd have to manually code when on ground
even RB makes this annoying as hell in comparison
Hello everyone everytime i install unity it's stuck at this
this is a code channel
also wait a while
oh
Well I have to switch from it if I am not able to do something as trivial as disabling its collisions
who said you cant disable collisions..
But it disables the whole component, not just collisions
I guess I can try making the collision box size 0 and see if it works
You dont need CC to move an object
CC just makes so when you do move an object its with Physics aka collisions
As I mentioned when you switch to disabled you can freely move the object without CC
you just need to account for collisions yourself on edge for example
hence the suggested Raycasting for such detections.
if(leftSideRaycast) // if hit a wall
{dont move this way} etc.
Yeah I know. You are right and that it is a possible way. I am just debating if there are any future cases where it could screw me over
Is setting a collider to be a trigger the only way to detect if it collides with something without interacting with physics?
That's basically the definition of a trigger
yeah it's not really a big problem for me, I just have a swtich-case statement in my "oncollisionenter" method and I just wanted to see if I could sneak the pickup in there
but I guess I will just have to settle for putting it in ontriggerenter
its still physics.. just not solid collisions
or use neither and go for physics queries
Worked great tho thanks👍
yes my first code in C++ works!!!
Unity uses C#
this would not work in Unity as is 😛
maybe interop.. but thats beyond #💻┃code-beginner
you might want to use the language unity api supports.. c#
How do you determine the position of the body/hands? Fixed offsets from the ledge above or is that somewhat dynamic?
It's fixed offsets yeah
Then i will learn C#
maybe reinstall unity hub
Hello,
I don't understand why my UI is in 3D 
-# Help me pleasee
Seems like a normal canvas
I dont know how to make it as a normal UI like in 2D
I have it always
I tried 5 Times reinstalling hub
but how do you make it in 2D ?
It'll look normal in the game. Open the game tab if you want to see it how it looks like in the game
It is
but normally it's supposed to be in 2D in the editor mod?
no it's not
it is
only if you're using the 2d view
oh sorry
It appears to be
I thought there was a problem
Your screenshot looks like 2D to me
Is there a way to tell if a component is missing?
from what context?
Like players have X script as target, but it was destroyed and it's now missing, that's not really null, how can I tell that it's misssing?
it'll say it's missing in the inspector
Yeah, I want to tell the scrip that if that happens, set it to null instead
what's stopping you from just checking if the class reference exists or not?
Exists?
use an == null check
they're looking for an editor script, guys
yeah would == null not override?
Daleo you need an editor script for sure. I'm not sure the exact code atm (no time, sry)
Pretty sure "missing" is not = "null"
most likely youre starting the coroutine more than once
I will look into this thanks
You can use a bool to avoid start a new one unless bool is true, or store the Coroutine in vairable and set to Null when coroutine is done.
Most often I use variable
private Coroutine myRoutine
myRoutine = StartCoroutine(TheRoutine())
if(myRoutine != null) //stuff
StopCoroutine(myRoutine) or avoid StartCoroutine while its finishing
Maybe try to look for installation folders of the different Unity editors and delete them
this is a code channel, use correct channel here
#💻┃unity-talk message
What’s the expected behaviour (vid)?
Already fixed thanks tho! the problem was in the build version there was just weird bugs but in unity the bugs that I was seeing in the build version were non existent in unity.
Nice, but.. That’s strange.. how did you fix it? Just curious.
whenever i try to build my project i get these errors
it works fine when i just run it in the editor
just physics issue's like I wasn't setting iskinematic properly floating issues physics update issues etc
You cannot use anything from the UnityEditor namespace in a build
How am I meant to alter the color of a sprite through code?
Can't figure out what is meant to be targeted in order to change the color of a sprite
.color
so then how do i add a prefab to the scene without dragging it, cuz im not dragging 200 prefabs
And what am I meant to feed that?
I tried giving it an RGB and a HEX value and it didn't work
i need to do it based on name
a Color
not sure if there is an alternative
If it's meant to happen at runtime in a build, you can't
bruh so im meant to drag 200+ things?
that cant be rigth
Does it need to be done at runtime
wdym
While the game is running
well ye
How do you intend to make a playable game if you have to drag in references while it's running 🤔
no
you dont drag them while playing
sorry misunderstanding
the dragging isnt at runtime
the usage of the prefabs IS at runtime
what no its not
ok
you dont have to drag references while its running
but i need to get a prefab based on a name
Right, so you don't need to include it
for loading/saving purposes
Put it in an Editor folder or exclude it from your assembly definitions if you have them
Thanks for the help, Finally fixed even made some further improvements by adding some cooldowns.
Checkpoint System ✔
Build Version bugs FIXED! ✔
What’s the original question?
this is the original post
im trying to use Resources.Load now
Why not just exclude your editor script like I suggested?
its not an editor script
its a runtime script
i think you misunderstood what i meant
i have a save, that stores a prefab id, i want to create a new instance of a prefab based on the id
so the id is the name of the prefab
rn i use the AssetDatabase to get the prefab dynamically to instantiate it
If it can be circumvented by dragging in a bunch of prefabs outside of runtime, it almost certainly can be an editor script
i dont get what an editor script would do
i have no idea how i would make that
cant i just do this dynamically?
why does it have to be hardcoded 💀
How are you currently doing it
var guid = AssetDatabase.FindAssets(prop.prefabId.Replace("(Clone)", ""), new[] {"Assets/Prefabs"}).FirstOrDefault();
and then i
var propObject = Instantiate(AssetDatabase.LoadAssetAtPath<GameObject>(AssetDatabase.GUIDToAssetPath(guid)), new Vector3(prop.posX, prop.posY, 100), quaternion.Euler(0, 0, prop.rotation));
So, you know how to load a prefab by name.
You can set variables of scene objects outside of play mode using an editor script
im not entirely sure what you mean sorry
what i would do is like, create a dictionary with strings as keys and gameobjects as values
but idk how i would fill it
Am I doing something wrong?
I've made sure everything that could be wrong is right but I still can't get the sprite to change colour
So, you say you could circumvent needing this script by dragging in 200+ prefabs right?
dictionaries dont even work well with unity
Color uses floats between 0-1. If you want to use 0-255, use Color32
yes doing this and then dragging 200+ prefabs. I would have to use 2 lists which is eew but ye
Ohhhhh thank you sm <3333
So, you write a script that would assign those variables for you using the AssetDatabase
so it automates dragging in
you can do that?
Yes, like I said, an editor script can set variables on objects in the scene
does that mean i can use a dictionary instead of 2 lists?
cuz normally a dictoinary doesnt work with dragging
If it's not serializable in the inspector, it won't be saved with the scene, so you could set it, but it would be lost next recompile
You could make a serializable extension of a Dictionary that'd get saved, but the built-in C# dictionary is not
ok im not doing that
i still hate that its not serializable
a dictionary is so basic
is there any docs?
i cant rly find it when searching for editor scripting
dictionary can be quite complex
since you can use anything as a key
For serializing a dictionary or making the editor script?
editorscript
like for how to assing the variables
and for where to put the script and stuff
Easiest way would be slapping a MenuItem attribute on a static function of something in an Editor folder.
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/MenuItem.html
Then you can use FindObjectsOfType to scrape the scene for what you need, and set the variables to those prefabs
Then you'd execute the function by selecting it from the top bar
A full-on GUI is overkill for this
its fine for now(IMGUI) but yeah just kinda dropped that without contex mb
I think nav just came in late and assumed it was a bit more involved than setting a few variables
ah
but yeah for future reference, Unity DOES want you to merge everything into UIToolkit eventually but thats another topic 😅
nothing wrong with IMGUI if you ever need some quick editor magic
the menu itme thing is to create new stuff?
i want to add stuff tho
what is "stuff"
oh wait i use FindObjectsOfType
what do you want to add
sure if you want to
its grabs them into an array
in editor those functions have no impact on gameplay anyway
(in game ofc u dont want to run that in update)
where is taht in
oh this should still be a monobehaviour?
uh it does say deprecated
FindObjectsOfType is a static function
ah by type ofc
yeah it should tell you which one to use instead
unity switched up some functions in unity 6
i want the sorting order to be from top to bottom tho but thats not an option
im not sure how they are sorted in the editor
alphabetically
well its the only one of that type
so if i can do something similar to FindObjectsByType but for in teh scene
oh its part of the scene already or you want to spawn it ?
Im confused on what you're going for I kinda just butted in at the end 😅
i want to link a prefab in assets, to a script variable in the scene
or well i want to link 200+ prefabs
and you cannot use SerializeField why ?
i dont want to drag 200+ prefabs
i was told i can get unity to put them in for me with an editor script
so i dont have to drag
ohh so you wanted a function to run in editor to do that/
editor part is not important, its more important is how you want to grab/distinguish between these
eg if all Furniture had a Furniture component its a lot easier
I get that
ONLY the prefabs have that script
but whats on the prefabs
Prop script
so then FindObjectsOfType<Prop>()
ye i have that part down
but how do i get the object in the scene and how do i put it in the variable of said object
place them in categories so they are easy to grab
say you want to place all barrels you could store them in List<Prop>barrells
perhaps here it would be okay to check their name
yes thats what i want to do but how do i store them
i have a List<gameobject> and a List<string>
the strings will be names
its basically key value
why two lists
ofc
you just cant see it in the inspector
there is a premade serializeddictionary package