#💻┃code-beginner
1 messages · Page 538 of 1
that could also work
im starting to think im overengineering it a bit since ill probably have 3 "parts" max to a sentence
in that case, make an enum for each sentence part
but ill give it a proper think after resting
whys that?
why don't you think the blend tree is changing?
so that you can define the valid kinds of sentences in the inspector
I guess you could just hard-code it in the script, too
i see what you mean
Here for example is the discrepancy
note that your blend tree is invalid, so that's not helping. two of the points are too close together
Oh yeah, this is just how you preview the blend tree
that way i can easily identify what kind of "part" it is and just check the order
The idle tree's x and y never change
The sliders have nothing to do with the default parameter values
(or the current parameter values, if you're in play mode and have an animator selected in the scene)
You can ignore them
aight im off for tonight thank you very much for the help!
no prob (:
No, it really is always 0,0 no matter what the x and y parameters are
I use SerializeReference quite a bit for making things like "filters" and "scoreres"
I can record a gif if it helps
Your blend tree is invalid
That's probably not helping
I think that's a bug, whenever I re-enter the tree, it is displayed correctly
Okay, that looks fine
Are you not seeing the animations playing at runtime?
I did just go and check on a VRChat avatar -- changing the sliders while live-linked to an animator in the scene does, indeed, affect parameter values
i was thinking of the behavior when outside of play mode, where the sliders have nothing to do with the actual parameter values
(for me, they're often things like "3.06e-10" or "NaN")
Hm, do I have to expose the parameter somehow? I remember this is kinda the case in the audio mixer
No, you don't
Like, how does Unity know these are all the same
Oh
You're talking about the position of each motion on the blend tree
The names are coincidentally similar
Perhaps me naming them "x" and "y" was not very helpful..
It basically describes the player's input axis
This blend tree has four motions in it
They're at these positions:
[0, 0]
[1, 0]
[-1, 0]
[0, 1]
I randomly picked two parameters from my avatar. I wound up with "Constant/One" and "Voice"
unsurprisingly, the first one is always 1
Ah, for me this is empty
did you make x and y ints
How did you get "Constant/One"
Oh yeah you used integers
that's why
I glossed over that entirely
blend trees use floats
I made them as parameters of the animator
Delete them and re-create them as floats
I wonder if x and y are just the default names it plunks in there
Hi, I don't know if you can help me with this code. This code is supposed to make the YXZ axes appear when an object appears but it doesn't move it with the axes.
the funny thing is that, under the hood, they're all floats anyway
Please use a paste site for large amounts of code
!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.
is that code
No i actually named it that. Anyway, thanks for the help, this works :D
public class GizmoHandler : MonoBehaviour
{
public enum Axis { X, Y, Z }
public Axis axis;
private Plane dragPlane;
private Vector3 dragStartWorldPos;
private bool isDragging;
public void StartDragging(Vector3 hitPoint, Transform parentPiece)
{
// Crear el plano de arrastre basado en el eje seleccionado
switch (axis)
{
case Axis.X:
dragPlane = new Plane(Vector3.up, parentPiece.position);
break;
case Axis.Y:
dragPlane = new Plane(Vector3.right, parentPiece.position);
break;
case Axis.Z:
dragPlane = new Plane(Vector3.forward, parentPiece.position);
break;
}
dragStartWorldPos = hitPoint;
isDragging = true;
}
public void HandleDrag(Vector3 hitPoint, GameObject parentPiece)
{
if (!isDragging) return;
Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
if (dragPlane.Raycast(ray, out float enter))
{
Vector3 dragCurrentWorldPos = ray.GetPoint(enter);
Vector3 dragDelta = dragCurrentWorldPos - dragStartWorldPos;
// Mover la pieza y el gizmo
switch (axis)
{
case Axis.X:
parentPiece.transform.position += new Vector3(dragDelta.x, 0, 0);
break;
case Axis.Y:
parentPiece.transform.position += new Vector3(0, dragDelta.y, 0);
break;
case Axis.Z:
parentPiece.transform.position += new Vector3(0, 0, dragDelta.z);
break;
}
dragStartWorldPos = dragCurrentWorldPos; // Actualizar el punto inicial para el siguiente frame
}
}
public void StopDragging()
{
isDragging = false;
}
}
Help triggering a beginner simple collision
If you can help me with the code
wow... that makes sense but feels cursed. i miss 10 seconds ago when i didn't know this
This is abused heavily for advanced VRChat nonsense
Almost every parameter on my avatar is a float so that it can be used in gigantic direct blend trees, but they're treated as bools by VRChat
wait how does that work for ints
theyr'e exposed as int32s, right?
but float32 doesn't work for higher values of int32
float32:max_safe_int is lower than int32:max_value
where?
in the scripting api
you mean how you can get an animator parameter as an int?
both getting and setting
Hey, I made a build of a game and send it to someone and got these errors in Player.log
The referenced script (Eggflation.Manager.MenuManager) on this Behaviour is missing!
The referenced script (Katsis.Manager.OptionManager) on this Behaviour is missing!
The referenced script (Eggflation.Menu.AchievementButton) on this Behaviour is missing!
The referenced script (Eggflation.Menu.AchievementButton) on this Behaviour is missing!
The referenced script (Eggflation.Menu.AchievementButton) on this Behaviour is missing!
The referenced script (Eggflation.Menu.AchievementButton) on this Behaviour is missing!
The referenced script (Eggflation.Menu.AchievementButton) on this Behaviour is missing!
The referenced script (Eggflation.Menu.AchievementButton) on this Behaviour is missing!
The referenced script (Eggflation.Menu.AchievementButton) on this Behaviour is missing!
The referenced script (Eggflation.Menu.AchievementButton) on this Behaviour is missing!
The referenced script on this Behaviour (Game Object 'MenuManager') is missing!
A scripted object (probably Eggflation.Manager.MenuManager?) has a different serialization layout when loading. (Read 32 bytes but expected 92 bytes)
Did you #if UNITY_EDITOR a section of your serialized properties in any of your scripts?
The referenced script on this Behaviour (Game Object 'MenuManager') is missing!
A scripted object (probably Katsis.Manager.OptionManager?) has a different serialization layout when loading. (Read 32 bytes but expected 364 bytes)
Did you #if UNITY_EDITOR a section of your serialized properties in any of your scripts?
The referenced script on this Behaviour (Game Object 'AchievementButton') is missing!
However I can't reproduce these errors on my machine, either inside Unity nor with the build, would anyone know what they could be related to?
(There are some UNITY_EDITOR things but it's related to an external library (Live2D) and I don't really have controls over that)
What are the values inside an empty array element?
Alright guys I haven't touched Unity in 5 years but I did learn C++, I got a 2D platform, and IDK how to use something like blender, how can I make a little sprite guy with some movement to get a game started?
any programs for making sprites?
how do I access game data like sprites in C#?
You can look up some free assets or draw your own.
The movement you'll need to code(or get an asset for it)
Sprites as in sprite assets, have Sprite type in code. You can find it all in the docs.
I do plan to program the movement, but I have no idea where to start since comparing C++ to C# is like comparing Fortnite to iRacing
They're not that different really.
But you should probably start by learning the C# basics.
There are plenty of resources online, including the official MS manual.
Alright, thanks
{
rb.velocity = Vector2.zero;
position *= speedMult;
rb.velocity += position;
} ```
i have this impulse script that is supposed to toss a ball towards the mouse position.
```mousePos = Input.mousePosition;
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
position = (mousePos - transform.position);```
all pretty basic stuff, but theres one thing i dont understand, if i put the mouse in a relaively far position above the ball, the ball will be tossed up to about 90% of the way to the mouse... if i put the mouse closer above the ball it will only travel about 30% of the distance to the mouse... shouldnt the relative distance traveled always be the same? since i just calculate a vector?
this feels like a mathbook question lol
Also if thats just the default, is there a way to make the ball be tossed a fixed relative distance? like always 70 percent of the distance to the mouse?
if anyone gets the chance, please look over my "Help triggering a beginner simple collision" thread 
Why did you delete it? I just replied there.
I closed the thread since it was resolved :o
Oh, that las message was 30 min ago...
you answered me and it worked :D I was using wrong cosole.log instead of debug.log
Ok, at least make it clear that the issue is solved
because it felt like you're gaslighting me
what xD
sorry not my intention
how should I better "mark as resolved" future threads instead of closing them?
Donno. But you could just keep it open and replied that it's solved or something.
oh okay, I figured I just close to reduce clutter :o
thanks for helping anyway!
Anyways, glad that solved it
Watching Brackeys tutorials to learn Unity, obviously they are quite old, so when he's talking about character movement, I hover over the code in VS Studio and it says "Interface into the **Legacy **Input system."
Does that actually cause any issues?
Not really, just interesting that it's legacy, you know, because the tutorial is from 6 years ago
Yeah. Things change fast in tech.
hi y'all, very basic question, I need to get the time but with millisecond accuracy to run some loops. How can I access this ?
Time.time and multiply by 1000
Thanks. Do I need to add some libraries on top like "with something" ?
I am not sure how the things with the with field are called
sorry the "using"
no it's a unity built in thing
ok thanks
A namespace using?
The Time class is in UnityEngine:
https://docs.unity3d.com/ScriptReference/Time.html
Unless you deleted it, this should be default in all ur scripts im pretty sure, and it includes Time
ok thanks
thanks, and now for all linear algebra operations like matrix rotation, multiplication, inverse, singular value decomposition etc is there a library that we can use ?
Depends on what exactly you need and trying to achieve.
There's a Mathf class in unity that implements some math operations.
thanks! I am trying to estimate a rotation matrix M from data, and I need to do decompose it into U Sigma V (svd) so I can get thet the U*V that I need ( to ensure that the result is a rotation matrix). I will check in Mathf
No clue what most of it is, aside from maybe a rotation matrix. Or rather a transformation matrix, because it usually includes information about object position, rotation and scale.
There's a Matrix4x4 class for working with matrices. It has some methods to translate and rotate it, so you could probably use that:
https://docs.unity3d.com/ScriptReference/Matrix4x4.html
But maybe there's a simpler way. Can you not explain what you need it for?
right, but I cannot do this here, it is in order to use an external frame of reference (from a Optitrack system), so I need to compare the points generated by that system and the coordinates of the headset so they can agree on a common system of coordinates
the issue being that the X and Z axes of the headset are arbitrary, and the origins are not the same for both frame. It is a relatively simple least squares problem so I just need matrix multiplication, inverse, and in order for the estimated matrix to be unitary I need to do svd on it, it could work without but I think it will be more accurate with that
the rotation matrix is between these two frames of reference
I know how to do it on python or matlab but this is the first time I use C# and unity
If you can do it in math, you can probably code it from scratch in any language.
Basic math operations are part of the basics.
right. I will try this
it is just that python and matlab have build in functions for svd, but if we can do multiplication and transpose already I think it is a good step
Im new to using c# and I was wondering how to I make a game object kinda leap forward at the start and just keep going after that?
Add a rigidbody and a collider to it, and apply an impulse force on start or something.
alright thanks
I was looking at the documentation, it seems that in the Unity.Mathematics/src/Unity.Mathematics
/svd.cs there is one thing that should work: [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static quaternion svdRotation(float3x3 a)
{
singularValuesDecomposition(a, out var u, out var v);
return math.mul(u, math.conjugate(v));
}
}
so to access it I guess I should type Mathematics.svd.svdRotation(Matrix) ?
scratch that it's not what I need. I will keep trying
public static class TimerManager : MonoBehaviour
{
List<Timer> Timers = new List<Timer>();
void Update()
{
foreach (Timer Timer in Timers)
{
Timer.Update();
}
}
public Timer NewTimer(float Duration,bool Repeating)
{
Timer Timer = new Timer(Duration,Repeating);
Timers.Add(Timer);
return Timer;
}
}
```is this a bad way to handle timers
or should i make a monobehavior Timer, without using a TimerManager
each timer definitely shouldnt be its own monobehaviour, but i also am not sure that TimerManager needs to be one either.
if this suits your use case then its not a bad way. i just dont exactly see what you'll be doing with these timers. i assume when the timer is returned you're subscribing to some delegate to be notified of when its done.
one thing you should consider is when NewTimer and Update runs though. Lets say you have a few other instances that wanna add a timer. if some objects add it before TimerManager's Update and some other objects add to it after update, you'll have some inconsistencies even though everything happened in one frame
i want to avoid using monobehavior but i need the built-in Update() function.
also if i "null" the timer, wont this cause problems, since its in the list. do u know how i can fix this
i know about pointer casting, i just didn't think it'd turn up here, i thought it was just converted normally
thanks for the answers
you dont need to rely on update/monobehaviours at all, but either way id still try to guarantee that this Update runs at a specific time. before or after all the NewTimer calls are done in a frame
and instead of just setting the reference in the list to null, just remove the timer from the list.
yes if its null and you try to call a function on it, it will give an error
cant i avoid that tho, ngl feels very tedious if i want to destroy some item class with a timer attached
this doesnt make sense with the code youve shown above. from the above it doesnt look like timer is a monobehaviour, so it doesnt matter if you destroy objects. as a regular c# class the timer wont just magically get set to null also, because the list still contains a reference to it
oh nvm ur right
hello?
Is it me you're looking for?
There is fire in your eyes...
Facing this weird error in Unity 6 while using new input system. Never faced this in earlier versions of unity. Please help. Following is my script:
https://hastebin.com/share/obukacecop.csharp
public class Movement : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
private PlayerControls playerControls;
private void Awake()
{
PlayerControls playerControls = new PlayerControls();
playerControls.PlayerActions.Move.performed += Move_performed;
}
private void Move_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj)
{
Debug.Log("MOVING");
}
public Vector2 GetMovementVectorNormalized()
{
Vector2 inputVector = playerControls.PlayerActions.Move.ReadValue<Vector2>();
inputVector = inputVector.normalized;
return inputVector;
}
private void OnEnable()
{
playerControls.PlayerActions.Enable();
}
private void OnDestroy()
{
playerControls.PlayerActions.Disable();
}
}
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Use a bin site that shows line numbers. !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.
We'd need to know which lines are which. Use the paste links to share code.
you never set playerControls. in Awake, you're creating a local variable instead of assigning to the field.
Check if player controls is null.
!unmute 433502248828665857 Don't spam the same link multiple times next time.
iota777 was unmuted.
thank god
I watched a codemonkey tutorial, they did it like that, does it not work in unity 6?
its not null
it doesn't work in any version. you did it wrong
It would seem it is
ohh
what do i do instead?
You've never initialized it
PlayerControls playerControls = new PlayerControls();
this is a variable declaration. you're doingPlayerControls playerControlstwice. you have 2 separate variables. you only initialized one, the local variable that the rest of the script doesn't see
instead of creating that extra variable, assign to the existing field
What you're looking at in Awake isn't the same as the class' member
remove the PlayerControls in the declaration in Awake to turn it from a declaration into an assignment.
[SerializeField] private PlayerControls playerControls()```
you mean this?
I removed the Awake
oh
that is not what i said to do
Thank you, it worked
that is also not what i said to do
I got it man
2 times I was initializing it
Can u guys help me out with this i need for a level project
2 times you were declaring it. you only initialized once, which is correct, but you initialized the wrong one (the one that shouldn't have been there)
You've declared it once as a class variable and another time in Awake - two completely different variables.
Understood
Also any good tutorial or document where I can know about Cinemachine 3.1? They have changed all of it
please share your error and code in a way we can actually use
!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.
Alright
Im using a school pc so its kinda hard to rn
How would i put the errors in just type?
as a comment?
no, screenshot the error, but actually focus on it
Okok
We'd need to see line 10 where you're trying to use some member named useEvent - the code shown doesn't seem to represent the error.
Whenever i click on the error it sends to that code
and its the only code which features that useEveny
Maybe you've changed the code or that's an old error
was fine until i added this code
seems to line up just fine, it's just really hard to make out because of the size
You've changed some lines of code and have not saved/compiled the script.
anyways, have you at least read the error
are you missing a using directive?
first error says
'Interactable' does not contain a definition for 'useEvents' and no accessible extension method 'useEvents' accepting a first argument of type 'Interactable' could be found (are you missing a using directive or an assembly reference?)
Your error line is here and not where you've suggested
The type or namespace name 'InteractableEvent' could not be found (are you missing a using directive or an assembly reference?)
So what would i do to fix
my c# skills r terrible rn
im not seeing either of these classes in the docs. are you using some library for them? if so, you are missing a using directive, as the error says
Either make sure interactable has that member or don't use that member. You may be referring to a different interactable if you believe it does have said member.
What foes this mean
or is Interactable your own class?
It means you didn't write/design your code and need to show or explain where/how you got it.
Pk ill send the video
In this video We're going to expand our interaction system to include the use of Events!
This is a really powerful way for us to quickly prototype and design our interactions!
Health Bar Tutorial
https://youtu.be/CFASjEuhyf4
00:00 Introduction
00:30 Unity Events Example
01:15 Interaction Event Script
01:53 Interactable Extras #1
02:25 Intera...
around 4mins
And how would i do that
uh, watch the tutorial?
Did i miss something in the vid or no
oh crap
useEvents is also defined around 2mins in
InteractionEvent is defined around 1min
if you're following a tutorial and something doesn't work, the first step should be to go back through the tutorial to see what you missed
Thank u
does Unity Learn support Firefox? I want to do the quiz for Prototype 1 and it sends me to this. I dont know where to really ask this question I didnt find a Unity Learn channel. do I need to put !bug in? I think I do...
🪲 To make bug reporting as quickly as possible, we made a bug reporting application for you. When running Unity choose Help->Report a Bug in the menu, or you can access it directly through the executable in the directory where Unity is installed. It will also launch automatically if you experience a crash.
📝 If your bug report is to do with Documentation, either an error, typo, or omission, you can report it by scrolling to the bottom of the page where you found the issue and click ‘Report a problem on this page’!
💡If your report is to do with a new feature idea, you can check the Unity Product Roadmaps page to see if your idea has already been planned.
For more complete instructions on how to report bugs, access: https://unity3d.com/unity/qa/bug-reporting
@vast stirrup How does this relate to this channel? Also don't cross-post.
oh ok sorry, im new. I do not know where this really belongs I just wanted some help or an answer.🙂
fogsight can you help me with some code?
just ask.. you'll have better luck
basically i am trying to place a building based on what the placer clicks in the ui
https://discussions.unity.com/t/character-flies-up-in-air/1566122
please help me here
yoo
can someone tell me why this won't work?
this issue started after i moved them into functions
the debug's are fired
but not the movement
you'll have to be more detailed..
odds are you wont have people show u exactly what u need.. but we'll help debug and fix things u may already have..
do u have anything done already? or code that ur working from?
I'd start debuging the variables themselves
ya, ^
Hi, I have this so:
namespace Scenes.Snowstorm
{
[CreateAssetMenu(fileName = "SnowstormConfigData", menuName = "Config/SnowstormConfigData")]
public class SnowstormConfigData : ConfigData {}
}
How can I create an instance of it in the editor via c#?
I tried doing this:
//sceneName is set to Snowstorm when executing the thing
var className = $"Scenes.{sceneName}.{sceneName}ConfigData";
var classType = Type.GetType(className);
var so = CreateInstance(classType);
var soPath = Path.Combine(sceneDir, $"{sceneName}ConfigData.asset");
AssetDatabase.CreateAsset(so, soPath);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
Also tried this var so = CreateInstance($"Scenes.{sceneName}.{sceneName}ConfigData"); and this var so = CreateInstance($"{sceneName}ConfigData"); and not a single approach worked.
I would really appreciate someone's help cuz I'm lost :/
Forgot to mention in the original message, ConfigData class inherits from so and this does appear in the create menu and works fine when manually created.
if (horizontalInput != 0)
{
rb.velocity = new Vector2(horizontalInput * characterSpeed, rb.velocity.y);
Debug.Log($"Moving {(horizontalInput > 0 ? "Right" : "Left")}");
}
else
{
Idle();
}```
one improvement I can suggest is just using a single variable for ur Horizontal movement..
no need for soo many if/else statements.. esp since one of em basically just cancels each other out..
if u use horizontalInput with Input.GetAxisRaw("Horizontal"); <-- then
horizontalInput is either gonna be -1, 0, or 1
then u can just multiply that by ur speed..
it'll automatically go left.. and go right
public class PlaceBuildChecker : MonoBehaviour
{
[SerializeField] private TileBase expected;
private TileBase test;
[SerializeField] private Tilemap tilemap;
[SerializeField] private BuyScreen BuyScreen;
public void SetExpectedTile(TileBase newTile)
{
expected = newTile;
Debug.Log("Nieuwe verwachte tegel ingesteld!");
}
private Vector3Int PointedCell
{
get
{
Vector2 screenPos = Input.mousePosition;
Vector3 worldPos = Camera.main.ScreenToWorldPoint(screenPos);
worldPos.z = 0;
return tilemap.WorldToCell(worldPos);
}
}
public bool IsValid(Vector3 mouseWorld)
{
Vector3Int cell = tilemap.WorldToCell(mouseWorld);
TileBase tile = tilemap.GetTile(cell);
return tile == expected;
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Vector3Int clickedCell = PointedCell;
TileBase tile = tilemap.GetTile(clickedCell);
if (tile == expected)
{
Debug.Log("Je hebt op een verwachte tegel geklikt!");
if (BuyScreen != null)
{
BuyScreen.ShowPanel();
}
}
}
}
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Tilemaps;
public class TileSelector : MonoBehaviour
{
[SerializeField] private PlaceBuildChecker placeBuildChecker;
[SerializeField] private TileBase tileToSet;
[SerializeField] private Button setTileButton;
void Start()
{
if (setTileButton != null)
{
setTileButton.onClick.AddListener(OnSetTileButtonClicked);
}
}
private void OnSetTileButtonClicked()
{
if (placeBuildChecker != null && tileToSet != null)
{
placeBuildChecker.SetExpectedTile(tileToSet);
}
}
}
yes its really low
thanks for the help
and what part of it isnt working?
or where are u stuck..
tile selector basically needs to do it needs to copy the position and bind to the button so it can replace the tile
wierd tho worked fine when i didn't move them into functions maybe i forgot to save ;/
i wanna bind the tile to the button efficiently there is where im stuck
ya, if ur talkin about the velocity.. rigidbodies tend to take quite a big number to get it moving
if u put a physics2d material on ur collider w/ zero or low friction u can get by with using smaller values
so if i press one of these i want the too spawn on the wood i touched
can u already select the tile and its position and everything?
is it finding out and assigning what "type" of house is where ur having trouble?
ýeah if i press the wood the ui shows up the problem is your 2nd line
ahh okay 👍 just trying to figure out the exact issue
huh but that is the issue
yea, i was just confirming the specific problem as at first the question was a bit broad
the easiest way imo would be to have an array of prefabs..
[SerializeField] private GameObject[] housePrefabs; // Array of house prefabs to spawn
^ could have (1) prefab for each house type..
then to spawn it or select it it'd just be
housePrefabs[0], [1], or [2] for example..
for determining which house u select i guess a ScriptableObject could work
public class TileData : ScriptableObject
{
public TileBase tile;
public GameObject housePrefab; // Associated house prefab
}``` like this..
if u did Scriptable objects u wouldnt even need a list.. (u'd just have a different prefab for each house)
tried to do that with the tileselector
because i already know the location
i suck at tilemaps.. im reading some stuff myself to figure out what the best approach would be
i have a parkour game but my character keeps flying into the celing
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 5f; // Speed of player movement
public float jumpForce = 5f; // Force applied when jumping
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
rb.useGravity = true; // Ensure Unity's gravity is applied
}
void Update()
{
Move();
if (Input.GetKeyDown(KeyCode.Space) && IsGrounded())
{
Jump();
}
}
void Move()
{
float moveX = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");
Vector3 moveDirection = new Vector3(moveX, 0, moveZ).normalized;
Vector3 moveVelocity = moveDirection * moveSpeed;
rb.linearVelocity = new Vector3(moveVelocity.x, rb.linearVelocity.y, moveVelocity.z);
}
void Jump()
{
rb.linearVelocity = new Vector3(rb.linearVelocity.x, jumpForce, rb.linearVelocity.z);
}
bool IsGrounded()
{
// Check for grounding to prevent floating or upward dragging
return Physics.Raycast(transform.position, Vector3.down, 1.1f);
}
void FixedUpdate()
{
// Extra safeguard to force Rigidbody's velocity in case of erratic behavior
if (rb.linearVelocity.y > 0 && !Input.GetKey(KeyCode.Space))
{
rb.linearVelocity = new Vector3(rb.linearVelocity.x, 0, rb.linearVelocity.z);
}
}
}
have you tried putting the gravity to 0 in the inspector?
for my game its a top down game so i used 0 gravity scale. the mass changes the speed of the character for me
might be the isGrounded function
it removes the infinite jumps
i think whats happening is the script doesn't know what exactly is ground and what is not
so you might have to make a method to make sure its grounded
it does know i added stuff
What goes wrong?
Hey, I moved question to the #↕️┃editor-extensions since it seems more fitting, where should we continue the conversation?
Why does Unity assume that when I specify a color, I want the alpha to be zero? That is so counterintuitive there must be a good reason for it.
Color is a struct, so you can't have field initializers (in the version of C# Unity is using, at least)
Color is just a vector4, and like the default values for vector2 and vector3, it's all zeroes
Because 0 is the default value for a float
&& @swift crag That makes sense. So, why are the static colors also set to a = 0?
I was using Color.blue
Color.blue does not give you a color with an alpha of zero
Or does that only modify the RGB?
i have a parkour game but my character keeps flying into the celing
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 5f; // Speed of player movement
public float jumpForce = 5f; // Force applied when jumping
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
rb.useGravity = true; // Ensure Unity's gravity is applied
}
void Update()
{
Move();
if (Input.GetKeyDown(KeyCode.Space) && IsGrounded())
{
Jump();
}
}
void Move()
{
float moveX = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");
Vector3 moveDirection = new Vector3(moveX, 0, moveZ).normalized;
Vector3 moveVelocity = moveDirection * moveSpeed;
rb.linearVelocity = new Vector3(moveVelocity.x, rb.linearVelocity.y, moveVelocity.z);
}
void Jump()
{
rb.linearVelocity = new Vector3(rb.linearVelocity.x, jumpForce, rb.linearVelocity.z);
}
bool IsGrounded()
{
// Check for grounding to prevent floating or upward dragging
return Physics.Raycast(transform.position, Vector3.down, 1.1f);
}
void FixedUpdate()
{
// Extra safeguard to force Rigidbody's velocity in case of erratic behavior
if (rb.linearVelocity.y > 0 && !Input.GetKey(KeyCode.Space))
{
rb.linearVelocity = new Vector3(rb.linearVelocity.x, 0, rb.linearVelocity.z);
}
}
}
Can you enclose that in a code block please?
how do i do that? srry im new
!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.
```csharp
[your code here]
remove the slash
@verbal heron Use paste site in the bot message
@verbal heron I recommend https://gist.github.com
gists seem more permanent.. hate to add one just to share it and then have to go and delete it.. all the others are more temporary.. dont have to deal w/ accounts either
I like Gists and their permanence so I can refer back to them later if I need a reminder. Also, if you post on StackOverflow or another forum, you can leave the gist up without having a branch dedicated to it on GitHub, so people who are looking for answers after you can still have context.
oh yea.. if ur archiving ur code or useful scripts.. 💯 prefer gists..
idk how to use it
just use one of those paste bin websites..
u paste u code.. hit the 💾 save icon and the URL will refresh
copy and paste that here
https://paste.myst.rs/ is my favorite.. b/c my theme is always set-up...
no suprise flash-bangs, oh and can post multiple code snips on a single page.. (good for systems)
i not working
//like this. make sure theres a line-break
but ur code block is a bit long.. sooo if u could use one of the links on the embed u got sent earlier.. that everyone keeps telling u to use
that'd be great.. ☕
lol.. ` <-- gotta use three back-ticks
at the top and the bottom
What is not working?
discord code formatting
alr
cs using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class PlayerController : MonoBehaviour
{
public float moveSpeed = 5f; // Speed of player movement
public float jumpForce = 5f; // Force applied when jumping
private Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
rb.useGravity = true; // Ensure Unity's gravity is applied
}
void Update()
{
Move();
if (Input.GetKeyDown(KeyCode.Space) && IsGrounded())
{
Jump();
}
}
void Move()
{
float moveX = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");
Vector3 moveDirection = new Vector3(moveX, 0, moveZ).normalized;
Vector3 moveVelocity = moveDirection * moveSpeed;
rb.linearVelocity = new Vector3(moveVelocity.x, rb.linearVelocity.y, moveVelocity.z);
}
void Jump()
{
rb.linearVelocity = new Vector3(rb.linearVelocity.x, jumpForce, rb.linearVelocity.z);
}
bool IsGrounded()
{
// Check for grounding to prevent floating or upward dragging
return Physics.Raycast(transform.position, Vector3.down, 1.1f);
}
void FixedUpdate()
{
// Extra safeguard to force Rigidbody's velocity in case of erratic behavior
if (rb.linearVelocity.y > 0 && !Input.GetKey(KeyCode.Space))
{
rb.linearVelocity = new Vector3(rb.linearVelocity.x, 0, rb.linearVelocity.z);
}
}
}
i did
i have a parkour game but my character keeps flying into the celing
- Ridd1er
(OG question buried ^)
@verbal heron Pick one of the links (except first one) and post code there. !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 did
hit the save button, and paste the URL it gives u here then..
@verbal heron You might need to tab out from the Fortnite you are playing to comprehend this.
lol.. but he's almost Top 5 😅
its creative
neither here nor there.. once u paste a good link to your code we'll be able to help..
@verbal heron Why are you doing the same thing again and again?
Do you see links in the message?
yeah
click them
i use myst
paste your code there, click generate link and post the link
i have a parkour game but my character keeps flying into the celing
a powerful website for storing and sharing text and code snippets. completely free and open source.
did you try lowering the jumpForce ?
i spawn and i start flying even with jumpforce 0
what is this supposed to do rb.linearVelocity = new Vector3(rb.linearVelocity.x, 0, rb.linearVelocity.z);
why 0
i just noticed two of em
Extra safeguard to force Rigidbody's velocity in case of erratic behavior
huh?
1 in update and 1 in fixed
it removes vertical movement
have u debugged ur velocity value and watched it?
its ur Y velocity variable wherest lies the problem
yeah but chatgpt added that after i asked him.....
and how ur managing ur rb.velocity directly
i could.. but that doesn't help you at all
dont make a game with a bot if you have no clue what code its telling you to use
first advice would be to stop trusting chatgpt
yeah.....
ok
at very least you should know what the hell you're copying and why. Its still wont help you fix it if its broken
it gets confused very simply when encountering someone thats learning
yeah
- its a yes, man.. it'll str8 up change its response just b/c u asked it too.. (even if by accident)
soo.. why do u have two rigidbody functions?
he added that aswell...
anyway the y velocity would only be set to 0 before doing a jump, so if anything it should go in the Jump function
and u know u shouldnt typically messs w/ rigidbodies in the Update() loop
u know the difference in the two right? the Update vs the FixedUpdate
yea, he's too far gone already
why are you here if GPT can fix it for you
he cant
time to scratch that conversation.. (and this is why ai == bad)
then stop using it
i am
all that time wasted
yessir
do u know what ur code is doing?
a lil bit
i suggest if u want the fast and easy way... thats marginally better than chatgpt.. is start working from a good video tutorial
it conrtolss the players movement, jumping and the speed and jump hight
most ppl will say stop what ur doing, start !learn Unity Learn material, do not pass go, do not collect 200 dollars
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
i lowkey challanged my self to make a game just with ai
challenge successfully failed i guess
that works only if you know what you are copying
yessir
I don't care for it myself.
what a joke
should i download vs or vs code?
whats the point?
download whichever one you want
+1 VSCode
rn, i got vs code but i dont have the suggested keywords
why even make a game if ur just letting the ai do it for u.. lol
i bet u get ur art from midjourney too
You need to add the Csharp and Unity extensions.
also please dont suggest AI crap in a channel about coding..
these?
or do i need more
idk if i need to somehow activate them
follow the thoroughly
Removed. Sorry.
yes
@verbal heron the rb already has gravity..
the velocity code u have conflicts w/ that.. + u do it again in fixedupdate
I highly recommend learning how to create a profile in VSCode specifically for Unity.
two questions
first, how do i do global scope
Update -> every frame
FixedUpdate -> every X frames (locked for physics)
WDYM by "do global scope"?
im doing a minigolf game, and i want the game to load the next course (?) after the ball lands in the hole
That's going to be your scene manager.
and assigning courses by the hole is clunky
I fail to see what this has to do with your question about "global scope"
its kinda difficult bc they're using mac and im using windows
that makes literally 0 difference
i want a global list of maps to refer to from the hole code
Create some kind of GameManager or CourseManager script and manage it there. You can make it DDOL.
Basically look up "Unity DDOL singleton"
cool
and its globally accessible yuh?
One of the main features of a singleton is the use of a static reference variable that lets you access it from anywhere.
Update is for Input and logic, and Fixed is for physics.. u can assign the velocity every update and fixedupdate will use whichever value it has when it runs.. but u shouldn't do this more than necessary.. and a lot of the times you can use functions like rb.AddForce() to let Unity do its own thing w/ the velocities.. but if ur gonna modify them yourself i would do it as little as possible.. and know when and how to.. b/c if for example you add force and then call rb.velocity = blabla.. ur gonna overwrite it immediately..
noic
rb.velocity = new Vector3(moveDirection.x, rb.velocity.y, moveDirection.z); doing something like this can be paired w/ AddForce if ur Force is on the Y b/c if u notice the new Vector3... ur changing the x, and the z
but we pass in the rigidbodies own velocity into the y
void Update()
{
Move();
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
Jump();
}
void Move()
{
float moveX = Input.GetAxis("Horizontal");
float moveZ = Input.GetAxis("Vertical");
Vector3 moveDirection = new Vector3(moveX, 0, moveZ).normalized * moveSpeed;
rb.velocity = new Vector3(moveDirection.x, rb.velocity.y, moveDirection.z);
}
void Jump()
{
rb.velocity = new Vector3(rb.velocity.x, jumpForce, rb.velocity.z);
}```
i wonder what this would do in ur project 🥄
split the inputs to their own method like Input() keep it in update, move Move() to FixedUpdate
for jump ud probably still wanna cancel gravity as mentioned cs void Jump() { rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.z); rb.velocity += Vector3.up * jumpForce; }
alr
+= just means this = this + that
ik
well wasn't sure if chatgpt had lied to ya or not..
same
guys what thing is this dropdown on for u guys?
yk where it says "unity"
what is it for u guys
bc i got the suggested keywords like (Input) and Keycode
but i dont got GetObject
unless i have to attach the script
to the item first
yeah that worked
no ddol tho since am not using scenes
what matters is that at the bottom bar says "Assembly CS-Sharp"
also please ease with the vertical messages
mb
dyk how i can get the getObject suggestion?
anyways second question
is there some means to subtype off a gameobject
wait. first screenshot the entire editor.
Assets\Scripts\PlayerMovement.cs(39,10): error CS0111: Type 'PlayerController' already defines a member called 'Move' with the same parameter types
alr, ill ss it with the xtension too
thats not the entire editor
so its working just fine
word salad but i mean like
i have a gameobj with children for a board, obstacles, spawn point n such
and i want to access these through a shared interface
and what is getObject supposed to be exactly ?
i was showing u how i dont have the getObject keyword
as a suggestion
those are GameObjects
https://docs.unity3d.com/6000.0/Documentation/ScriptReference/GameObject.html
ohhh
you declare types not methods for variable
and am wondering if i can have a prefab obj with these as children, and to access them in some neat way
*be able to
tbh you should follow the !learn pathways you wil be better off
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
these are people who made the program ^
where do u reccomend i start bc im learning python in skl so im sure i can transfer some skills
do Essentials -> Junior Prog, and go from there
i js dont wanna waste my time learning things i already have
alr tysm
most of the essentials like configure editor you did already so no worry, just check out where eevrything is in the editor
just have a references in the inspector and create a get property to interact with them
there are ways to programmatically access the children but its not very precise / inefficient
if you have components its easy to store them in arrays
Gameobject / Transform works too but its pretty useless most of the time
public class Board : MonoBehaviour{
[SerializeField] private Obstacle[] obstacles;
public Obstacle[] Obstacles=>obstacles;
//etc
}```
why the access modifiers
Have you ever done Unreal development?
and.. i guess why is it inheriting from monobehaviour
this sounds more like what you do in Unreal
no
in Unity, you don't subclass GameObject or otherwise create more "specific" kinds of game objects
so it can be placed on a gameobject(now you can reference stuff via inspector), then you can simply make it a singleton
you just attach components to game objects
i ugess
yk how if u press space or enter, the suggested keyword would replace the word ur typing, how do u avoid that?
I do this very commonly. I often start with a "bag of data" that then gains functionality later on
i mean i was just gonna shove it into a StupidGlobalsClass.all_boards
and leave it as
escape key
or turn off the setting (i forgot where it is on VSCode)
anyways third question, is there a way to make/get "model groups" from a blender model
stupid wording but what i mean is, i want to make my game map in blender instead of playing lego with cube objects
you can import a model that contains many small objects in it
oh alr tysm
but in said map i need to f.e treat borders differently than the floor
tysm
so how/can do i do that without just importing multiple models and stitching them together
why not proto with ProBuilder, its similiar to blender for basic needs like grayboxing
i know 0 of blender sorry 
You can create small models in Blender, then create prefabs out of them in Unity and build your level out of those
Building the entire level directly in Blender sounds awkward for a couple of reasons
ama check rq if it runs on manjaro
If you use the same floor piece 1,000 times, you'll get 1,000 copies of that mesh when you import it into Unity
Probuilder is part of Unity.
You would also have difficulty adding behaviors to the objects in the level
in Unity, you can make a prefab that has a model and some components to give it functionality
then scatter that prefab around your level as needed
yeahhh i realized that half-way through writing that q
You'd need to either manually attach components to all of these Blender-imported objects, or write editor code to automatically do this
main appeal was actual control over the model
i mean, you can still make models in Blender
you just don't want to build the entire level into one giant FBX
cuz again, stitching cubes is a mental pain
oh yeah btw am i just unable to access consts from outside the class
const-ness has nothing to do with accessibility
you say that but if i remove the const modifier from my public const int AIM_LOCK_AIMING = (1<<0) it just works
show the relevant code
ooh, right -- I forgot about that behavior of const
lemme check if throwing static at it will fix it
it also makes the member static
as the error suggests, access it from the type itself
not from an instance of the type
read the message. Use the type name
standard C. const belongs to the class not an instance of it

there is no point to accessing it from an instance, yes
say you set a layer mask to one layer for a raycast. that is the layer it is meant to collide with? will it be blocked by things in other layers?
no
no it only hits whats in that layer
I have 2 objects in unity that are clickable with the OnMouseDown() function in unity, and one of the objects apears on top of the other. However, the hitbox for the first object covers over the one for the second, making it unclickable, this isnt helped by the fact that object 2 is a child of object 1, but im trying to figure out a way to make them both clickable at once
how do i animate an object without giving it full on physics
am trying to do a cool "yeet the map offscreen on finish" animation and giving the floor rigidbody feels wrong
specifically i want it to accelerate along the y axis
asking here since i assume there's already an inbuilt for this
tweening or something like that
Use a RayCastAll probably or get it from the EventSystem version.
Use the IPointer interfaces
there is not going to be a "make the level fall down" component, but you can absolutely write one
adding an increasing amount to your Y position every frame would do the trick
i meant a "animate x object from point y to point z" function
or hell even transform a to transform b
libraries like DOTween will let you do this easily
yep, as mentioned Tweening
oh you meant that for me
aig ama look that up
worst case scenario ill bootleg some custom interpolation shit
tweening just uses interpolation
Tweening is basically Lerping on steroids
non-linear lerp 🤭
i have two scripts, Player health and Enemy Controller, in Player Health i have a method that takes away damage every 5 seconds and in enemy controller the enemy follows the player and if its 5 or under away it stops and im trying to get the Player Health method to work inside the stopping if statement. Can anyone tell me what i did wrong/ didnt include?
so you reposted it here while ignoring wha was said to you in #archived-code-general
good way to get help..
I just downloaded unity and have absolutely no clue what I’m doing. How should I start? Should I start by learning C++ or smth?
Free tutorials, courses, and guided pathways for mastering real-time 3D development skills to make video games, VR, AR, and more.
@hybrid finch #archived-code-general message
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using static UnityEngine.GraphicsBuffer;
public class PlayerHealth : MonoBehaviour
{
public int playerHealth = 100;
public int damage = 25;
public Transform enemy;
public float timee = 3.0f;
[SerializeField] private TMP_Text HealthDisplay;
private void Update()
{/*
if (enemy != null)
{
enemy = GameObject.Find("Enemy(Clone)").transform;
}*/
if (playerHealth <= 0)
{
Destroy(this.gameObject);
}
HealthDisplay.text = playerHealth.ToString() + "%";
/* if (enemy != null)
{
if (Vector3.Distance(transform.position, enemy.transform.position) < 6)
{
// EnemyTakeDamage();
}
}*/
}
public void PlayerTakeDamage()
{
timee -= Time.deltaTime;
if (timee <= 0f)
{
playerHealth -= damage;
timee = 5f;
}
}
}
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class EnemyController : MonoBehaviour
{
public Transform target;
private NavMeshAgent agent;
public bool isStopped;
private PlayerHealth health;
// public PlayerHealth playerhealth;
void Start()
{
agent = GetComponent<NavMeshAgent>();
target = GameObject.Find("PlayerBody").transform;
health = GetComponent<PlayerHealth>();
}
void Update()
{
if (Vector3.Distance(transform.position, target.transform.position) > 5)
{
agent.destination = target.transform.position;
agent.isStopped = false;
}
else
{
agent.isStopped = true;
health.PlayerTakeDamage();
}
}
}
@rich adder
mate use the links as stated in this message #archived-code-general message
this makes it very difficult especially on mobile
i did
hatebin
no you just plopped the code here as a message instead of sending the links
paste each script on the site, save , send link of each
hey mates, sorry, I'm ashamed to ask, but how do I get the ref to a script?
case: I have a playercontroller, which has an action (basically doDamage())
if(Input.GetKeyDown(KeyCode.Space)) {
Attack();
GameObject enemy = GameObject.Find("Enemy").GetComponent(typeof(EnemyController));
}
My Enemy GameObject has a public field "health". All i really wanna do is set health -= 1
I tried accessing with via GetComponent<EnemyController>() but that also didn't work.
(Using unity 6.0)
Choose the best way to reference other variables.
I have a navmesh agent and an array of objects, how do I make the navmesh agent choose the closest one?
do a distance check within a loop
how do I do the distance check though?
is there a way to calculate the length of the path instead of just the distance?
you can query for a path and then check how long it is
sure calculate the path to each object then walk the paths in code
You'll have to get the list of corners from the path and then compute the distance between each pair
if you have many objects you probably dont want to do all of that in one frame
You could make the process more efficient by sorting the objects by distance and then giving up once your best path is shorter than any of the remaining distances.
Imma try that then
I started the tutorial and I’m at a part where it says to use the arrow keys to move forward, backwards, left, and right but when I press the up and down arrows on my keyboard I move up and down not forwards and backwards. Do you know how I would fix this?
you'd have to show your current script and which specific page/lesson your on.
Also important to see your setups like pivot and its mode (local vs global)
how can i make it so it picks at random which one of the 2 backgrounds its going to pick?
put them in array, pick random index between 0 and max array length
img = images[Random.Range(0, images.Length)]
THANK YOU SO MUCH
does c not have a Pick() proc
*cshart .
c# and no it does not
and which one is better?
for generic game dev? nothing
some engine-specific langs do cool stuff
engine specific language isn't usually useful in the real world
so the language is bad because there is no Pick() method?
yep
thinking of organizing an objective system and im just like
what if i used a really big else if statement
im making the quests, that's fine. but im just like how do i organize this mess
or just a switch
your future self will wish you had been strangled at birth
but usually there is a better way like SOs and arrays
yeah p much
this sucks :(
i personally am used to abusing prototype subtypes
because i can do f.e var/quest_type = pick(subtypeof(/quest/generic_guard))
tho obviously thats not a thing in cshart
will have to figure out if theres some analog
i am at a point where i read that and it completely goes over my head i am cooked
did not think the inventory system was the easy part
who ever said inventories are easy?
they can be basic or get very complex, not usually easy though if you're a beginner
to be fair you can get fairly far with if and var spam
exponentially slower to get there but yes
if and var spam , no idea what you mean by that
if(equipping_to == SLOT_NECK) neck = item
else if (equipping_to == SLOT_HELMET) helmet = item
else if (equipping_to == SLOT_BOOTS) boots = item
else if (equipping_to == SLOT_GLOVES) gloves = item
yuh
am myself refactoring inventory from that (or well was gonna, and then gave up half way) to a type-based system
this would be very restrictive and not scale well, but sure it can get you the bare minimum
yeah duh
Hey! So having a quick issue. I haven't worked a lot with Vectors, and one of my issues right now is when I hover over my game object, it just...floats until I get off it. What I want it to do is move the X coordinate up 10, then when my mouse goes off it returns (I have a method for that which Ill add.)
Currently heres the code:
public void HandleHoverState()
{
glowEffect.SetActive(true);
rectTransform.localScale = originalScale * selectScale;
rectTransform.localPosition = Vector3.up + rectTransform.localPosition;
Debug.Log($"HandleHoverState");
}
Any ideas?
every tick it checks if you're hovering and if it does it moves up
It depends when and where HandleHoverState is getting called
i think theres a proc for "on hover start" but if not just have a is_elevated var or such
If it's every frame it will move every frame
Yeah, its in the update method. I need to see if what Lemons said works
so not really a vector problem
how do i generate a random number between -10 and 10, but have it be weighted like a bell curve
Sounds like you want a Gaussian distribution!
(with a bit of truncation)
I use this in my game https://discussions.unity.com/t/normal-distribution-random/66530/3
It'll need a little adjustment to clamp the number between -10 and 10
You can play with a calculator like this to find a decent standard deviation (the mean will be 0)
This gives a 98.7% chance of picking a random number between -10 and 10
mean is 0, standard deviation is 4
That code has you plug in a random number between 0 and 1, and it gives you a value from the curve
0 would be infinitely far left, and 1 would be infinitely far right
0.5 is the center of the curve
so in this case, I think you'd just need to do this!
float prob = 0.9876; // got that from the website
float margin = (1 - prob) / 2;
float sample = Random.Range(margin, 1 - margin);
return PeterAcklamInverseCDF.NormInv(sample, 0, 4);
It'll pick a random number that's not too close to 0 or 1 -- so that we stay in bounds -- and then computes the resulting value from the normal distribution
https://paste.ofcode.org/3aQpSVFKrBNWvL97uQxFvzQ
You can use this code -- no point in making that thing a MonoBehaviour :p
thats a lot more code than i thought jeez
thank youu i was NOT gonna figure that out myself 😭
also, i corrected this sample -- forgot to pass in the mean and standard deviation
The mean is the center of the curve, and the standard deviation is how wide it is
the default values of 0 and 1 would've given you numbers much closer to zero
can someone tell me why its behind the main menu?
i changed the layer but it still would go behind
is the main menu on an overlay canvas
canvas
Overlay canvas?
why am i colliding with the tilemap building here?
Layers don't really matter with UI
why wouldn't you?
you have a tilemap collider on it, no?
You've selected a sprite renderer
because the green outline is the collider and theres space
These are unrelated to UI rendering
An overlay canvas gets drawn on top of everything else after the rest of the scene renders
i do but isnt there space for my player to squeeze past?
so how do i not do that?
for reference, this is my player collider
hey guys :) So I have a working system where when my player get close to an interactable object, a white line is applied around it
https://paste.ofcode.org/5mAXkP3MEfuu8LNQDKxzKY (<--- the script for that)
Now, I'm trying to add a system that will display unique dialogue depending on which object is interacted with (upon it being highlighted and pressing E)
I have an IInteractable script that simply reads
{
void Interact();
}```
and an "InteractableObject" script that reads
```public class InteractableObject : MonoBehaviour, IInteractable
{
public void Interact()
{
Debug.Log($"Interacted with {gameObject.name}");
}
}```
I have the "InteractableObject" script applied to every interactable, and upon entering within range, it plays the debug log without any input.
Could anyone advise me the way I could Implement this "E to read a script" idea? I'm pretty knew and had help with the InteractableHighlighter :)
Ive tried watching video tutorials for this, but since my game is 2d and I already have a way to detect the closest object, I end up having to modify their code and it doesnt work anymore 
You will need to modify it a little to work with 2d. But this video does what you're looking for.
https://www.youtube.com/watch?v=LdoImzaY6M4
For example, use vector2 instead of vector3.
I'll try this one, thank you : )
And collider2d instead of collider.
I implemented the same system in a 2d game. So I can confirm the video does work.
How to make a smooth jump in 3D
(Sorry for my bad english its not my first language)
Hi im currently making a 3D platformer. Im working on the player jump but I just dont get a smooth jump. I tried looking for tutorials on youtube but every video is ether for 2D or for the CharacterController. But I need to use a Rigidbody for my use case. I want to make something like a mario jump.
For my jump im currently using:
rigidbody.AddForce(new Vector3(0f, jumpForce, 0f), ForceMode.Impulse);
But this is to snappy. It looks more like the player is teleported to the top and then glides down.
Well, you have different force modes, and if those dont satisfy the requirement you've other movement methods like SetVelocity which override many of the physics features
Like this? @timber tide
I tried that but now my player doesent jump at all.
jumpForce is set to 130f
what is the mass of your rigidbody? actually, can you show a screenshot?
Addforce works fine for jumping, just makes sure nothing is overriding your Rigidbody's Y velocity
Yeah but I want the jump to be more like a curve. With AddForce its more like the player is teleported
if you want anything but a parabolic trajectory, using AddForce or force simulation in general, is not the best way to go
your drag is way too high
default drag value is 1, so best keep it like that
I set it to 0 but the player still doesent move
well, then something you aren't showing is overriding what you do to the rigidbody
My jump function:
private void Jump(InputAction.CallbackContext ctx)
{
Debug.Log("JUMP - Ground Check");
if (!IsGrounded()) return;
Debug.Log("JUMP");
//this._rigidbody.AddForce(new Vector3(0f, this._jumpForce, 0f), ForceMode.Impulse);
Vector3 velocity = this._rigidbody.linearVelocity;
velocity.y += this._jumpForce;
this._rigidbody.linearVelocity.Set(velocity.x, velocity.y, velocity.z);
}
you should probably share all the code that acts on the player object
and stick to AddForce for now
My playerController.cs file
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerController : MonoBehaviour
{
[Header("Values")]
[SerializeField] private float _moveSpeed = 2.5f;
[SerializeField] private float _crouchSpeed = 1.0f;
[SerializeField] private float _jumpForce = 1.0f;
[SerializeField] private float _isGroundedDistance = 1.0f;
[Header("Connected Components")]
[SerializeField] private Rigidbody _rigidbody;
[SerializeField] private Collider _collider;
// Private
private InputController _inputController;
private Vector3 _currentMovement;
private Vector3 _currentGravity;
private void Awake()
{
_inputController = new InputController();
_inputController.PlayerGameplay.Enable();
_inputController.PlayerGameplay.Movement_Jump.performed += Jump;
}
private void OnDestroy()
{
_inputController.PlayerGameplay.Movement_Jump.performed -= Jump;
_inputController.PlayerGameplay.Disable();
}
private void FixedUpdate()
{
SideMovement(this._inputController.PlayerGameplay.Movement_Sides.ReadValue<float>());
this._rigidbody.linearVelocity = this._currentMovement;
//Gravity();
}
/// <summary>
/// IsGrounded confirms that the player is grounded, by checking if it hits a collider in range set by _isGroundedDistance.
/// </summary>
/// <returns> bool If the player is grounded it returns true if not then false. </returns>
private bool IsGrounded()
{
return Physics.Raycast(transform.position, -Vector3.up, _isGroundedDistance);
}
/// <summary>
/// SideMovement moves the player to the sides on the X axis. If the crouch button is pressed it moves the player with the crouch speed.
/// </summary>
/// <param name="ctx">The CallbackContext from the input action.</param>
private void SideMovement(float inputValue)
{
if (!this._inputController.PlayerGameplay.Movement_Crouch.IsPressed())
{
this._currentMovement = new Vector3(-(inputValue) * this._moveSpeed, this._currentMovement.y, 0f);
} else
{
this._currentMovement = new Vector3(-(inputValue) * this._crouchSpeed, this._currentMovement.y, 0f);
}
}
private void Jump(InputAction.CallbackContext ctx)
{
Debug.Log("JUMP - Ground Check");
if (!IsGrounded()) return;
Debug.Log("JUMP");
//this._rigidbody.AddForce(new Vector3(0f, this._jumpForce, 0f), ForceMode.Impulse);
Vector3 velocity = this._rigidbody.linearVelocity;
velocity.y += this._jumpForce;
this._rigidbody.linearVelocity.Set(velocity.x, velocity.y, velocity.z);
}
private void Gravity()
{
}
}
you are overriding rigidbody veloctiy in each update (_currentMovement) and jump does not write to that variable
you need to add your jump to _currentMovement like you do in SideMovement
Updated Jump function:
private void Jump(InputAction.CallbackContext ctx)
{
Debug.Log("JUMP - Ground Check");
if (!IsGrounded()) return;
Debug.Log("JUMP");
//this._rigidbody.AddForce(new Vector3(0f, this._jumpForce, 0f), ForceMode.Impulse);
this._currentMovement.y = this._rigidbody.linearVelocity.y + this._jumpForce;
}
Now the player jumps but just keeps going up.
well yes, you are setting the Rigidbody's Y velocity to linearvelocity + jumpforce which will set its Y velocity to whatever you set it to, you should probably stick to Addforce and not overwrite your rigidbody's Y velocity
But how would I get a jump that is smoothe. With addforce the only thing I get is more like a teleport.
do not overwrite it's Y velocity and put that drag variable on the RB itself to 1
Ok but now its like a teleport
Or what type of Forcemode should I use?
Right now im using Impulse
Impulse is fine, show me your new !code using one of the paste sites
📃 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.
you are still overwriting the rigidbody's Y velocity this._currentMovement.y instead use _rigidbody.velocity.y
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
ahh now its smoothe thank you very much ^^
o7
I think that I get the gravity stuff myself. Thank you for the help.
Yeah me too. The last project I did was witht he 2022 version.
New problem for me. https://paste.ofcode.org/GbmSkaH9bD6Dzbj5773Riz
Heres my current code for my card movement, but onPointerExit, the original position of the second card (the x) gets moved to a the other cards? I dont get it, since I have that saving variable. Any ideas?
Sorry thats a bad explanation, but I don't know how to word it better.
You'll need to debug some more info. Like what original position is being set on awake and in other places and what transform position is being set to each time you modify it.
Maybe because of length, you could use Pasteofcode?
next time
!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 have the code on github https://github.com/SunnyFloppyDiskStudios/VRSystems/blob/main/Assets/Scripts/VRControlSystem.cs
im having trouble with the headset rotation not rotating and the controller positions not changing
Sounds like a VR related issue, so #🥽┃virtual-reality
I've seen lots of people use variables to check grounds, jumping, etc. for platformers, just wondering if using a state machine like this would cause any issue?
so far it's going great, but dunno if it's better to do differently
It might be an issue when you want to have combinations of these states.
But maybe worry about it when there's an actual problem.
Hey, I want to make movement like in super mario galaxy where you can run on any surface, but rather than running around planets I want it to be able to walk on any surface, like complex meshes, etc. How should I go about making something like this?
You'll need to adjust the gravity vector dynamically.
I am a bit new to Unity and I'm having a few issues with a classlib I built. I first am having trouble finding the main entry point to add some hosted and transient services or and similar for each scene. I also am not finding the window for adding a reference to a NuGet package in my local NuGet feed
the nuget option is also greyed out in vs2022
There's a specific plugin for NuGet if you want to use it with Unity
You don't have a typical entry point with Unity, but you can probably manage some service locator pattern using a singleton which you can refer to when changing scenes and flagging it with https://docs.unity3d.com/ScriptReference/Object.DontDestroyOnLoad.html
Hey sorry for the late reply, i think i understand that part, but what would you do to solve charp corners or rounded parts? I have my player rotate towards the normal of a down raycast and make the gravity vector the normal, but how do i detect to go around a corner, etc?
[RuntimeInitializeOnLoadMethod] is the closest thing you can get to an "entry point", I use it for setting up stuff like that
Well, that's a design problem. How do you want it to be handled?
In the first place, do you want it to be possible to change gravity on sharp corners?
If yes, then maybe lerp between the old and the new normal over time.
if you were to do sphere casts(potentially several, both right below and a little bit towards a position in front of the character), you could detect a "wall" in front and get it's normal.
Yep i wanted the character to be able to change gravity on sharps corners and using a spherecast to detect the wall was smth i actually hadn’t thought of. Thank you for pushing me in the right direction!
Can someone pleases tell what is happening?
it worked well like an hour ago and now it every time i pass through a tube it stops and give me this error
Something on line 18 in that script is null
im sorry but can you tell me what is wrong
theres nothing null in line 18
Well I would wager that instance of your Score singleton is null
Perhaps its not in the scene anymore
NEVERMIND I FOUND IT
Thank you tho i was so stressed i didnt see that it was line 18
was exactly that
is there a way i can assign multiple "owner types" to my inventory class? its being used by my character class and my item class, but i can only assign 1 data type
The way to do that would be with polymorphism but I do not see what a charaacter and item have in common. Perhaps a IInventoryOwner interface would work better here.
Ty, i will try that
try making a JointMotor2D variable which stores slider.motor, then you should be able to modify motorSpeed of that variable
thanks a lot
How can i fix this error ?
i have made it public but it does not appear in the editor
JointMotor2D isnt serializable
im a complete beginer
what does serializable mean
why does this not work
because motor is a struct
how do i connect it then
if you post your !code correctly I will show you
📃 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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class platformscript : MonoBehaviour
{
public SliderJoint2D slider;
public float speed;
public float distance;
private float DistanceMoved;
private float rotation;
public JointMotor2D Motor;
// Start is called before the first frame update
void Start()
{
Motor = slider.motor;
}
// Update is called once per frame
void Update()
{
Motor.motorSpeed = speed;
DistanceMoved =+ Time.deltaTime * speed;
if (DistanceMoved > distance)
{
DistanceMoved = distance;
speed = -speed;
}
if (DistanceMoved < 0)
{
DistanceMoved = 0;
speed = -speed;
}
}
}
void Start()
{
Motor = slider.motor; // Make a COPY of motor
}
// Update is called once per frame
void Update()
{
Motor.motorSpeed = speed; // Change the LOCAL COPY
slider.motor = Motor; // set the COPY back to the ORIGINAL
this is the same workflow for ALL structs as properties
It is not possible to update a struct directly. You must either make a copy of the struct, change that, and replace the existing struct, or you use existing methods in the struct so it modifies itself, if applicable.
Unlike classes which can be modified directly
Something something value types and them being copies
motor is a struct, struct is copied when you set it to a variable
"easy" as in relatively easy compared to trying to figure out how to organize how to have a dozen or so quests, and have them change dependent on what quest has already been done.
the inventory took me like a week of actually trying to understand. it was hard, but i did reach a point where I went ohh and it started to piece together
this, however, i just don't know
i feel like a bunch of if statements would work but that might be overcomplicating it, but i cant think of a way that can be more dynamic
i mean if i made it so quests couldn't be failed or skipped, or something, then that would work but i want it scalable so that i could include changes like that
i need 2 lines of code
How often do you need to be told?
use a !code paste site
📃 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.
yes, remove and use a paste site as per the bot message and that you have been told on many occasions
okey
what about 'use a paste site' did you not understand?
go here: https://hastebin.com/
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
paste code in box
click save
and then put that link here
okey
after you save, it should show a screen like this (i don't have any actual code there, so i just wrote "Type here"), and then click copy url
the blue one i mean
thanks
ye
going to go cry as i can't figure this objective system out
good night
i need to make a new system for this its so over
says Player profile for '' not found! and Opponent 1 profile for '' not found.
!code ```cs
private void HandleCampaign()
{
Debug.Log($"Campaign cost text: {campaignCostText.text}");
if (int.TryParse(campaignCostText.text.Replace("M", "").Trim(), out int campaignCost))
{
if (userBalance >= campaignCost)
{
userBalance -= campaignCost;
UpdateBalances();
Debug.Log($"Campaign started for {stateNameText.text}. Cost: {campaignCost}M");
UpdateCampaign(stateNameText.text, selectedPlayerCharacter, PlayerProfileImage);
CharacterProfile selectedProfile = CharacterProfiles.Find(p => p.CharacterName == selectedPlayerCharacter);
if (selectedProfile != null)
{
Button clickedButton = GetButtonByStateName(stateNameText.text);
UpdateStateColor(stateNameText.text, null, null, selectedPlayerCharacter);
}
}
else
{
Debug.LogWarning("Insufficient balance for campaign!");
}
}
else
{
Debug.LogError("Invalid campaign cost!");
}
}```
📃 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 you use assembly definitions?
i think no
Then try deleting your library folder and having Unity regenerate it
private void HandleCampaign()
{
Debug.Log($"Campaign cost text: {campaignCostText.text}");
if (int.TryParse(campaignCostText.text.Replace("M", "").Trim(), out int campaignCost))
{
if (userBalance >= campaignCost)
{
userBalance -= campaignCost;
UpdateBalances();
Debug.Log($"Campaign started for {stateNameText.text}. Cost: {campaignCost}M");
UpdateCampaign(stateNameText.text, selectedPlayerCharacter, PlayerProfileImage);
CharacterProfile selectedProfile = CharacterProfiles.Find(p => p.CharacterName == selectedPlayerCharacter);
if (selectedProfile != null)
{
Button clickedButton = GetButtonByStateName(stateNameText.text);
UpdateStateColor(stateNameText.text, null, null, selectedPlayerCharacter);
}
}
else
{
Debug.LogWarning("Insufficient balance for campaign!");
}
}
else
{
Debug.LogError("Invalid campaign cost!");
}
}```
it is passing Null sometimes
can I know how to fix
Please specify what can be null sometimes
selectedPlayerCharacter
Nothing in the code you just send explains what selectedPlayerCharacter is. Please share the full !code on a paste site
📃 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.
Skimming through the code it assigns selectedPlayerCharacter exactly once, so I suggest you debug the result of the Playerprefs call done there
Log a message, see if it's truly null, then come back
Note that the player prefs has a default value of "", so if it truly returns null then that means that something has explicitly set SelectedCharacter to be null and so it does not use the default value
However, once again I don't see any code that sets this value so I would not know what it does
Trying to make some sort of bouncing ray, as you can see it works here, but when I move the blocks slightly, it goes in the wrong direction
for (int i = 0; i < 360; i+=10)
{
var _x = Mathf.Cos(i * Mathf.Deg2Rad);
var _y = Mathf.Sin(i * Mathf.Deg2Rad);
var pos = new Vector2(_x, _y);
var hit = Physics2D.Raycast(transform.position, pos, 10);
Debug.DrawRay(transform.position,
pos*10f, Color.green);
if (hit)
{
var hitPos = hit.point;
var newDirection = Vector2.Reflect(pos, hit.normal);
var hit2 = Physics2D.Raycast(hitPos, newDirection, 8);
Debug.DrawRay(hitPos, newDirection * 8f, Color.blue);
if (hit2)
{
var hitPos2 = hit2.point;
var newDirection2 = Vector2.Reflect(newDirection, hit2.normal);
var hit3 = Physics2D.Raycast(hitPos2, newDirection2, 6);
Debug.DrawRay(hitPos2, newDirection2 * 6f, Color.red);
if (hit3)
{
var hitPos3 = hit3.point;
var newDirection3 = Vector2.Reflect(newDirection2, hit3.normal);
var hit4 = Physics2D.Raycast(hitPos3, newDirection3, 5);
Debug.DrawRay(hitPos3, newDirection3 * 5f, Color.cyan);
}
}
I'm sure my code is super bad but I can't figure out why this happens'
I wonder if the red line is starting from inside of the block and then instantly hitting it
The Debug.DrawRay lines you're drawing do not depend on how far the raycast actually traveled
Also, to reduce code duplication, consider doing something like this!
Yea I know, I think I should use line renderer component instead
I want the lines to be visible in play mode after all
Nah, you just need to change how you use it (or use DrawLine!)
var _x = Mathf.Cos(i * Mathf.Deg2Rad);
var _y = Mathf.Sin(i * Mathf.Deg2Rad);
Vector3 pos = transform.position;
Vector3 dir = new Vector2(_x, _y);
float rayLength = 10;
for (int try = 0; try < 10; ++try) {
float hue = try / 10f;
Color color = Color.HSVToRGB(hue, 1, 1);
var hit = Physics2D.Raycast(pos, dir, rayLength);
if (hit) {
Debug.DrawLine(pos, hit.point, 3f, color);
pos = hit.point;
dir = Vector2.Reflect(dir, hit.normal);
} else {
Debug.DrawRay(pos, dir * rayLength, 3f, color);
break;
}
}
Something like that
I renamed "pos" to "dir" because that's what it actually represents
Yea that's much cleaner xd
HSVToRGB is useful for creating a range of colors
In that case, you may need to slightly push the start point along the direction of the ray
This is for a demo thingy that is supposed to visualize sound
I know it
it's a simplification
Since sound actually doesn't reflect speculary
Unless it's a extremely smooth surface
i wonder if it winds up being a BSDF
just like light
bad thought! bad thought! bad thought!
Neat!
I've been fussing around with implementing my own spatial audio system (Steam Audio doesn't work on ARM hardware...)
I've only really done occlusion (in straight lines) and using a nav mesh to figure out the ratio between:
- the straight line distance
- the shortest path to the listener
I need a 3D navmesh system for this 
Haaugh
FYI Steam Audio also went open source some time ago if you wanna investigate https://github.com/ValveSoftware/steam-audio:man_facepalming:
E: Oh you literally just linked their repo 🤦♂️
Yes this work but DrawLine() doesn't need that 3f parameter btw
Thanks
Let me know how it goes
I'll probably implement portal based occlusion since my interiors are procedural so I already have portals and simple wall geometry
For exteriors I need to think of something else 🤔
Couldn't find it - do you have a link?
i am also struggling to find it
I found the link from this blog post https://camiloruizcasanova.home.blog/tag/svo/
Cheers
In theory it's not that bad, and I don't need to bother with things like obstacle avoidance
but it still sounds scary
Ah this is so close to my implementation I just cant get the morton codes octree working in parallel but that paper they mentioned might be my answer.
does anyone know how to deal with scenes? I know basic stuff such as scenemanager.setactive or whatever but i want to minimize loading time. I'm using quantum, which uses additive scene loading.
that's a bit vague :p
i see a lot of unity made games with super quick scene loading, for my game genre (fighter) at least
do they load it all at the start or something?
You can use LoadSceneAsync to read the data from disk in the background, but scene activation will still have a cost
Is it possible to have all scenes loaded at once?
will that become very costly?
if theyre deactiveated
I havent used addressables yet but those can probably be used to manage what is loaded and when
SetActiveScene is not used to "turn a scene on"
A better name might be "main scene"
It's the scene that new objects go into, where lighting settings come from, etc.
does using addressables require a lot of extra work?
You can certainly just load every scene with LoadSceneAsync, but not activate them
But this will not reduce the hitch caused by creating all of the objects
Someone else should answer, I just recently installed it
depens on how far you want to go with addressables really, if you just want to load stuff it shouldn't be too much additional work besides changing some parts of the code to be async
I dislike how it adds the Addressable toggle on every asset though... Waste of screen space
then later you can deal with sorting things into proper groups, reducing asset duplication, loading things remotely
I haven't really used Addressables yet. I played with using it to easily load every asset of a certain type (without having to dig around in a Resources folder for them), but that was a bad idea
since I had no Addressables scenes and I wasn't using any addressable asset references, the objects I got from Addressables had nothing to do with the objects I was referencing from my scenes
(This only becomes apparent in the built game. In the editor, loading an Addressable asset just grabs it from the AssetDatabase)
yeah, resources folder is also an option for lazy loading
although less robust than addressables
I wound up making "catalog" objects that reference every object of a relevant type
I have not yet automated putting things in the catalogs. I should...do that...
ah well there's no point then. someone showed me this thing where I can make load async a lot faster by increasing the priority of the background loading thread, so i might just do that for now
increasing the what now
This will allow the game's framerate to dip in exchange for faster reading of the scene data
Note that this won't do anything to the hitch that you get when a scene activates
That does look useful, though. I might switch that to "High" when the player hits Start
that's fine, the scene is black during loading anyway so it's not like they're going to see anything
At that point you could just load the scene synchronously
the same thing in inventory can be compared to quest, you can have a simple "easy" to make one compared to a more complex system. Lets just say both systems are difficult in the beginning but once you get an idea on the approach you start refining it
configure the IDE properly
looks like you manually linked the exe and its causing issues now. Go to External Tools and fix it
I need async loading cus it's for a multiplayer game
@floral viper also don't crosspost
guys why do i have to close unity then open it again just for the script to load
no.
well, it's happening to them right now :p
like whenever i do smth in vs code and i save it, for the changes to be implimented onto unity, i have to close unity
does that make it reload?
do you have auto refresh enabled? If not then you have to manually reload
preferences -> general (2021), Preferences -> asset pipeline (unity 6 and 2022) for auto refresh
tysm
for helping me
is there a way to set space to the hand?
like how in photoshop and illustartor, if u hold space bar, u can use the grab
to mvoe around the screen
nvm i think i found it
middle mouse click I believe
oh em gee
You can also press Q to switch to the "View Tool"
tanks so much ❤️
hi y'all quick question how do I add two vectors? I get an error that + cannot be used between a Vector3 and something like (0,1,0)
if I have v as a Vector3, how do I do v+(0,1,0) ?
because (0,1,0) is not a vector3 and is probably being counted as Tuple
you can certainly add 2 vectors, you just cant multiply them
(0,1,0) is not a Vector3 it is a tuple.
new Vector3(0,1,1) is a vector3
var tuple = (1,3,4)
var vector = new Vector3(1,3,4)
A tuple is, essentially, several values glued together. They're useful...but irrelevant here
lazymans struct
https://hastebin.com/share/cikiweheca.csharp
so i have this script that is supposed to scale my bullets while they travel but it doesnt really work
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
removing the Time.deltaTime is making it work but its scalling too much, and it just becomes huge instead of stopping at certain size
for (float i = 0.01f; i < 0.1f; i++)
{
scalling += i * Time.deltaTime;
}```
you know this entire for loop is going to run instantly right
The code after it will run after the entire loop
and you are doing all of this every single frame
well...