#๐ปโcode-beginner
1 messages ยท Page 407 of 1
Easy solution to camera avoidance, stencil buffer to keyhole the player no matter what's in the way. Like NWN:EE does it
e.g.
not "easy" but a fun one
ohh booo ur tricking us
I just said NWN:EE here! D:
i can barely read sorry ๐
S'all good, wish I was that clean with my stencils ๐
i see picture and go "whoo.. picture.."
whats ur project running? URP?
Yeah, I was gonna go HDRP but didn't really need most of the extra features. So I stuck with URP and added overrides for specific things like decals/VFX graph etc.
Though the initial stage of the project was a pain because uhh, I went URP->HDRP->URP
Had to convert all my assets twice
next time: branch it
i barely been giving my production progress any attention
took me a long time to get a menu and save system working..
now im thinking my list of scene indices is a bad choice.. since now i need a cutscene to stick in place of element 1
and soooo all the others would need dropped down a spot
thats gonna be bad to work w/
HDRP to me feels like a little extra for alot more pain..
unless u specifically need something from HDRP like volumetrics
I really wanted volumetrics, but the lack of support for a lot of existing unity tooling (E.g. terrain tools being severely messed up) was enough for me to scrap volumetrics and instead rely on screenspace fog.
use third party volumetrics
I couuuuuuuuuuuld, it's not a bad idea.
hmmm i'll look around
I've seen really good URP volumetric solutions
i been working on my lighting and skyboxes
But they've usually been OTT for my purposes
i tend to tint my fog to match the very bottom of the skybox (horizon)
loooks good.. but also looks "samey"
most are paid unfornuately
Love the style
but im down w/ that.. i bought my character controller.. i see it as an investment for systems that are heavily relied on
thanks.. im trying to go low poly.. but stylized
havent decided how to texture just yet
i wrote this soo long ago.. im lost
commentless
why tf am i passing in a scene and not using it ๐ค
ohh nvm thats a unity function
public int[] GetSceneIndex = new int[12]
{ 2,3,4,5,6,7,8,9,10,11,12,13 };
public int GetSceneIndexFromChapter(int chapter)
{
if(chapter >= 0 && chapter < GetSceneIndex.Length)
{
return GetSceneIndex[chapter];
}
else
{
Dbug.Error("Chapter can't be converted to scene");
LOAD.ShowErrorScreen();
return -1;
}
}```
gross lol
i musta been high when i wrote this.. ๐ซฃ
honestly dont know how to fix it...
welp, ignore me.. i was rambling.. i have to take a minute to figure out how i wrote this.. and the flow it takes
https://www.spawncampgames.com/paste/?serve=code_202 if anyone's interested <-- My GameManager.. its a big chunk of nonsense lol
is this still beginner #๐ปโcode-beginner message territory?
What happened? Is smth not working? This does look like old code, haha . . .
Hey guys, I'm making a cookie clicker like system where a building generates a bps (butter per second) and adds it to a stack in the game manager with the other buildings, and the game manager uses that total bps to generate butter per second.
In my Game Manager, I have this code:
get { return baseBpsStack; }
set { BaseBpsStack = value; RefreshBaseBps(); }
}
public float BaseBps{
get { return baseBps; }
set { baseBps = value; }
}
public float score;
public List<float> baseBpsStack;
And I have a script called SpawnButterOverTime which is attached to every building that spawns in butter. Every building also has a building script.
Here is the building script:
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Building : MonoBehaviour
{
public ShopItem itemData;
public GameObject itemIcon;
public GameObject itemNameText;
public GameObject itemCostText;
public GameObject itemAmountText;
[HideInInspector] public string name;
[HideInInspector] public float cost;
public int amount {
get { return Amount; }
set {
Amount = value;
if(itemData.bps > 0){
GetComponent<SpawnButterOverTime>().CalculateBps();
}
}
}
public int Amount;
void Awake()
{
name = itemData.itemName;
cost = itemData.itemCost;
amount = itemData.itemAmount;
itemNameText.GetComponent<TextMeshProUGUI>().SetText(name);
itemCostText.GetComponent<TextMeshProUGUI>().SetText(cost.ToString());
itemAmountText.GetComponent<TextMeshProUGUI>().SetText(amount.ToString());
itemIcon.GetComponent<Image>().sprite = itemData.itemIcon;
}
void Update()
{
}
}
And here is the SpawnButterOverTime script:
using System.Collections.Generic;
using UnityEngine;
public class SpawnButterOverTime : MonoBehaviour
{
[SerializeField] Building buildingInstance;
[HideInInspector] public float bps{
get{ return BPS; }
set{
Debug.Log(GameManager.Instance.BaseBpsStack);
if(GameManager.Instance.BaseBpsStack.Contains(bps)){
GameManager.Instance.BaseBpsStack.Remove(bps);
}
BPS = value;
RefreshBuildingBps();
GameManager.Instance.RefreshBaseBps();
}
}
[HideInInspector] public float BPS;
void Start(){
CalculateBps();
}
public void CalculateBps(){
bps = GetComponent<Building>().itemData.bps * GetComponent<Building>().amount;
}
void RefreshBuildingBps()
{
GameManager.Instance.BaseBpsStack.Add(bps);
}
}
The problem I have is that whenever I run the code, it generates this output:
I have 3 building objects placed down thus 3 building script instances, thus I think each error is only occuring once in the building script.
Does anyone know why I may be getting this error?
nothing really.. im coming back to it.. and its a bit hard to follow.. im thinking of redoing the way i load my scenes...
now they're just indicies but im not sure its very scaleable.. say now i want a cutscene between the first level and the main menu.. imma have to drop down every single value to make room
and i can only imagine how that'd end up the more scenes i have to add to it
but i have to get there first.. gotta follow the flow of the game-manager.. im not very good w/ breakpoints
if i write all these out on scratch paper i can probably keep up with them and update it just here and there
its simple.. its an NRE
the code is trying to access something that isn't assigned correctly
line 12 of SpawnButterOverTime
bps = GetComponent<Building>().itemData.bps * GetComponent<Building>().amount; what is this syntax? im not even familiar w/ that
ohh nvm its two values being multiplied ๐คฆโโ๏ธ lol
ohhh sorry ๐ญ
lol, dont be sorry
whats line 12?
the debug.log
I see. Maybe you can store types of scenes in separate collections, like a list or dictionary. The cutscene can be the key, and its scene index the value . . .
a dictionary has been recommended before.. which im okay w/ using
but ive never used one.. soo ๐
Honestly, that's what I'd do . . .
thats good enough for me โค๏ธ
i have a scriptable object that holds their data and i calculate bps based off of their multipliers in the scriptable, that's what the line is for. But line 12 apparently is the debug.log. Even if i remove the debug.log it still says line 12.
clicking on the error again gives me this
yea, its not actually 12.. it might be a little before or after
CalculateBps is ur error
No need for [HideInInspector] for the bps property as properties don't appear in the inspector unless you manually add an attribute . . .
it's public, it kept coming up
i do that too.. for editor stuff i assign a texture publicly and then hide it
is it because it can't detect the list?
i'm trying to debug log the list but it's not coming up
but i coulda just used the Debug version of the inspector to assign it i guess
shouldn't u loop thru the list and debug each element
this is where i define the list
no no it's not working and failing
it's failing and working
ohh my bad lol
lol
for some reason
trying to access the list is giving it an error
but why can it not access this list?
until later?
but the code above is initializing it at the very start
the baseBpsStack;
and when i go into my inspector the buildings script is automatically disabled on runtime
The BPS field would appear, so that one makes sense, but not bps?
That's declaration not initialization
Then GameManager.Instance is null
Is GameManager or Instance null?
If you are receiving a Null Reference Exception on that Debug.Log line then yes it absolutely is
That's the only common denominator between that line and the debug log line . . .
nice! lol
Just check the value of both. There's obviously an error and we can't do anything but wait until you tell/show us . . .
๐
usually we are ๐
Ummmm why is it null ๐
good question
Because you are accessing it before Awake has run on that component
mmhmm.. i concur
how do i fix it so this does not happen
Access the Instance property no sooner than in Start
Thank you
i had a hell of a problem with this kind of stuff as soon as i start making real game managers..
๐ค
It works ๐
When i earn 10000000 dollars from this game I'll dedicate it to you guys
fr
screenshotted
Yes
Never assume. Always check . . .
Yeah alright
debug stuff regardless
I will never make this mistake again โ ๏ธ
good luck w/ ur next section
heck ya! w/e that means ๐คฃ
lol ๐
Lol
Does anyone know why changing a value in inspector doesn't trigger the set or get property
u need to use Editor OnValidate() type stuff i believe
Ohhhh
why would it? it's the backing field that is serialized and being edited in the inspector, not the property
Gotcha
might be able to rig something up to do it
maybe not tho.. im not big into getters and setters yet
i'll see might not be worth it to go through that
but i'll check it out
thanks bro
i like editor scripting ๐ its a good change of pace
Haha, this is the same as my notes . . . ๐
I have a gameobject called "Load" and this "Load" has a component called "Thing". "Thing" creates a gameobject primitive cube. And that works just fine. But if I have it create another primitive cube. A crash occurs. Does anyone have any ideas?
namespace Redacted
{
class Thing : MonoBehaviour
{
private GameObject leftPlatform;
private GameObject rightPlatform;
public void Start()
{
if (Redacted != null)
{
leftPlatform = GameObject.CreatePrimitive(PrimitiveType.Cube);
leftPlatform.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
leftPlatform.transform.position = GorillaLocomotion.Player.Instance.leftControllerTransform.position;
leftPlatform.transform.rotation = GorillaLocomotion.Player.Instance.leftControllerTransform.rotation * Quaternion.Euler(0f, 0f, -90f);
leftPlatform.SetActive(false);
rightPlatform = GameObject.CreatePrimitive(PrimitiveType.Cube);
rightPlatform.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
rightPlatform.transform.position = GorillaLocomotion.Player.Instance.rightControllerTransform.position;
rightPlatform.transform.rotation = GorillaLocomotion.Player.Instance.rightControllerTransform.rotation * Quaternion.Euler(0f, 0f, -90f);
rightPlatform.SetActive(false);
}
}```
(More towards modding but it follows the same principles)
Perhaps components just cant host multiple gameobjects or I have some kind of name looping over?
why u using if (Redacted != null).. ofc its not null.. Thing is within Redacted..
thats the problem
can anyone help me with fixing my walljump code
i have got it to work
but it works like half the time
or pretty much randomly
show code
do you want me to just copy and paste it
!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.
Do something like this
Read the link and use the websites listed to post code . . .
use links for large code
my brother in christ
https://hastebin.com/
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
(in like an hour sorry)
anyone got an idea as to why my player character (smiley) won't properly collide with the obstacles (red)? please ignore the horrible temporary assets lmao
to be clear, it should be colliding fully with the obstacles. but instead of bumping into the sides of them, it's only bumping into the middle :l
Thing isn't in redacted that is just a placeholder name
If I create 2 gameobjects within the same script it causes a crash but I tried seperating it into 2 different scripts and it worked
depends on many different things..
this is true, i'm rather confused
it being my first time with a tilemap doesn't help much lol
if you have colliders and rigidbodies on em i could guess that ur using translation to move it maybe?
not sure? i'm moving the character by adding force relative to it's position
did you use tilemap collider? are the physics shapes correctly set, show the colliders in scene view
show code
you got it. please no flaming
if (Input.GetKey(KeyCode.W) == true) {
Player.AddRelativeForce(Vector3.up * MoveSpeed);
}
this is the code to move the player up, super simple
oh. yea thats fine.. wouldnt cause a no-collision situation
oh ok , can u show the player colliders and environment , make sure gizmos is on to see colliders
oh shit
i misread that. well then
hold on a moment lmao
why is the answer to my problems always my own stupidity
why is the collider half the size of the graphic?
i don't know lmao, i suppose that's the problem? hold on
its ok now... we dont talk about that
thank you for fixing my stupidity once again navarone
collision will only occur with the box. anything else will pass through other objects . . .
the fun never stops around here
yep, somewhere along the pipeline i fucked up my collision box somehow
how can i slow down - boost speed with CharacterController.velocity just like Rigidbody.velocity
What do you mean boost speed? You directly move the CC as you want via .Move
If you want to move it further, give it a vector with higher magnitude
oh thanks
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
here is the code for my walljump
it works randomly
i don't think it is any collision issues
could someone please help?
done
Have you tried putting the if (isJumping) code in an Update void?
This might be a contributing reason as to why the wall-jump code works randomly.
@sick storm
Yeah
It let me jump all the time
But i would only jump up
Straight up
And the wall jump would happen randomly
Like the fixed update
While fixed update only lets me wall jump but randomly
Have you tried doing the WallJump() function in Update()?
FixedUpdate only runs under a specific rate provided in the editor
Maybe try doing the function in Update (called every frame)
Did that
But it wprked the same as fixed update
I tried both at the same time
Didnt work
Tried just not having it as a function and putting it in update
have you also checked your colliders?
This can affect the script too
if not then i advise checking
I put a debug message to tell me when im wall sliding
And it always says i am when hugging a wall
Which means all i have to do is press jump
But thay works half of the time
And the wallslide code works
Maybe you can set a ground check
So that the function will only trigger when you're not grounded
as in, standing on ground
I tried that
Same resuly
I put a ground check in the if statement but nothing changed
Does the problem still persist even after recompiling or restarting the editor?
Yeah
is this scene 3d? i'll try to recreate the problem myself with the code provided
2d
ahh alright
Yeah alr
Also noticed you're using Visual Scripting too
Yeah
Does anyone have a solution for intellisense in vscode? It suggest stuff like MonoBehavior but never game objects
Ive tried following the guide but it didnt seem to work well https://code.visualstudio.com/docs/other/unity
we dont know what your vsc config looks like so we're not sure how to help
wait
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
โข Visual Studio (Installed via Unity Hub)
โข Visual Studio (Installed manually)
โข VS Code
โข JetBrains Rider
โข Other/None
Ah that's the same one, it's updated.
im really sure i have the default
do you really love vsc that much
For clarity's sake, what do you mean, "Intellisense does not suggest game objects?"
Edit: the way it reads to me is a functionality which the Intellisense is incapable of, no matter how it's configured... It can't autocomplete to references for specific GOs. Your IDE is not aware of the Unity scene in that capacity.
just vs keeps crashing
Hi, I downloaded for the first time and I can't open a new project
not sure
is 12 enough?
hey all. i have a mega basic character script, nothing fancy at all. i can walk lol.
What would be the best way to apply a talent/skill to my character? should i make my talents scriptable objects and add them to a list on the player character? that's kind of what im going for, but i cant make the selected talent scriptable objects actually apply to the player currently - so i was wondering if there was another 'best practice way' or if i should stick to this until it works.
I'm pretty new to all of this, i don't know whats best from a design perspective.
something like this thats not suggesting
ah alright. That makes more sense... and is a problem :/
why scriptable object
not saying you're wrong but i just want to confirm what you plan to do with a scriptable object
like how do the functions in your scriptable object apply to the player
Do you think it makes sense to learn normal C# and then switch to Unity C#?
yes
you should have a good grasp on c# and what object oriented programming is, itll make your life in unity much easier
Thanks for your assistance.
are you still there?
I'm here-ish
is there a solution for this?
I'm not really sure... I use VS for Unity, myself - when I started the VSC extension was unmaintained and lacked debugger support, so I defaulted to VS and never gave VSC a run...
The only things I could think to do in your situation are just generic steps which I'm sure you've already tried - removing the VSC extension, removing the Unity package, and taking it from the top, ensuring that you're using the Visual Studio Editor >= 2.0.20 package (and I guess that the Visual Studio Code Editor package is not installed). Then rebooting all the things.
It's uber weird that that you intellisense only seems to work for some of the core types, but not others :/
Unity is telling me it doesn't register either the rooms or roomIds of the rooms list. I have no idea what might be causing this issue.
roomManager script -> https://gdl.space/erudahisig.cs
actually it might be the ids
if u double click the eroor what line of code does it show you?
line 47. The sort
I thought it's becuase I'm not assigning the roomIds, but even in that case it should at least tell me there cannot be any duplicate ids
Where do you assign the rooms?
I added this line but it did nothing -> room.roomClone.roomId = room.roomId;
it should be in the link
put
if(room.roomId == null)
{
Debug.LogError($"Room {room.name} doesn't have an id");
}
inside the initialRooms loop
at the start?
Wherever you want
well if it's an int it can't be null
it can be 0, also
0 doesn't throw a NRE
also the rooms have an id always as it's manually added in their serialize thing
what I'm doing rn is making the roomManager operate on copies instead of originals
before all worked as intended
so no need to worry about the original rooms
the copies are messing something up with the sorts
The rooms list is public, is it empty in the inspector?
Is it empty when the game is not running
yes. It's all added in the awake
Did you check?
now I did. I deleted the first three things, I have no idea why they were there
the list was supposed to be empty
so far after I launched the game there's no error
lemme test it and see
well good news is the rooms operate properly. But I have one question, if you're still here
What line can remove any missing elements from a list?
to be honest i went into unity without any experience in programming and i made a game successfully
experience is more important than skill
but yeah it is good to have an understanding of OOP ofc
just not required in my opinion
rooms.RemoveAll(room => room == null); doesn't seem to do the job
in what way is experience not skill? yes you should definitely have a background in c# if you want an advantage compared to most in this channel
Yes but for some people who want to get into unity fast they dont have the time to spend hours learning c# when they can spend their time MAKING a game that will in return give them skill and experience at the same time
if you have experience you have skill, if you have skill you have experience, they're linked, I assure you. As you get experience from something you don't know anything about, you'll start to know some things about it. Same way as to get skill you need to do the thing in which you want skill so that's experience
tf am I saying
they dont have the time to spend hours learning c#
yet they have time to spend weeks debugging beginner level issues
If youre following a specialized curriculum then you shouldnt have any issues
why is this not working???
Deleting a gameobject doesn't remove the element from a list, that index just becomes null.
You don't do anything to remove an element of rooms
so what should I do to delete it?
you need a ref to the Room type and then google -> how to remove element from list c#
.RemoveAt() is what I found
that requires the index, there's also another way
is this better?
what does your test show
before the if
Debug.Log($"room is null : {rooms[i] == null}");
I'm not too sure bout this but the room is not null, the reference is still set. The object is gone though
so should I destroy the originRoom entirely, not the gameObject?
You need to remove it from the list before destroying it
seems more like you want to remove currentRoom though.. as that's the one being destroyed
yeah, my bad
alright, everything works fine
thanks for helping me end a 2 days long headache
does order in layer affect collision?
No, purely visual.
then why did my collision stop working when i changed the order of layer
i have one projectile which is a trigger and a player thats not a trigger
i changed the projectile to 2 order of layer and player 1
suddenly collision stopped working
sorting layers are render order only
collisions are based upon layer collision matrix
hello, does using new inputsystem change something about the movement itself or only the way it registers input?
only the way you access the input data
the data itself remains unchanged
so static variable acts as global variable defined at top?
i guess so
but not really
static variables are variables in a class that arent attached to an object
you're probably making this statement coming from a c++ perspective
c++ has both static variables and global variables though
Static variables are associated with the type rather than the instance. That is all
As in, how do you serialize references to scenes?
The Scene type itself represents a loaded scene, so it's not appropriate. I use a "SceneField" class I grabbed from the forums a while ago
It references a scene asset and copies the path of the asset into itself
you can resource.load it and see what type comes up
imma give it a try
@swift crag UnityEditor.SceneAsset
editor only thing
unity will scream if you build using that
Yeah, thatโs what the SceneField class uses
Does having big scripts slow down the speed
Your script is not big; don't worry about it. The only thing it'll affect is the performance if written badly . . .
howdy, I have this code that rotates a object and it works good but it lags the game alot. no idea why? its not the object as when i turn the script off no lag, but when the thing starts rotating i get 5 fps, if anyone has any idea why pls lmk, would be appreciated :)
public class RotateObject : MonoBehaviour
{
public float rotationSpeed = 100f; // Rotation speed in degrees per second
public bool clockwise = true; // Direction of rotation
void FixedUpdate()
{
// Determine the direction of rotation
float direction = clockwise ? -1f : 1f;
// Calculate the rotation amount for this fixed frame
float rotationAmount = direction * rotationSpeed * Time.fixedDeltaTime;
// Apply the rotation to the GameObject
transform.Rotate(0f, 0f, rotationAmount);
}
}```
So if it handels like a lot of different actions in one script it wont affect it ?
By default, each script should handle one behavior. If handling many actions, then your code will be harder to maintain and break SOLID principles . . .
List<int> numList = basicNumList;
numList.Remove(1); its why deleting the element of basicNumList?
it removes the first entry which has the value 1. Perhaps you want RemoveAt
im need the Remove. but my problem is: not need to delete in basicNumList
because both variables are referencing the same list.
but they are the same thing
if you want to create a new list that contains the same elements as another list, there's a constructor for that
ok thx
other variables not have this method
like what?
"variables" don't have methods or constructors or anything else
perhaps you can show what you're trying to do
I'm guessing you don't know the difference between Value types and Reference types
dont know. im reconstruct the list and its working now
Hello there, im currently having a problem with my character controller. Im trying to create a character with topdown movement locked to the camera, however, the code for the rotation doesnt work properly for me. Whenever i rotate, my character makes weird and drastic movements and snaps from one position to another. Furthermore, I know that the issue is with the code for the rotation, as without it, the character moves as expected. Does anyone know whatยดs wrong?
(My code is down below, along with a video showcasing the issue)
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class CodeController : MonoBehaviour
{
public float f_speed;
private Vector2 move;
public void OnMove(InputAction.CallbackContext context)
{
move = context.ReadValue<Vector2>();
}
void Update()
{
movePlayer();
}
public void movePlayer()
{
Vector3 movement = new Vector3(move.x, 0f, move.y);
if (movement != Vector3.zero)
{
transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement), 0.15f);
}
transform.Translate(movement * f_speed * Time.deltaTime, Space.World);
}
}```
how can i make a kinematic game object collide with a static tile map collider?
yo, HOW DO I MAKE MY FUNNY BEAN MOVE! I've been coding for days and i cant even make a feckn camera move even a lil! If anyone is wondering here is my code. I've mad two C# scripts
public float sensX;
public float sensy;
public Transform orientation
float xRotation;
float yRotation;
private void start()
{
cursor.lockstate = cursorLockMode.Locked;
cursor.visible = false;
}
private void update()
{
// get mouse input
float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = mathf.Clamp(xRotation, -90, 90f);
// rotate cam and orientation
transform.rotation = Quaernion.Euler(xrotation, YRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
this is the first
!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.
how else do i show my code
It's almost like the message I just sent called up a bot that tells you multiple ways to do that
๐ฟ
btw do i just wait for someone to help me or do i ping someone
You can start by actually posting your question properly
with formatted or external code
i just got on the server less than a minute brotha. chill your beans
yes, but he did explain how to format it. so you should try that my friend
he didnt
โฆ
do i have to individually click each link?
you should try reading
๐ฟ๐ฟ๐ฟ
my bad
//public float sensX;
public float sensy;
public Transform orientation
float xRotation;
float yRotation;
private void start()
{
cursor.lockstate = cursorLockMode.Locked;
cursor.visible = false;
}
private void update()
{
// get mouse input
float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = mathf.Clamp(xRotation, -90, 90f);
// rotate cam and orientation
transform.rotation = Quaernion.Euler(xrotation, YRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
!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.
it didnt work.
// Your code here is a placeholder
Programming is going to be very hard for you if you don't have reading comprehension
Don't use whatever it is you think this slur is. And just copy/paste the message if you don't know where the key is.
these
these??? '''
Just use one of the bin sites
If you're getting filtered by copy-pasting this is going to be difficult
if you have a US keyboard it is top left below the Esc key (don't use shift)
just copy/paste the message if you don't know where the key is.
ok this is what happens.
public float sensX;
public float sensy;
public Transform orientation
float xRotation;
float yRotation;
private void start()
{
cursor.lockstate = cursorLockMode.Locked;
cursor.visible = false;
}
private void update()
{
// get mouse input
float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = mathf.Clamp(xRotation, -90, 90f);
// rotate cam and orientation
transform.rotation = Quaernion.Euler(xrotation, YRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
!code
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
I STILL DONT KNOW WHAT THE FUCK THAT MEANS. SENDING IT MORE WON'T HELP
@long igloo Copy this and put your code inside, where it says "code here"
thta's an image
I literally do not know how to explain it any simpler. Literally copy paste
This can't be easier
The message with plain text is right above.
I refuse to believe this is a real person
I'm going to mute you if you continue trolling
!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.
Are you part of that uncontacted tribe off the coast of India that keeps spearing journalists to death
Can you understand copying plain text from this message?
Copy and paste the BOT message
yes
// public float sensX;
public float sensy;
public Transform orientation
float xRotation;
float yRotation;
private void start()
{
cursor.lockstate = cursorLockMode.Locked;
cursor.visible = false;
}
private void update()
{
// get mouse input
float mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
yRotation += mouseX;
xRotation -= mouseY;
xRotation = mathf.Clamp(xRotation, -90, 90f);
// rotate cam and orientation
transform.rotation = Quaernion.Euler(xrotation, YRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
sorry absolute beginner here but unity isn't letting me build my game pls help
Try rebooting, it looks like it's stuck importing
Okay, so, first off fix all of your misspelled words that should be underline in red if your IDE is configured
Second, are you calling start or update anywhere?
you can look they're not misspelled
idk what it is
Okay then show your code for Quaernion
If that's not a compile error then you must have a class by that name
is that in the debug thing
It's in your code
Either that's a compile error you've failed to mention, or you made a class Quaernion
do i just type in Quaernion?
What is a Quaernion
You misspelled it
that's not a thing that exists
It's remarkably similar to a thing that exists, but, and I quote:
Which means that you must have a class by that name
so show it
literally how
Just like how you've shown this class
Show wherever you've defined Quaernion
Or, you can admit you made a spelling mistake instead of insisting you didn't when I can fucking see it right in front of me
where is it.
lmao
Jesus fucking christ
@long igloo Can you screenshot your IDE with this script?
๐ฟ
Okay, here's how you fix your code. Take your hard drive, wipe it, and donate to those less fortunate because you're not gonna need it
You. Misspelled. A. Word
You should confirtm installed IDE first the rest will be easier
For this error. There's actually much more
the only red words are private, void, and public
I didn't think this would be the hard part
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
โข Other/None
MVS isn't there, do i press other?
...MSV?
Just LOOK at your code. At Quaernion. Is that the right spelling? No, of course not. Spell it right
microsoft visual studio
its right there
it's subposed to be red right?
re-started unity and pc but its still not working :/
- That's not what it's called
- The acronym for that isn't MSV
- It's literally the first option
- Fuck you I'm done dealing with this
Is it the same warning? That it's stuck importing?
@long igloo Make a thread so you're not flooding this channel with this ridiculousness. Anyone who wants to humour you can do so in your thread.
yes the same message pops up again but then disappears and then its as if nothing happend
Close the project, delete the Library folder from the project, and re-open it. It'll reimport every asset so it might take a while but it should get past whatever one it was stuck on
It's a generated folder so you won't lose any progress (as long as you just delete Library), it's just a thing that lets your project boot faster
i didn't put it in my code like that it was just a discord message
this
Thread's that way ๐
when i load the scene after dying the saved high score resets back to 0 even though i saved it using playerprefs
Where do you load it?
omfg
in logicscript.cs on void start
Can you show the !code for where you load and save the score?
๐ 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.
and the save code is in update
or should i not use playerprefs
GetInt returns the value, the second parameter is the default value to use if the key is missing. You probably want to do highScore = instead
but setint is good as it is?
Yeah, SetInt is fine, that one takes the value you want to store as the second parameter
But GetInt is slightly different
im trying to make a save/load position which will save the scene you're on and what your position is on that scene, the problem is that when i load the scene it won't also load the position, I've tried it without loaidng the scene and it saves my position just fine. Is there a way to fix this?
First, log the pos you calculate to make sure it's sane
just finished doing this but its still the same
If it looks fine, then explain how your character moves. You might need to set your position in a different way.
I just did that and it shows the correct position but it puts me right back at the start of the scene
I though of that and made my movement script not active when i load
You have a bunch of references to editor-only classes.
Given the names of the folders, are those editor tools?
You may just need to throw them into a folder named Editor
That keeps them from being included in a build.
These were not in your original screenshot
Yeah, you have a lot of Editor scripts that aren't being excluded from the build
yeah just noticed that i had these turned off๐ฅฒ
Hello,
I follow a tutorial to create a 2D game on Unity and now I create my game. I try to create my inventory system but I have question. In my tutorial, he does a script for scriptableObject for all items availaible in the game. Is it better to create 1 scripte for all items in the game or different scripts for different kind of items (weapons, armors, potion...)
Probably the best way would be to have a general Item SO, then have different types of items as child classes of that, then have individual items being a child of that. So something like:
- Item
-- Weapon
--- Sword
---- Sword of a Thousand Truths
How can I create child items in the SO script ?
By inheriting from the parent type
Same as any class
public class Thing : ScriptableObject
public class SpecificThing : Thing
Thanks
So, is it okay to do this ?
using UnityEngine;
[CreateAssetMenu(fileName = "Item", menuName = "Inventory/Item")]
public class Item : ScriptableObject
{
public int id;
public string itemName;
public string description;
public Sprite itemImage;
public class Weapons : Item
{
public int damage;
public int reach;
public int cadence;
public int lachose;
}
public class Armors : Item
{
public int armor;
}
}
I would not nest the classes
Weapons and Armors would be better OUTSIDE of the Item class
[CreateAssetMenu(fileName = "Item", menuName = "Inventory/Item")]
public class Item : ScriptableObject
{
public int id;
public string itemName;
public string description;
public Sprite itemImage;
}
public class Weapons : Item
{
public int damage;
public int reach;
public int cadence;
public int lachose;
}
public class Armors : Item
{
public int armor;
}
u making an inventory system?
Yes
ohh cool good luck mate ๐
Thanks ๐
ANd another question, I see on internet some people using abstract for the class, why ?
abstract classes can allow u to to for example define a function that must be present..
An abstract cannot be created directly. This allows you to make sure no one (including future you) tries to
in all inheritanced ones.. but u could overload.. to change the behaviour
public abstract void Use();
public override void Use()
{
Debug.Log("Using weapon: " + itemName);
}```
public override void Use()
{
Debug.Log("Wearing armor: " + itemName);
}```
So we use abstract when it depends of an other class ?
An abstract class is a class that cannot be instantiated directly. It can contain both abstract methods (which have no implementation) and non-abstract methods (which have an implementation). Abstract classes are used as a base class for other classes.
Okay, I think I understand
idk yea lol ๐
i use interfaces more often than abstract classes
but im sure im stilll just learning as well and will refine that once it clicks more
What does this + symbol mean? its the only object that acts strangely in multiplayer. it teleports to the center for 1 screen but is fine for the other. Also, nothing useful on google about it that I could find
Look up abstract, virtual, override, sealed and new keyword. Abstract indicates that there must be an implementation added before something can be used. When it's on a class, this class must be inherited from in order to be used. When it's on a method/property, the class must be inherited from and you must implement the given abstract properties/classes. A class in this case is always abstract. If a property/method is abstract, it has no body.
virtual/override is only possible on method/property level. A class by default is always virtual and does not have to be specified. virtual is the same as abstract, but the implementation is optional. The body of a property/method will always be defined, and might be empty.
If you want to override a property/method that is abstract/virtual, it must contain the override keyword. This indicates it is being overridden. This does not have to be done for a class.
If you want to override a property/method that does not have abstract/virtual, it can contain the new keyword. This means the original method is no longer shown when you use the inheriting class. It is optional but the compiler will inform you to add it.
If you don't want to allow a property/method/class to be overridden if this is allowed, then you can add the sealed keyword. This means the property/method/class cannot be overridden and the compiler will throw an exception if you inherit anyway.
It means this instance of the prefab contains things that aren't on the original prefab asset
this worked, thank you! however i have a button that is supposed to show up at the end of the start scene that leads to the second but the button doesn't show up in the build (it works fine in normal play mode in unity) any suspitions why?
you probably have an issue with your UI anchors
Show me the inspector for the button object.
It's anchored to the center of its parent right now.
However, the X and Y positions are really small, so it's not like it's going to fly way off the screen if your resolution changes
the Z position of -2000 is interesting, though...
You should ask about this in #๐ฒโui-ux . Include a screenshot of the canvas's inspector.
Also, try changing the resolution of the Game view (it's a dropdown in the top left corner). This may reveal the problem in-editor.
this button wasn't there before i just added it maybe that was the issue ? im gonna try and build it again and see
ok thanks!
If your code tries to activate the button, then yeah, it wouldn't work without the reference
But I'd expect that to break in-editor too
Hello, im just getting started with 3d unity, (not for real project, just for some hobby experiments). I created playermovement, works fine, but if i jump to for example a mountain, i can't move if the slope is too deep, but when i jump i can reach top of the mountain cuz my character bottom stick to it. Whats wrong? I guess my character should just slide down
ask this in #๐ฒโui-ux too
Hellooooo
You know how like, when you start typing and vscode auto suggests the possible things, i don't know what they are called
But it's not showing up
!ide
If your IDE is not autocompleting code
or underlining errors, please configure it.
Select one:
โข Visual Studio (Installed via Unity Hub)
โข Visual Studio (Installed manually)
โข VS Code
โข JetBrains Rider
โข Other/None
Thank youuuuuuu
So, im just starting a unity project and im following a tutorial to get the movement started. For some reason, the ray casted to tell if the player is on the ground doesn't work. I've been at it for three hours and know that the ray is being drawn and it should be colliding with the ground, but it doesn't. Can anyone help? (the debug.log always shows false)
What is whatIsGround?
Show the inspector for this
If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:
โข Visual Studio (Installed via Unity Hub)
โข Visual Studio (Installed manually)
change your DrawRay's distance to Vector3.down * (playerHeight * 0.5f + 0.2f)
So you can see how long your actual raycast is
Are there any colliders inside of that ray? That looks pretty small and also way below the capsule
what do you mean? theres nothing other than this line of code
I wasn't asking about code
I was asking if that ray is colliding with anything
it doesn't look like it's colliding with anything
but colliders could be invisible so I'm asking if there's anything there
It looks like the controller is offset from the actual transform
yes, it is colliding with the ground object box collider
Can you show a screenshot where the ray is visible colliding with it?
oh
i was moving the ground around so the top of it would collide with the ray and it started working
i had the ray fully covered with the ground and not touching the top
i guess that was the problem?
@swift crag i've been recommended to rewrite my entire system to use fixed-point math, as well as create my own physics system with its own collisions to achieve full determinism ๐ญ
you can enable backface hits in Physics settings (which is enabled for 2D by default) 
There is the Unity Physics package. It's supposed to be able to provide deterministic physics (at the cost of some performance)
It's intended to be used with the rest of the Entities packages, though.
DOTS physics? apparently its not deterministic cross platform, and im not even using actual rigidbody physics, i'm using my own stuff but its using floating point math
by own stuff i mean like, kinematic character controller or whatever
i'm back, i cant build again :/
This one looks like your main problem
Check the import options for that asset
more editor-only assets that got into the build, methinks
i think so too but when i move the folder to Editor these pop up
its the tool i use for the dialog so i think moving it messes some stuff up
it can no longer use the cherrydev i need
nobody said to move the entire folder into an Editor folder though
it's just the one asset in the Resources folder that seems to be an issue
Hey, can anyone help me? Im trying to make a platformer game and I've got a basic movement script and animations, but for some reason the jumping animation which has 11 keyframes only plays 2 first frames and loops them
creditTextRef is a Canvas Image. This snippet is inside my introManager script (https://gdl.space/buketafama.cs). Not only is the color alpha not changing, but I hear the audio play on every frame this if is reached. Can someone help?
if (creditTextRef.color.a != 1) {
Color creditTextColor = creditTextRef.color;
creditTextColor.a = 1;
creditTextRef.color = creditTextColor;
audioManager.PlaySFX(audioManager.Popup1, Random.Range(0.9f, 1f), 0.7f);
}
any tips to learn coding? im fairly new and understand a few things, when i watch a tutorial i understand the code most of the time but when i have to type it myself i dont know where to start...
Is your transition from AnyState? Perhaps it is just continually reentering the animation
yeah, it is from anystate, should it be from something else?
Doesn't really sound like a matter of knowing code but rather a matter of knowing what you are wanting to do within the engine
Yes. Basically try to not use anystate at all. There are some occasions it can be useful, but not for states you go in and out of multiple times
alright, ty
how have you confirmed that it isn't changing
because otherwise I'd see the value change in it's color property
or am I missing something
it worked, tyvm. is there a way to loop the last 2 frames so i could have a falling animation?
I'm having this weird issue where I'm using RotateTowards, and, it appears to be changing speed constantly. Sometimes it feels a lot slower when I'm close, othertimes, when I'm really far away, its stupdily quick/speeds up quickly. Why is this happening?
void Update(){
if (player == null) {
return;
}
Vector3 playerPos = player.position + (Vector3.up * aimOffset);
timer += Time.deltaTime;
positionHistory.Enqueue(playerPos);
if (timer >= lookAtDelay) {
currentDelayedPos = positionHistory.Dequeue();
Vector3 direction = (currentDelayedPos - losAimPoint.transform.position).normalized;
Quaternion targetRotation = Quaternion.LookRotation(direction);
// Smoothly rotate towards the target rotation at a constant speed
aimingHead.rotation = Quaternion.RotateTowards(aimingHead.rotation, targetRotation, lookAtSpeed * Time.fixedDeltaTime);
}
}
problem is though, is that it is changing. but something else is likely changing it too. don't rely on inspector values for debugging purposes. use breakpoints and actually inspect the current values or log the values
I would make two states. The first which doesn't loop, which transitions to the looping section
imma do the breakpoints, gimme a sec
alright, ty
I'm doing the breakpoints, but either I'm doing it wrong or the value just isn't changing
where did you actually put the breakpoint
Hey everyone;) I have a question I have a parent with a child gameobject the child has 0.15 for y the rest are 0 when I move the parent now in x direction and look at child.transform.x it does not match with parent.transform.x what is the reason?
i know
Examples of it happening.
https://gyazo.com/c4daf738c192cee56e266df7525c708b
https://gyazo.com/f45683e9ef3e1783f934bd4f8893e96c
i did that but now im kinda stuck
i dont know what to do next, im in tutorial hell lmao, im just watching tutorials and i know the code they write but i cant write it myself
Then do not watch tutorials.
Try to make the simplest thing on your own
thats the problem
Just brickbreaker or something
dont know what to write
ah ok it worked!
i know i few things
You did the essentials and junior programmer pathways on learn.unity?
yes i did, i know what functions and methods are and all, i just dont know where to start, i understand what youtubers do when they show the tutorial but when i try to make on my own its impossible lol
Well, step one, stop saying or believing any of that.
Step two, just start, be willing to fail and write garbage, and push through
one of the most important skills when it comes to game dev, and just programming in general, is the ability to break what you want to do down into smaller problems. then you just need to learn how to solve those smaller problems individually and put all that knowledge together to actually make something
i just dont know what to write for the thing i want lol, i cant even write basic movement out of my head, i just dont know what or how to write, but if i watch tut i understand it
Seems like when you're up close you're hitting the maxDegreesDelta limitation, as small amounts of movement result in a larger change in angle.
When you're far away, your movement results in a much smaller change in angles, and so unlimited by the maxDegreesDelta argument, the rotation is able to more precisely follow your movement
i have a simple idea like flappybird, but when im trying to make it i just dont know what to write...
Too much. Start smaller
Get something SUPER simple done. You just need confidence
That is sort of what I expected.
At the end of the day, I want it to rotate at a specific speed always. RotateTowards, doesn't seem to be what I'm looking for in this case.
i just dont know what to write, no matter what im trying to make, i need to google it how i need to do it...
i am doing a few things right when coding but then i dont know what else i need to do
you don't just go "i'm going to write flappy bird, here is the code for that". you break that down into smaller steps and write code for that. like "how do i make the object fall" then you realize you can just slap a rigidbody on it with gravity. then it's "how do i make the object jump" and you realize you can add force to the rigidbody. and you just keep making incremental steps like that. that is how you make stuff
Stop thinking like that. Just write garbage. Keep writing. Try to fix the garbage.
Break it down as small as you can in your spoken language. As precise and small steps as you can
Like making a sandwich could be 30 to 50 steps or more if explicit enough for a computer to act on.
Reach right hand towards loaf of bread. Clamp hand onto it with low force. Lift loaf. Bring to cutting board. Remove tie. Remove plastic. Reach for slice. Etc
Just as an example.
Write your pseudo-code like that
cant fix the garbage without internet....
Disagree. But you do seem to have internet now..
bro, i just dont know what to write lmao
I just told you what to
i've run into another issue, i have noticed that my character moves at extremely different speeds depending on which aspect ratio is used any idea how to fix this?
Write pseudocode first
It's more about the thinking than the writing
If you always rotated towards the player's current position, it would be a constant angular speed, since it wouldn't factor in how the player moved as it currently does...
But are you saying you want the point on the beam closest to the player to travel the same amount of distance, regardless of the distance between the turret and the player? (In which case, the turret would actually rotate slower when the player is far, and faster when the player is close)
write garbage but if i dont know what is wrong about my code and i cant use the internet then im done
then don't bother practicing and never get better ๐คทโโ๏ธ i don't know what else you are expecting to hear other than "break things down into smaller, more achievable steps"
i just dont know what to write without the help of the internet
i open vscode and im there like, what do i need to write to move
so you look up various ways to move an object
you're not just going to magically know how to do something without having researched how to do it first
At this point it is just whining. Stop doing this here, and just go start writing the pseudocode
Write what you WANT to happen in real words. Then try to convert it to code. If you struggle, then ask here
Ideally, you'd acquire some input from the user and apply it to the character
yes i know, and i'v searched how to write movement code and now im trying to do it without looking it up on the internet but i dont know anymore...
then fucking look it up. stop putting these restrictions on yourself and actually learn.
Sounds like a dependency issue
Movement is honestly one of the harder things to do. Stop starting with the difficult stuff
Your entire issue seems just one of your thinking. Stop telling yourself you can't
public class new_player_movement : MonoBehaviour
{
public Animator anim;
public float speedH;
public float speedV;
public float RunSpeed;
public bool walk = false;
private EventInstance playerFootsteps;
private EventInstance playerRunsteps;
// Start is called before the first frame update
private void Start()
{
playerFootsteps = AudioManager.Instance.CreateEventInstance(FMODEEvents.Instance.playerFootsteps);
playerRunsteps = AudioManager.Instance.CreateEventInstance(FMODEEvents.Instance.playerRunsteps);
}
// Update is called once per frame
void Update()
{
transform.position += new Vector3(Input.GetAxis("Horizontal")*speedH*(Input.GetKey(KeyCode.LeftShift)?RunSpeed:1), 0, 0);
transform.position += new Vector3(Input.GetAxis("Vertical") * speedV * (Input.GetKey(KeyCode.LeftShift) ? RunSpeed : 1), 0, 0);
anim.SetBool("isRunning", Input.GetKey(KeyCode.LeftShift));
anim.SetFloat("Walking", Mathf.Abs(Input.GetAxis("Horizontal")));
transform.localScale = new Vector3((Input.GetAxis("Horizontal")<0?-1:1), 1, 1);
}
}
this is for my player movement
I want it to always rotate towards the players position (Or in this case, the players delayed position) at a constant rate. So if the player gets a speed buff, the laser will still try to get to the next delayed position, at the same rate.
So if I tell it to spin at say, 5 degrees a second, then, it should always turn at 5 degrees to reach the given target position. It shouldn't ever go faster, or slower than that 5 degrees.
but its defenitly normal to look things up on the internet on how to write it?
doctors don't go "i'm going to diagnose this patient without consulting any documentation about diseases". don't just completely take away your learning resources when you still very obviously need them just because you want to stop relying on them. you need to rely on them until you have the knowledge to do it without them.
Yes of course!
so its normal if i learn how to do movement code, the next day i'll still need to research it bcs i cant remember how to do it?
Sure
You probably haven't learned it but that's to be expected
pfff i thought i was abnormal bcs i need to research everything
when you were in grade school did you only spend a single day learning how to add numbers together then you never practiced it again until you needed to add something? no. that shit was discussed repeatedly until you actually knew and completely understood what was happening
I guess that that's pretty much what you have going on already... the issue is the question, "what happens if it actually reaches the delayed position?"
I've been coding for 8+ years. I still Google stuff all the time. Heck, I'm struggling with something right now lol.
Then it would stop rotating.
damn... ait
But thats not what is happening right now..
I wager it is what's happening. It slows down because it achieves rotation to the delayed position. If it wasn't achieving the rotation to the delayed position, then it would not slow down as it would ride the maxDegreesDelta cap
Ohhh You know what.. That might be it.
So I guess I need to get the delta between the current rotation and target rotation, and, if its less than the maximum speed, skip the saved position in history.
TBF. There might be an easier way than using the history. I think thats my main problem here. I think if I just figure out if the player is Clockwise or Counter Clockwise from where its currently aiming, I just increase or decrease the rotational speed over time. That way I'll get that "Overshooting" motion I need.
Glad I wasted 2 hours on that. :^)
Could anyone please tell me what that means?
There's a script component on an object but no script attached. Either you have compile errors, the script that used to be there was renamed/deleted, or the script was manually removed
search thru ur hierachy and inspector to find a component that looks broken.. (it'll be obvious)
once u find it remove it
thanks for the help @rocky canyon and @polar acorn
I agree on premise, the history seems a little heavy... But I'm not entirely sure how I'd approach this either.
The simplest thing I can think of is maybe like... track the current direction of rotation. Update it each frame based on the player's position. If it changes signs, flip the direction of rotation in n seconds.
Though... hmm
Ah that still has issues. It does seem like a problem that I too could waste hours on ๐
Hey everyone, I'm trying to make an audio system for my quiz game. I hve four audio clips such as button clicking and a clock tick sound effect. I want the clock tick sound effect to play when there is a new question, which I have achieved by using PlayClipAtPoint(), but I also want it to cut off after the player answers the question. I cant find a way to access the game object that is created by PlayClipAtPoint() to Destroy it if the player answers the question. Also, there will be other audio clips playing at the same time as the clock tick if an answer is selected. SO, how to disable just the clock tick sound effect?
eh PlayClipAtPoint each time is overkill, they are better for one time sounds instead of frequently used for example
just store an AudioSource
having a reference to an audiosource you can easily Stop/Start, PlayOneShot, whatever
so create an audio source for each clip?
thats up to you really. You can also swap clips
but then it would be diffcult to play 2 diff sounds at same time if you need to
not sure if i have to code a camera instead of use cinemachine
since when i zoom out, all the characters get pixelated and when standing still its even worse, when moving its a bit better lol
are you using Pixel Perfect ?
also not really a direct code question, show what it looks like n setup in #๐ปโunity-talk prob
so maybe create four audio source game objects as children to the audio manager and then assign and play the clips I need in the methods ive written. got it. I'll let you know how it goes
theres always a dozen ways to play audio in ur game.. its really up to you and the workflow ur comfortable with when it all comes down to it
i tend to use a seperate GameObject for each type of audio
then .PlayOneShot() all day long
my debug logs are being grouped rather than being displayed in order, extremely disruptive to debugging. Is there a setting somewhere to prevent the unity editor from ever doing this again?
disable collapse
i must have clicked that by accident, thanks
{
foreach (Transform i in tegels)
{
if (i.position.z == Left.position.z)
{
int x = selectedtile.Length + 1;
selectedtile[x] = i;
}
}
}```
Hi
When i run this code it's giving the following error, does anyone know how to fix this problem?
Well the last item index in selectedtile is selectedtile.Length - 1 and you are using +1
ah
Well, considering you set x to a value greater than the size of the list, that would probably explain why it's telling you x is greater than the size of the list
thanks!
Hey, can anyone help me? I'm having trouble with making an animation while wall clinging, I think everythings right here and in Unity but it doesnt work. Any idea why please?
this is the code:
dyno asleep
use a site https://gdl.space
aight
or any from #854851968446365696
also could you explain exactly what "doesn't work" means in this context
The animation won't play, I have the bool and the transition done
are you talking about the "OnWall" one?
the others work ?
yup
are you using Unity 2022 ? Go under Physics Debugger and check the casts
make sure first the cast is correct then narrow down from there
sure you do, its under Window -> Analysis
there will be a tab called Queries in PhysicsDebugger
okay, what am I looking for there?
click ShowAll
yea
then check playmode with gizmos enabled, lets see the boxcasts
Okay ๐ it turns out i ctrl z'd the layer back to ground instead of wall, ty for helping
VoxelData voxelData = ChunkManager.Instance.voxelData;```
if i use one of these methods, am i making a copy of the data or storing a reference to the original? i'd rather avoid making copies
Is VoxelData a class or a struct?
its a class
Then you are only referencing the original, so it's what you want
allright ty
Well, as long as GetVoxelData isn't making a new copy
If it was a struct then it would give you a copy because it is a value type
{
return voxelData;
}``` i guess they should do the exact same, but i can keep the access on private with the method
another question i had, im using a 3d array the size of about 500x50x500. the data it holds is not sparse. would using a dictionary for those sizes be better if i want to change the values in it often?
Beautiful!! How did you end up implementing it?
How can I give a script the gameobject its attached to? (Without using a public variable and just slapping the gameobject on in the editor)
The bulk of the code is this:
Vector3 playerPos = player.position + (Vector3.up * aimOffset);
Vector3 direction = playerPos - losAimPoint.position;
direction.y = 0f;
Quaternion targetRotation = Quaternion.LookRotation(direction);
float angleDifference = Mathf.DeltaAngle(aimingHead.rotation.eulerAngles.y, targetRotation.eulerAngles.y);
if (angleDifference > 0) {
targetSpeed = lookAtSpeed;
} else {
targetSpeed = -lookAtSpeed;
}
currentSpeed = Mathf.Lerp(currentSpeed, targetSpeed, Time.deltaTime * speedChangeSpeed);
float step = Time.deltaTime * currentSpeed;
float newYAngle = aimingHead.rotation.eulerAngles.y + Mathf.Clamp(Mathf.Abs(angleDifference), -step, step);
aimingHead.rotation = Quaternion.Euler(0f, newYAngle, 0f);
Might be able to clean things up a bit but yeah.
nvm got that figured out
Very nice - that definitely seems like an elegant solve. I like the gradual accelerations as well - makes it feel like the turret has weight ๐
Yup, it also lets the player dodge through it and have some breathing room as well.
I don't think the frequency of changing values would matter either way in that scenario. I sort of lean towards the 3D array just on the premise of memory offsets rather than hashing... but I doubt it would matter much in practice(?)
thats good to know ty
Hello! I am new to ECS. I just followed the "Netcode for Entities" tutorial for creating a networked cube.
Now I want to spawn the cube in a specific location controlled by spawner logic. But the tutorial spawns the cube from the networking system. A spawner system should do that, not a networking system.
How do I tell the spawner system to spawn the cube? Set a flag on the spawner component that we are "ready to spawn"?
Okay, but then the networking system needs to associate the cube with the networking id.
So does the spawner system then set another flag on the spawned entity to signal to the networking system that it's now spawned and ready to have the networking id set on it?
What am I missing here? Surely a ridiculous setup of signaling back and forth to do a basic spawn and set some data is not the correct ECS workflow?
I'm probably not quite getting it since I have an OOP mindset. Maybe in ECS we don't care if the spawner controls the spawning logic and I just make the networking system do the spawning logic?
I suppose I could put the spawning logic in a shared namespace that both the spawning system and the networking system can use...
Thats where im unsure, and came here for a second opinion. I read some posts and wasn't sure if scriptable objects are ideal here. I would have a list<talent) to get the objects attaches. But i would like to know if theres a better way to do so.
the text that i add goes in the bottom left corner of my screen in game mode instead of staying where it is in the scene mode, how do i fix this?
tbf it does look nicer but id still like to know
Hey everyone. I'm getting an error CS0029: Cannot implicitly convert type 'int' to 'bool' on lines 51 and 64. I know its probably something super simple but I dont know how to fix it. Here is my code: https://gdl.space/zitokozuya.cs
Check for equality with ==, not = on your for loops
A more common pattern is to use i < Count though, it's resistant to the case where i exceeds that value. With == you'd end up with an infinite loop, as i would be greater, which isn't strictly equals to the (count - 1) anymore
Like, in a canvas-based UI? That would likely be an issue with your anchors - but you should take the question over to #๐ฒโui-ux, preferably with a screenshot detailing the problem in question, and the inspector for the text object
You might get a better response on this over in #archived-networking
im just switching bewteen the #scene and game icons in the editor
I'm not sure I follow
i made them buttons and im gonna add the coode SceneManager.LoadScene (sceneName:"Put the name of the scene here"); dont know how much it will affect it
due to them not following the design i give them im not sure how the code will interact with the words or "hitbox"
I think the large white outline in your first image is your screen space - so the text in the game view appears to be right where you've placed it - flush with the left edge, near the bottom.
It's following the design you give them, it's just that the UI Canvas is way bigger (1 unit = 1 pixel) so you just see the bottom-left corner of the canvas
Denoted by the slightly brighter lines that go up and right
When making UI, don't think about the objects in the world, because they're not in the same "dimension", and vice versa
No, UI elements are overlaid on the screen and it adapts to the screen size, given that your anchoring presets are correct
Again, the two dimensions are separate
The apparent position of an overlay canvas is completely irrelevant
It is admittedly somewhat confusing that Unity displays overlay canvases in world-space when the two have nothing to do with one another... They moved away from that approach with UI Toolkit
The actual positions of the objects do match where you see them in the scene view
but yeah, they aren't rendered by the camear
Hello, can anyone give me a little help?
if you ask a question, maybe!
I have a butotn that doesn't change the color of a sprite
I even set up the Event System and everything
The main idea is that there is a genie (A sprite) which is a singleton that can grant wishes
And each button (R,G or B) can ask the genie to grant a wish (add the color to the corresponding color of the sprite)
Something like this
Wait, could it be I can't add any more white than 255?
m_SpriteRenderer.color = color;
m_SpriteRenderer.color = new Color(255,255,255);
You seem to set the new color, then immediately overwrite it with white, no?
You pass in values from 0 to 1
removing the last line yields the same result for me
hi guys can someone help me implement a line of code in my code? in #๐ปโunity-talk they suggested i implemented this to fix my problem but im clueless, if i send the code can someone help?
Yeah, I think that'd be a product of caesar's point there ๐
I don't really understand it, could you elaborate further for me?
id assume that would be a problem since rgb only goes to 255, unless unity recognizes that and just sets it to the maximun (255) and white doesnt have a value of 255, it would be 255,255,255 or #FFFFFF
the values range from 0..1, not 0..255
You need to pass in values in range from 0 to 1, not 0 to 255
Color uses floats colors in that range.
Ohh, I see
The 0..255 you are used to is an artifact of how colors normally use 8 bits per channel
so 0..255 is the range of integer values you can store for each channel
Color allows for a wider range of values (each component is a float)
When you go past 1, you'd call that an "HDR" color
There's only way to find out!
People will generally be more reluctant to commit to answering a question or helping with something if they don't know what the problem is, or if it's even in their wheelhouse. Better to just provide the information and ask the question ๐
you're a lifesaver thank you ๐
ok ok, so basically there's two problems: 1) i'm using a secondary camera to render my guns, which already was a big problem but i got it working, but now my guns render through walls and stuff, so in #๐ปโunity-talk they suggested to add this: gameObject.layer = LayerMask.NameToLayer("Default"); in my code, but i dont know in what code i could do that. 2) when i try to drop off a gun, instead of replacing the new gun i picked up, it just starts flying in a random place. Here's the weapon + interactable object scripts if needed:
First off, !code
Second, when would you want to set an object's layer to default? That would help you figure out where in the code it should go
๐ Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
๐ Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
oh ok sorry i didnt know i had to use !code. I have to set the object to default when its not in the player's hand
๐ 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.
Silly buttons only accept ints as input tho ๐ข
So, what code do you have that changes whether an object is in the player's hand or not
Isn't that because your silly method has an int parameter instead of a float? (You can also just divide it by 255 in the method if that's what you prefer)
should be weapon manager
no, my silly method only has silly float params ๐ฅฒ
public void setRed(float red)
{
float conversion = red / 255;
setColor(m_SpriteRenderer.color - new Color(0, conversion, conversion));
}
public void setGreen(float green)
{
float conversion = green / 255;
setColor(m_SpriteRenderer.color - new Color(conversion, 0, conversion));
}
public void setBlue(float blue)
{
float conversion = blue / 255;
setColor(m_SpriteRenderer.color - new Color(conversion, conversion, 0));
}
I got another error anyway
Fix the errors first then
Yeah, code won't update until it can compile without errors.
Its not compilation tho
Its an ArgumentException: method arguments are incompatible when Iclikc the button
I imagine because I expect float and I can only give int because of Event Trigger doesn't let me add floats (e.g. 0.5)
Try removing and adding them back.
You need to actually follow the instructions that the !/code command brings up
๐ 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.
how big is a large code
Anything above like 5 lines imo
sooooo i use the links? just to be sure
Yes, use the link.
okay
weapon manager: https://paste.ofcode.org/LP43a2Pj3ZukCuqMjXU7JG weapon: https://paste.ofcode.org/dhG6BViAgY3zr6wBNS6sq6 interaction managerhttps://paste.ofcode.org/hdCxwrKMrR4AP6L2wtjvvu
why the ๐คข @north kiln
The logic is bad, confusing, or even wrong. Also the method names aren't PascalCase, which is normal C# standard.
Because subtracting like that makes no sense?
What are you trying to do
I cannot make sense of what this code is supposed to accomplish
I'm just currently working on a method to leave a white color more "reddish", "bluish" or "greenish"
but why would it not make sense?
I can't explain that to you, because I don't understand how you think it does
To tint a color generally you're best to use multiplication.
color * new Color(1, 0.9f, 0.9f) for example would return a slightly more red color
Because you've scaled down the non-red channels slightly
I was trying to accomplish that with subtraction
I'm gonna give multiplication a try!
Thanks for the suggestion
I see now why you were using subtraction, but it wont return colors that are always positive, which is definitely an issue!
I see!
But I also think it's odd to provide 0-255 value under the guise of a single color, say "red" and then use that to scale an existing color. It's just weird logic
You mean the conversion logic?
I was using it to accept int parameters
Because that was the issue I was having, Event Trigger didn't update realtime as I updated my method's parameter types
It works ๐ฎ
Thanks everyone! ๐
Could anyone help me make a roll mechanic (like, roll a few units in a direction with editable stats and the roll decreases your collision by a bit)? I tried making it myself, looking for it online even using chatGPT but I can't for the love of god make it work (2D)
this is my current code https://gdl.space/eguqutipav.cs
๐
Well,does it not work? What doesn't work?
I click R, the button for rolling and it won't roll. I have it bound to R in input manager axes, it doesnt work. i tried everything but it does nothing
Well, where in the code would your roll start?
See for yourself. Add a debug log in there and see if it prints.
But to be honest, if you just started, you should probably go !learn the basics first.
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
what should I change to make this work ๐ญ
Did you confirm that it doesn't work?
so us more of the code
Yes
By adding a debug log I mean
Yes
Share the updated code