#💻┃code-beginner
1 messages · Page 803 of 1
yeah im looking for it
I can see two right there
- delete the duplicate script
- Rename the
movementclass toMovement - you should be able to assign it properly then
I have an invisible unity sprite, no clue why its not showing up
camera z = -10
GameObject sprite z = 0
You put an Image component on it
instead of SpriteRenderer
Image is for UI
ah
it also... has a RectTransform?
Meaning you put it on a canvas
so is this intended to be a UI element, or is it intended to be in the game world?
Btw you can disable sprite filter in sprite settings
Well smoothing
gotchu thanks
hey, me again! im having trouble using shader graphs to implement into my game gerstner waves; i want them to move all over the place but they seem to only move back and forth (and not side to side). Does anybody have any ideas on how to fix it? I can send pics if needed
You can't use variables that don't exist
Write your code so it only uses variables that actually exist
My two colliders(hook and fish) arent colliding
fish as circle collider and rigidbody, both 2D
and the Fish has just a capsule collider 2d
well the first collider is a trigger which is not a solid collider for collisions, it is a trigger volume
okay how do i fix this, because toggling Is Trigger false does not fix this issue, none of the functions(either OnTriggerEnter or OnCollisionEnter) fire
see, if it was about physics messages you should have said that. your message implied you wanted physical contact (a collision) to happen
go through this: https://unity.huh.how/physics-messages
aah that worked, I was using OnTriggerEnter, and not OnTriggerEnter2D
~~ hey, i'm a complete beginner and i want to add a script to an scene object but i get an error which says "Can't add script behaviour 'inputManager'. The script needs to derive from MonoBehaviour!"
Everywhere i have asked or looks just says that the class name doesn't match the file name, use GameObject.name to find it without actually telling me wtf a class anme is and where i am supposed to run GameObject.name
please help, idk if this is the right place but i couldn't find a "Help" channel sooo.~~
fixed it
how would I reset the position of a collection of rigidbodies? Trying to restart a player position and the player is a ragdoll
I’ve done something similar and I simply set the Rigidbody component “isKinematic” to true, move it wherever, then set it back to false, hence giving control of that object’s Transform back to the physics system
Not sure if it’s best solution but I never had any glitches
is there an easy way to iterate through all of them and change Kinematic/reset position/change Kinematic back
Yes by doing exactly what you just said 
that makes sense lmao
is there an issue with just setting the position of the rigidbody directly? it's documented as effectively teleporting the rigidbody
I have two monobehavior classes that I need to run identical code (inserting prefabs into a container). I'm trying to figure out the best way to handle this. I was leaning towards an abstract but don't love the fact that I will have to pass in the prefab and container as parameters since a parent can't access child properties. Other options I found; static class, base class, service locator seem to all have the limitation as well so I assume abstract it is. Figured I would ask for thoughts.
since a parent can't access child properties
is the container in the child? what exactly is the set up here
what's common and what's different in this "identical code"
When I said child I meant child class (in this case : scene class -> abstract class). Abstract class can't get the scene properties (content + prefab properties) directly. What is duplicate is one method that renders a bunch of prefabs into container.
prefabs aren't in the scene, and you haven't actually specified what this content/container is
also, the abstract class can absolutely get stuff from the scene
an instance of a child class is also an instance of its parents
Content is a empty GameObject. I'm rendering inventory items (prefab) on to a UI panel. So I have the sceneController script, that will have the content + prefab attached to it. But I don't know how to give access to that in the abstract class, so I assume I have to pass it in as parameters.
you can have serialized fields in the abstract class, no?
inventory items (prefab) on to a UI panel
so prefab instances, gameobjects in the scene, not prefabs
Ahhh....of course...that makes a lot of sense. I didn't even think of that for some reason.
technically this doesn't need to be abstract either, with the constraints you've given. just some parent class representing the behavior of instantiating a list of objects into some other object
of course if there are other details that would make this invalid on its own, then you would have it abstract
another option would be to just have some static utility method somewhere (if it's just a chunk of logic that isn't exactly its own behavior)
Ah ok...so that might be better if I want to repeat this behaviour with something not inventory related.
Thanks for the thoughts...I really appreciate it
A user interface (UI) is what allows a user to interact – or interface – with an application. A UI often includes images, text, buttons, toggles, sliders, or dropdowns.
In this mission, you will design your own title screen and functional settings menu.
By the time you complete this learning experience, you will be able to:
Decide on a ...
thank you
That would work but also need to reset both velocity and angular velocity @brazen pumice
this is a code channel, #🧰┃ui-toolkit and #📲┃ui-ux (for the older UGUI)
sorry it honestly was hidden in suggested channels
i didnt mean to misuse channels sorry
you're not the first and won't be the last to use the wrong channels. Use id:browse to find the correct place for things (if nothing exists for your question, then the defacto place is #💻┃unity-talk )
~~I need a little with understand of my problem with Vectors.
So...
I have a enemy and I wanna set a ray(s) at the direction(y) to player BUT at the same time also use vector needs to set ray to require angle(Making a ray of attack). I'll not show this vector(main_dir) 'cause it almost the same as transform.forward.
At the end I want to get vector that is looking at y-pos of player and also rotates along x depending on transform.forward (that is, depending on the enemy's rotation)
My actually problem/issue that when I'm trying to go at the side from enemy's rays these rays are starting to move up and down. I don't understand how its actually possible. I tried to search information and there was also nothing about my sort of problem.
Maybe you can help where do I have an issue in the code?
I am open for all questions.
//dirToTarget is vector to player(not normalized!)
Vector3 planeNormal = transform.right;
Vector3 fwd = Vector3.ProjectOnPlane(transform.forward, planeNormal).normalized;
Vector3 dir = Vector3.ProjectOnPlane(dirToTarget, planeNormal).normalized;
Vector3 main_dir = Quaternion.AngleAxis(currentAngle, transform.up) * transform.forward;
//currentangle to set angle
float xAngle = Vector3.SignedAngle(fwd, dir, planeNormal);
Vector3 direction = Quaternion.AngleAxis(xAngle, transform.right) * main_dir;
//Vector3 direction is going to use for a ray calculating.
```~~
How do I make this action possible on a UI button?
bool isShooting = Input.GetKey(KeyCode.Z);
_animator.SetBool("Shoot", isShooting);
With script you mean? Or that?
I didn't quite understand
well your button needs some kind of script to work
something that tells it what clicking, releasing or even hovering on it does
it cant know how to do something unless you tell it to do that
I mean do you need it to be triggered (adding the event) using code or just set it to trigger when the button is clicked by default?
Yes
Hah, which one? :)
Sorry, I'm using the translator.
Just set it to trigger by default when the button is clicked.
the issue im seeing is why are you trying to do "input.getkey()" on a ui button
Okey. So you can add to your script a method which works when you press a button.
public void Action()
{
//your action/script
}
And then go to editor to the component "Button" on your object.
Then add an action
By None(object) set object with your script and choose on the right side function you want to invoke.
I hope its quiet understandable :>
Can somebody helps me? Pls?
im thinkin it through,
so you want it to be aligned to the forward direction of the enemy, but then angled up/down to look at the plane of the player?
might have to draw this out, i'm not seeing the picture
thats what im working on xD
Can you share a picture of the scene or something? Becasue your text description of the problem was confusing to me
It's sounding like you probably just want some kind of vector projection but it's unclear
Okey, one moment.
i think i understand
you rotate your local baised on current angle with transform up and forward yea?
Another half of the video is more informational.
Yes. One(X ray direction) with transform.up and another y-axis direction with transform.right.
oooo
so when you rotate a vector by tilting that changes your "up"
that yaw happens when your look dir is no longer horizontal
No? I don't change transform of the object. The transform in that case is this AI enemy.
you want the rays to sweep left to right?
Yes, I also think that is because of this vector. But If I set one of more variables to 0(to get only one axis) my ray is crushing and stop working well. I confess what I am not so well with so sort of geometry.
I want to sweep them up and down with one vector and set a direction forward with another.
Difficult I know. But... okey I guess there is no "but"...
HI everyone, I opened Unity earlier this week and am trying to make a basic tower defense game. I found a tutorial on YouTube, but I don't understand why my display is different from theirs. Could someone help me? (1st image is the tutorial, 2nd image is my screen)
Is that all you have on the screen?
which particular difference are you asking about? This is a pretty broad/vague question
It looks like you aren't seeing the tilemap's grid
On his screen, you can see the grid of the tilemap and the camera's field of view, while on mine everything is smooth.
he has gizmos turned on
you don't
Also, your top bar is laid out a bit differently. This could just be due to different defaults in different editor versions
You can rearrange the groups of buttons
It's good thanks 🎉
what exactly is happening here that you want to happen differently?
Hey, it's me again. Still struggling with my tutorial 🥲 I'm trying to drag a sprite into my scene, but the sprite goes under the tilemaps and I get this message in my logs: "Sprite Tiling might not appear correctly because the Sprite used is not generated with Full Rect. To fix this, change the Mesh Type in the Sprite's import setting to Full Rect." Except when I look at the Unity documentation, I can't find the steps to do this, and the screenshots are different because it's not the same version of Unity. Do you know where I can change this setting to see if it solves my problem ?
Click on this and open the sprite asset itself
You can change the sprite settings there
As for the rendering order you need to look at the Sorting Layer and Order in Layer of the tilemap vs the Sprite Renderer
Okay, I understand. So for the tilemap, I should leave “Order In Layer” at 0 and set my sprites to 1?
or put them on different layers entirely
So, put the ground in the “Default” Sorting Layer and create a specific one for buildings?
There must have been seeing as I had to look into how to get around that whole situation.
IIRC the physics system continues to try to control the Transform leading to some weird in-between effect
the position of the rigidbody, not the position of the transform
modifying the transform would indeed lead to a desync
Blue - player
White shape - enemy
Black - rays attack
Red - direction to the player
Yellow - rotation of the enemy
At the end I DONT want to have an example on 1st image. **I want the scenario at the image number 2. **
The direction of rays changes when player is moving aside the enemy and that is quiet annoying. I want just the rotating on the y-axis without any changes on the another axes.(I mean rays of attack are always looking with transform.forward and I change the y-axis of the rays due the script.)
ah, i see, i confused y-axis rotation with pitch
this makes much more sense
if the player is in front of the enemy, but slightly above or below, would the enemy look up or down accordingly?
well, the attack specifically
if not, it would just be a projection like praetor mentioned
if so, it would use projections, but you'd also have to check how far away the player is from the facing direction, and see if that's in a threshold
It also has whacky results when Interpolation is on.
Not sure how that is affected when doing the “Rigidbody position” vs “Transform” position thing though
setting the position of a rigidbody doesn't have interpolation, that's moveposition
If you want to continuously move a rigidbody use Rigidbody.MovePosition instead, which takes interpolation into account.
Don’t make me jump into Unity and double-check bro omg 
Sure whatever, if you’re sure then ok cool
i mean, i don't doubt that there's an issue, ive heard this recommendation of kinematic -> teleport -> dynamic before
but if what you're saying is the issue directly contradicts docs, i'm not gonna immediately believe it lol
docs can be wrong, sure, but i'd like to see some evidence or a clear description of the issue
hm, rigidbody2d.position docs are... extremely brief, and don't mention this at all (and neither does moveposition)
is the behavior maybe different between the 2 engines, yet again?
im very new to programming and unity, can someone explain how i can use the activescenechanged event to call my method?
you subscribe to it?
The docs miss important stuff sometimes,
Like the whole “MovePosition and MoveRotation only respect Interpolation for kinematic RB” thing that was recently discussed here
have you tried researching events/delegates in c# yet
how do i do that 🙂
true, but what you said is in direct contradiction to the docs, at least for 3d
try googling events/delegates for c#
Events can be subscribed to by giving them a method to call.
This page includes an example
(code at the bottom) Instead of deleting when clicking on the object this code makes the object delete just when i hover over it and and it doesn't plus suns
I'm a complete beginner and i'm following a tutorial right now to make a ripoff of flappy bird.
I tried to bind a key but unity gives me an error message about using the wrong imput, please help.
!input
To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling
• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.
is the code correct though?
switch the input handling to both and try it out
Try it and see
configure your ide
!ide
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
nvm found it i think
the code isn't showing glitches
One of the reasons you should configure it
Can you disable root motion on single animations or block it through code?
Right now I only want it on the dodge roll and do it like this:
public void OnAnimatorMove()
{
if (!IsDodging) return;
var deltaPosition = _animator.deltaPosition;
if (deltaPosition == Vector3.zero) return;
_characterController.SimpleMove(deltaPosition / Time.deltaTime);
}
But I assume with more complex animations that is going to be a can of worms 😄
when you close unity with the ide still open it can "disconnect" closing them both and opening the ide from unity tends to fix this
The program I use searches code differently I am telling you it doesn't show any glitches it's just doing something different
Configure your !ide and let it auto-format your code and you'll see the problem
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
god forget it I'll just ask on reddit someone there will help me
There's no point in trying to code without setting up your tools
but people here are trying to help you and you aren't listening to them
Yo. Got a potentially major bug with unity
button callbacks don't work if you lower the resolution
As in UI? You're probably covering it up with another object so you can't click on it
Yes, that's very likely
If you are using the old input system, you can select the Event System and look in its preview pane (bottom of the inspector) to see what's being pointed at
for some reason, the new input system doesn't show this
could be--all that I have in my scene are some buttons. When I set the game view to free aspect, all buttons work at normal res (1920x1080 ish) but when scaling down to like 800x300, some buttons become unresponsive
canvas set to scale with screen size, match h/w 0.5
AH diagnostic text displayed over derp
it wont lemme do transform.rotate(); it wants to do transformblocks
well it would be transform.Rotate()
not with a capital T
second, your IDE may not be configured properly for use with Unity.
!ide
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
yea its configured and I have the extension
Do you have using UnityEngine; at the top?
If so, I'm like 80% sure you don't have it configured. It should be saying "Unity Message" or "Unity Event" over Update()
lemme relook at that page I had followed the steps and went thru packaghe manager and got the extension I dunno
im not seeing the extension under package manager to update. the extension is installed
and what about the other steps?
only other step is to set editor as default and it is
well no, that's not the only other step. but show where you did that
this is not set up correctly
"Visual Studio Code (internal)" is wrong
says do package which I cant find and then default editor
if you think that is the only two steps then you are missing the vs code extension
Note that if you just installed the package, it can't actually compile and start working if there are outstanding compile errors
you should be seeing something closer to this, with a version number at the end
now im confused do I install that one or not I saw the response but it was deleted sorry had to walk away for a minutes its giving me a headache. I cant seem to get this to work I think your right its not configured correctly im gonna reinstall it and restart see if that helps
you only need the "Visual studio editor" package in your unity project
that covers VS and vs code
protected override IEnumerator AttackTimer()
{
agent.isStopped = true;
animator.applyRootMotion = true;
animator.SetBool(enemySO.meleeEnemyAttacks[0].attackName, true);
yield return new WaitForSeconds(enemySO.meleeEnemyAttacks[0].attackTimer);
animator.SetBool(enemySO.meleeEnemyAttacks[0].attackName, false);
animator.SetBool(enemySO.meleeEnemyAttacks[1].attackName, true);
yield return new WaitForSeconds(enemySO.meleeEnemyAttacks[1].attackTimer);
animator.applyRootMotion = false;
agent.isStopped = false;
agent.ResetPath();
agent.Warp(transform.position);
yield return new WaitForSeconds(0.1f);
SwitchState(EnemyStates.Moving);
}
does anyone know how to fix root motion issues? when the animation stops the enemy snaps back to the navmesh agent position, basically "rolling back"
using UnityEngine;
using UnityEngine.AI;
public class ApplyRootMotion : MonoBehaviour
{
[SerializeField] Animator animator;
[SerializeField] NavMeshAgent agent;
void Start()
{
animator = GetComponent<Animator>();
}
void OnAnimatorMove()
{
if (!animator.applyRootMotion) return;
agent.transform.position += animator.deltaPosition;
agent.transform.rotation *= animator.deltaRotation;
agent.nextPosition = agent.transform.position;
}
}
ApplyMotion is in the same object as the Animator
are you looking in the unity registry
also installing by name does not mean using its display name
that wouldn't "break" unity. but you could also just . . . install it again
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
!code for large code posting
https://paste.mod.gg/nkhjbckhgkfn/0 tried writing a basic player movement system on my own , anyone can tell me if its efficient or not? and whats a better way of doing it
A tool for sharing your source code with the world!
is there a decent video that covers shortcuts in vs code?
everything is long and not what im looking for
I imagine alot are normal windows keys wbut im not familiar with even all those
what magical shortcuts are you hoping exist?
and im sure the actual docs for vs code will list these instead of a yt video
alot of the videos I see people Ijumping aroundf in the code etc without clicking their mouse
cool im gonna print that
hey can anyone check out my thread in networking. i really need help here
Hmmm im lost with tutorial
ctrl-shift-P will open the command palette, which lets you search for commands by name
this is useful for running commands directly
but it also shows you the shortcut if one exists
I fixed it self lol. I feel myself as a genius. Thats why I also love programming and math.
how can i fix this??
as the error says: you have code that uses the old input manager, but you've set your project to only allow use of the new input system
old input might look like this
Input.GetAxis("Horizontal");
i have it Input.getkey("W") 4
how would i swap it back to the old one?
or how would i convert it into the new one
im follwoing an older tuturioal
open your project settings, go to the Player section, and then set the Active Input Handling setting to "Both"
Stick with the tutorial for now
There is a marginal performance penalty when you do this, but that doesn't matter at all
!input
To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling
• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.
i have an animated button pixelart which i want to add to a button (object) what is the difference between animator, animation and using the button transition "animated"
Why the difference when creating a monobehaviour script
the one is in tutorial video on left
Left side has some extra c# libraries, but monobehaviours (at minimum) only need UnityEngine
yea I guess ill just mirror the tutorial and type those in
If you're using lists in your scripts then you'll also be using the Generic's library
Unity changed the default MonoBehaviour template in Unity 6
They no longer include using System.Collections; and using System.Collections.Generic;
so I dont need to add them to the script even though the tutorial has them?
Do you need those namespaces?
If the tutorial later uses a type from one of those namespaces, you'll want to add the directives
e.g. the latter is where you get List<T>
the former gives you IEnumerator
both of these come up somewhat commonly
A using directive doesn't actually "import" anything; it just lets you write a shorter name
using Foo.Bar.Baz means I can write:
public Thing myVariable;
rather than
public Foo.Bar.Baz.Thing myVariable;
using UnityEngine; means that you can write MonoBehaviour instead of UnityEngine.MonoBehaviour
hence why that's still there
so if I'm following what your saying using.whatevernamespace just basically allows shorthand in code?
Correct. It's not actually necessary
ok
public List<int> numbers;
public System.Collections.Generic.List<int> moreNumbers;
The first line is only valid if you have a using System.Collections.Generic; directive up top
Your IDE should insert this for you if you try to use List
ok ok im following
using UnityEngine.InputSystem;
Vector2 moveInput = Vector2.zero;
so is this using that namespace? im trying to figure out how to tell or if its just something you learn eventually
Try removing it and see
You could also just look up the class in the documentation and see what namespace it is in
oh yea it underlines everything red that requires that namespace
the script does change in tutorial smh
lol the tutorial has you use chatgpt
Vector2 is not a namespace.
The full name of the type is UnityEngine.Vector2
similarly, System.Collections.Generic.List<T> is a type
a type is a kind of thing
yea I figured that out pretty quickly after what dig said appreciate the rest
successfully found where I was being stupid after 20 mins
coding on no sleep is not a good idea
shorthand sometimes creates problems when you do run into statics/objects with similar naming. For instance you will run into conflicts with Unity's Random class and c# base class Random Library so sometimes it's just better to inline it.
don't you also get (internal) for vs installed via unity hub?
vsc can also be installed via unity hub as the recommended ide for newer versions on mac
Vector2 is a name (of a type), UnityEngine is the "space" that name lives in, a namespace
whats the best book for a beginner but doing "junior programing pathway". Doing 3d games?
how do i make the camera follow an objects like 3rd person im very new to unity guys i just want a simple script for testing
using the new input system package btw
look into cinemachine
go to project settings and do this
switch that one to "both"
that should fix it
I think the proper answer here is that you get really used to Google and typing in error messages. This one in particular I think you find good fixes for.
so real
thanks
Can someone help me learn how variable references work in C#? Here is some sample code :
public class SaveData { public Dictionary<string, int> inventory = new Dictionary<string, int> {}; }
public class SaveManager { public Dictionary<string, int> InventoryIndex(){return saveData.inventory;}}
public class Example {
public void Example()
{
Dictionary<string, int> inventory = SaveManager.InventoryIndex();
foreach (var item in inventory)
{
item.Value++;
}
}
}
Does SaveManager pass a reference to saveData.inventory by default. I just want to make sure I'm not editing the actual inventory in Example.Example(); Is there a rule of thumb on how it works? Google says "In C#, arguments are passed by value by default, whether they are value types (like int, structs) or reference types (like class instances, string, arrays). The mechanism creates a copy of the value being passed into the method's local parameter. However, the "value" of a reference type variable is the memory address (reference) of the actual object on the heap. When this reference is passed by value, the called method receives a copy of the reference, but both the original and the copy point to the same object in memory.". Which doesn't make sense to me. I also know my ServiceLocator passes class objects by reference (one instance) so maybe classes have different rule? Sorry for the vague question...just trying to learn how stuff works and not sure how to ask properly.
variable references aren't a thing in c#
for variables of reference types, the value stored in the variable is a reference to the actual object somewhere else in memory
classes are reference types, so they go by these rules, whereas structs are value types
I just want to make sure I'm not editing the actual inventory in Example.Example();
then you'd need to copy it, though why do you need to edit it at all?
ServiceLocator passes class objects by reference
it's passed by value, where the value is a reference to an object.
I'm building a craft system...so I want the inventory on the bottom of the page to change but not what is actually in their inventory
So it seems like my current code will not edit the actual inventory. But you said I need to copy it?
my current code will not edit the actual inventory
it will
sounds like you may need a separate inventory store and an inventory view? but i'm not sure what exactly you're going for
hey everyone should i use root motion or code to move my enemy attacks forward?
I don't think so. They're iterating value types.
Though, perhaps they're boxed due to the for each. Not sure why there would be a .Value field...
Ok, dictionaries are a reference type. Got it. So how do I make a copy? I just need to get the correct local Dictionary in my example class and I can take of rendering no problem.
Aaah, it's key value pairs.
this was a funny example, it actually does not compile
Property or indexer 'KeyValuePair<string, int>.Value' cannot be assigned to -- it is read only
foreach(var item in existingDictionary)
newDictionary[item.key] = item.value
oh true, i don't think it'd be boxed
And yeah, it should result in a compile error.
public readonly struct KeyValuePair<TKey,TValue>
I found this approach : var copied = new Dictionary<KeyType, ValueType>(originalDictionary);
Man...I never heard of boxing before
If they're simply wanting to iterate the collection and increment the value, they could probably box the integer in a class and increment the value by accessing the object.
Did not realize that constructor existed.. but if I ever found myself wanting to copy a dictionary into another dictionary I'd probably be re-thinking my algorithm tbh
I was just trying to give a simple example. What I want is to remove any inventory items used in the crafting system from the actual inventory count. Think minecraft/grid.
I'm going to assume they'll be eventually adding other features to these values as well, like locked or non stackable etc
in that case you could just actually remove them from the inventory and then just return them afterwards as necessary
in minecraft the cursor is another inventory slot
Hmm...I'll consider it. Currently anything going through the saveManager is written to disk. I think I understand things better now. Thanks for the thoughts. I appreciate it.
How am I supposed to set up a git repo?
I made a repo on my account through the web, cloned it to a local folder which gave it a name with dashes
My project has spaces in the name, not dashes. How is this supposed to work? Do I just put the whole project inside the repo folder so it'd be like "..\My-Project-Name\My Project Name"?
Github does not support spaces in the repository name and automatically installed -
In principle, the name of the repository and the main folder does not affect the development in any way
Hello. I am trying to make a simple physics based 3D game. I am using rigidbody and new input system to move the player. I trying to recreate player movement like in animal crossing but I also trying to keep physics interactions like horizontal winds or push pads, friction (I am using physics material for this) etc.
I tried setting the rigidbody.linearVelocity = player input * player speed which gave me the snappy directional movement but this also killed any external forces when there is no input.
I tried using rigibody acceleration but that gave me like true physics movement with curvy movement instead of snappy movement.
Is there a way to have animal crossing like movement and also have external physics interactions?
If you want to set the linearVelocity directly then you have to apply all external forces manually
I could do that but is there any other way? Because doing this means I need to do all other physics interactions from scratch.. meaning rigid body is not used at all.
What other way is there?
How would any other system know how you wanted your character to "feel"? Your request is already an contradiction. You cannot have 1:1 snappy movement and have external forces influence that, since your snappy movement by definition is snappy.
You're going to have to handle this with some logic that only you can define. If the player is in a wind zone, maybe they store a state (IsInWind), and only then the movement isn't "snappy", so that character can freely add the velocity of the wind to their current movement.
the repo's name and the folder name aren't linked, only perhaps used as a default when setting up. they can be handled/changed independantly
The proper way to do a character though is to actual apply forces via input as well so that you can add up the total velocity of the player for that frame. The input can just have a high acceleration. When they're in a wind zone/or boost pad, it simply is just a high external force that pushing against it "takes time" to go against it.
And then coming out of the zone/pad would have the player slowly decelerate by nature because their current speed would have to come down to their max speed (or zero if there's no input).
So for my case it's just a specific folder within the whole project i want to capture so I think what I came up with is to do the above and just do a copy&paste of the whole contents to the git folder whenever I'm ready to branch and push, yeah?
Oh ok let me experiment and try that
if you want to go for something atypical like that, you'll have to manage the repo setup yourself, which isn't impossible, but i wouldn't recommend it when you're starting out
also, if you already have a project, create the repo as the project and upload that, that'll be easier
what git client are you using?
Fork
And yeah I already have the project made so git came after the fact
mm, not familiar with fork so i can't walk you through that, sorry
Technically, you can just copy paste everything in if you just want to see how it works from "scratch".
- Create the repo on github (or wherever)
- Clone the repo via Fork so that it creates the folder on your PC
- Put in the
gitignore(found online) for Unity into the folder and commit that. This is important - Copy the entire contents of your Unity project into the repo folder on your PC
- Commit the entire thing to the repo
Then you can just delete your local (original) project and then in Unity Hub, just point the project to the repo folder to link it back up.
Hi everyone, I'm still having trouble following my tutorial, this time with a script. In the tutorial, he writes the script that I copied (see attachment) and he also changes the “Active Input Handling” parameter to ‘both’ in the “Player” category of the Project Settings, except that when I run the game on Unity and try to do what the script is supposed to do, I get an error message and I feel like it's this setting that's causing everything to crash, but I don't know how to fix the problem. Can you help me ?
this is not really helpfull
Do you have a camera in your scene with the MainCamera tag set?
What makes you think it has anything to do with the input handling?
half of the code only as image
You have a null reference error. Something on that line is null.
do we just guess this is the Towerplacer.cs
Sorry, I just put the part of the code where the error is located.
I have a camera, but it's just called “Camera” and not “MainCamera.” Is that the problem ?
The name doesn't matter. Is it tagged MainCamera
the tag is important here not the name
Your game is looking for Camera.main, which is the camera with the MainCamera tag.
by default this is the case but you might have added your own cam and deleted the old one, as Osteel pointed out
It was set to “Untagged” by default. I didn't know it could be linked like that. It works now, so thank you. 😅
Hello Friends, I'm not sure if this is the right place, but I'm trying to connect my unity hub project to Visual Studios to make a mod for the game ROUNDS.
I've installed Visual Studios 2022 and checked the box next to Game Development with Unity, but VS doesn't appear in my list of options for external script editors in Unity Hub. (Visual Studios Code is there, but that is a different interface that won't work for what I need)
damn, what version of unity is that
can really only give as much advice as this
!vs
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)
it is unity 2018.4.34f1, necesarry for the mod
you're most definitely on an unsupported version of unity, you'll be hard-pressed to get help with that here
these kinds of weird restrictions are part of why modding discussion isn't allowed here
ah gotcha thank you for the link
it worked thank you sm been trying to figure that out for a while
I have my rigid body variable in my code and assigned in the inspector, but when I reference it in my script it gives me a null ref?
and it seems like you are never making use of MovementInput()
and your AddForce doesnt make much sense too
That was only there to create the null ref
It was a test
ok
you are inexperienced, not dumb
i agree, that even happens to us sometimes
i mean, i don't know for sure if you're dumb or not, but this in particular is just a sign of inexperience
Yeah I haven't actually programmed in unity in a minute
hmmm I have two light sources
This is a channel for coding help
for issues with lights and such #1390346776804069396 would be more appropriate
= is assignment
== is comparison
Ohh discord just updated...
One quirk in unity objects you can omit the == too and do if(rb) or in this case if(!rb)
True
Unity does love overriding comparisons dont they
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
hey guys. i have a post open on networking for a bit and i haven tbeen able to find a solution. I am really stuck can someone help?
any reason im still getting an error here for the missing skinnedmeshrenderer even though im directly checking for it in the first if statement?
well this works because conditional statements for an if statement do not require comparing against a constant. switch statements do require a constant expression or pattern matching
nvm apparently i had set a value to mainrenderer somewhere else in the code and it wasnt reading as null but it wasnt actually a skinnmeshrenderer 🙃
YOO can anyone share some wisdom??
I’m at a stage where I can read and understand most C# code and some OOP concepts, but I struggle to write my own code without constantly referencing documentation or AI-generated examples.
I’ve been learning for about 4 months now.
Any tips or exercises to get better at writing code independently?
"I struggle to write my own code without constantly referencing documentation "
welcome to the life
thats kinda how programming works lol
there is nothing wrong with referencing documentation when writing code
i would stay clear of the ai generated answers though
for me, gamejams and small projects have helped a lot
When someone has answer they will, no need to cross post here
4 months isn't a lot, I couldn't even write a raycast without copy and paste from docs . Documentation is there for a reason , eventually you use something so many times it gets ingrained in your mind. Comes with experience/ practice & time
Wops mobile autocorrect
Try something new
Word up. anytime i run into a new concept i drill it with AI as a tutor till i understand it. i want to get to the point where i can type everything on my own without running into errors asap
if you want to get to that point
New how?
youre going to have to ditch the ai
Eventually becomes muscle memory
its a crutch and its only hurting you in the long run
A new mechanic maybe,.like fishing
Or maybe climbing
leave it to your creativity
I like that ill try that out. my current project is really big maybe i make smt smaller
Something big in 4 months is crazy
İ have been doing it for 6 years and i am not going for things thats too big
Yeah, the idea is basically sonic x killing floor x hotline miami, im treating it as a whole learning project. its been mad helpful
Even if im using it as a tutor? im not blindly copying and pasting code
imo thats already more agreeable but its a slippery slope
ai is wrong, and frequently
even if you use to learn new things it can teach you the wrong things
you said it yourself, 4 months in and you cant really write your own code without errors if you arent using ai to help you out, it might be a sign of something
try going on a bit of an ai detox, if you have to learn something, google it, look on forums, ask here, try things. It will make you a better programmer overall
because its all about problem solving, and if someone else always tells you exactly how to solve those problems you suffer the risk of skill atrophy.
hey, me again! ive been trying to implement an HLSL custom function node into my ocean's shadergraph to make waves but im having some trouble doing it; does anybody have any pointers or suggestions?
whats troubling you specifically
honestly im struggling to understand where to begin; i tried looking on github for useable HLSL code but none of it worked when i plugged it in
When you finish a script, redo it on your own to see if you can remember the structure and its process . . .
do you know hlsl?
no but im trying to learn haha
well then learn
fair enough
current issue is trying to design enemy attack combos for close range combat
these are all rlly good points i think youre right
i really dont think that would help a lot if he/she doesnt understand what does what
hlsl can be daunting, but at its core its a very simple c-style language. The confusing parts are the inputs and outputs.
i wish i had resources but im sure google will give u some good ones
on a separate note, i got the gerstner wave shadergraph working without HLSL but im having trouble syncing it with the physics so my player can actually walk on the waves (i know its on the GPU and doesnt have collisions btw, im trying to add a separate physics object and just sync the shader with the object)
@opal zodiac one of the skills of coding or game dev in general is referencing documentation. Nobody remembers everything. Coding is about breaking down problems into solvable chunks and then accessing the resources to remind yourself how to do it
most stuff in unity i just remember by now after like 8 years but if i forget something I just look it up, find an example etc
If they finished a script — either alone or from a tutorial — and don't understand what it does, then that's an earlier problem they need to tackle . . .
Typically, when you finish a script, you'd understand what that script does. If not, then you go line-by-line until you understand what each term, phrase, method, etc., does . . .
I think my issue is that im moving too fast and i need to practice the fundamentals till theyre second nature. I understand Composition, Inheritance, classes and im able to read/iterate code made by AI however i struggle to create code from scratch without a prompt due to lapses in my knowledge
ditching AI for a while and focusing on making a game a week may be the solution. what do yallthink
i agree
i might have something to help you
gimme a sec
https://20_games_challenge.gitlab.io/ @opal zodiac try this.
ive heard nothing but good things about this "challenge" from people who started to learn game dev
hell yeah I'm gonna do that and see where im at afterwords
is it useful to study CS along with this or should i just focus on writing games from scratch and learning the concepts as i go
There is a way to use "DefaultAsset" variable out Unity Editor?
I'm trying to compile my project, but get an error when I set it out "if UNITY EDITOR"
I want to refer my folder inside the variable
is your ide properly set up?
What are you trying to use it for? If it's in the Unity editor namespace it won't exist outside of the editor
Is because I'm trying to get the files inside this Resource Folder
I know that I can use "Resources.LoadAll"
But how can I set the "Database" folder without uses the name folder string?
Because, when I compile the game using the name folder, wont works right?
Instead of loading a folder, you should make a ScriptableObject that has references to the other components, then you can do a LoadAll for that asset. Instead of having a Database folder, you'd just have assets that are only containing this specific set of data
So, instead of loading the Shinobu prefab, you'd load an SO that has a reference to that prefab
Once it's in Resources it all basically blobs into one big pile with no directory structure
This folder will have various characters
So will have various files inside
I was trying to avoid to add one by one
(you'd need to know the actual asset path for the DefaultAsset, anyway -- the name alone would not be helpful)
Let me share my code
If you're just going to have one Database folder, it's perfectly fine to use the name directly
Literal names get problematic when they're prone to change
like if you do Resources.Load("JeffKillblaster")
So, you could make a Character SO, and make one for each character, then you can do LoadAll on that type
and then you rename him to BillMcMurderson
now it's broken
but Database sounds...pretty set in stone
I wouldn't be concerned if I saw Resources.LoadAll<Character>("Database/Characters")
(i'd add an extra folder, because I bet you'll want other databases later)
But, will not get an error when compile it? Because when compile will be everything binary?
i don't understand what this means
Thats my code
https://pastebin.com/hMypbJQa
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Resources.Load does not care about actual file paths
File paths do not exist in the built game
The names you use are derived from the folder and asset names you used
I guess I'm not sure what you're worried about right now
I was worried if typing the exactly name folder will works when compile the game
But, if will works, okay ^^
I'm trying to setting a DLC content
Is my first time working with DLC
So I'm confuse :/
i was following a tutorial for unity and when i tried to use any kind of Input i got hit with this message
it is from a 3 year old tutorial and i already changed code testing it without inputs and it works but any time the if statement requires an input it breaks
!input
To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling
• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.
im following a tutorial and for some reason im getting a weird error from "SimpleMove"
You can't name your own class CharacterController
I think your ide is not set up properly.
For your issue, I'm guessing you have named your own class CharacterController as well (it's cutoff in the screenshot), which is where the error comes from. The easiest solution is changing your class name.
is DrawMeshInstancedIndirect available for unity shadergraph?
Ah
Makes sense
Im using vscode for my ide
I mean you need set allow Instansing check box in material settings
If it's underlining errors it's most likely configured , you can double check if you declare a variable of type Rigid.. you should see all the unity options like Rigidbody
it was the script name
The type or namespace name 'EnumerableApplyChangesToContextCommand' could not be found (are you missing a using directive or an assembly reference?)
Im getting an error with the Test Framework unity package
and its with every unity project I make
this is one of the lines thats erroring command = new TaskTestMethodCommand(test);
the other is this
command = new EnumerableApplyChangesToContextCommand(command, changes);
Yep
You're not coding anything, you're getting an error coming from that package
I didn't understand
Uhhh perhaps its a problem with your unity version, messed up package for it or something..
You could probably just uninstall the package if you arent using it
I cant
Its test framework
its a dependency
Oh
and I'm using the newest version of both unity editor and Test Framework
Try switching to an LTS

Don't ask why my unity installs are in my Unity 2021.3.2.21f1 folder
I dont know myself
Sorry not exactly sure without seeing the script that is calling that, but it's probably just missing a using line at the top
That doesnt solve my problem, 😭 What is the missing using
using System;
using System.Collections;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands;
using UnityEngine.TestTools;
using SetUpTearDownCommand = UnityEngine.TestTools.SetUpTearDownCommand;
using TestActionCommand = UnityEngine.TestTools.TestActionCommand;
I'm so very confused
Definitely sounds like the test framework package it downloaded has issues
Try closing unity then deleting your library and packages folder and reopening unity
Omg ive done that 5 times
Try another lts
This sounds like a problem with your package cache
I've seen this happen a few times
for whatever reason, a file is just Completely Missing™
it results in nonsense errors like this
Do the following:
- Close the editor
- Delete the UPM package cache. This page tells you where to find it.
- This will make Unity download the packages again if they need to be reinstalled
- Delete the Library folder in your project
- This will force Unity to reinstall the packages
- Reopen the project
If you don't clear the global cache, you'll keep getting the same broken package over and over
Im relaunching my unity project right now, Thanks for the help
Ive done both of those things and im still getting the error
having your installs in OneDrive is already very weird
i would suggest removing the editor and fixing your install directory
I have them on my desktop
yes, which is a folder inside of OneDrive
my install path on my Windows machine is C:\Program Files\Unity\Hub\Editor
who installs a program in the desktop
Me
well time to stop. leave it as is unless changing to another drive
I would have left it as it was but my unity broke itself with a glitch not installing anything so i had to manuanly install some stuff
even projects should not be in onedrive/dropbox/gdrive as its a bad solution
that sucks but probably was a better solution
what do you mean by "jitters a lot"?
it sounds like there's some fundamental problem here
completely remove your editor installs and the unity hub
restart, then reinstall the Hub
do not change any default settings and install the editor
thats what im doing right now
i did that it works now thanks very much 😄
how do i make my movement smooth?
define "smooth" ?
also that += most likely supposed to be just +
& the function should be in FixedUpdate
so what exactly isn't smooth about it ?
its jittery like
Okay give me a second
alr , can try it with interpolation enabled, see if helps.. but if you have follow camera it might be the camera itself
Should definitely enable interpolation
mp4
discord wont let me embed it
Hard to see on mobile but does it jitter if you stand still and just look around?
No
Also show the rest of the code, how is the camera set up, are you moving any rigidbody or its parent via transform or animator, etc
Also a general tip, setting targetFrameRate to a low value makes it easier to debug sync/jitter issues.
I also like to have a toggle for slow motion (Time scale ~0.1 or something) for debugging
ill keep that in mind
I dont even know where this is called from
its in update
Cant help without seeing all the code. Too many different posskble causes for this
And is the camera a child of the rigidbody object or what?
Usually camera movement is done in lateupdate anyway
Otherwise another script might move stuff in Update after the camera has moved for that frame
unrelated, but also why is that clamp happening after passing it to the camera ? 🤔
hello i need help figuring out why when i set this bool active in another script the gameobject doesnt appear/activate , but when im starting the level the deactivating works
public class appearPlate : MonoBehaviour
{
public GameObject objectToControl;
public TriggerHandler key2active;
void Awake()
{
}
void Start()
{
MakeInvisible();
Invoke("MakeVisible", 3f);
key2active = FindFirstObjectByType<TriggerHandler>();
}
public void MakeInvisible()
{
objectToControl.SetActive(false);
}
public void MakeVisible()
{
if (key2active.appearPlate == true)
{
objectToControl.SetActive(true);
}
}
public void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
collision.gameObject.transform.parent = transform;
}
}
void OnCollisionExit2D(Collision2D collision)
{
if (collision.gameObject.CompareTag("Player"))
{
collision.gameObject.transform.parent = null;
}
}
}```
are you talking about the MakeVisible method ? put a Log before the if statement to verify its being called properly and print something useful with it like the key2active.appearPlate
also fyi big code like this should be posted using link services
!code 👇
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
The key2active.appearPlate bool you mean?
Is the other class just changing the bool or is it calling the MakeVisible method?
it just changes the bool to true when the player collides with the other class , im trying to have a gameobject appear after collecting an item
fixed it
you should most likely use a property for that
would this be a good place to look for a partner to start learning unity with?
:loudspeaker: Collaborating and Job Posting
We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**
oh okay thx
Neither of these are code questions :/
that would fall in graphicas i believe
If this canvas, change canvas mode to "cameraSpace" and pin camera
It was actually because of the Z
Maybe
not code related = not for this channel
try #💻┃unity-talk
thought that was just for general discussion, didn't realise it was a help forum too mb
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #🌱┃start-here
unity is bugging with sprites on 3d. wrong layers being rendered first
is there a solution to this?
99% user error but wrong channel too
i was being stupid and it was just ordering layer
seems like an unsupported material
this is a code channel
ask in #💻┃unity-talk or #1390346776804069396
Whoops wrong channel
Coz server has million channels
I have a particle system that isn't a child of the player and I have a empty game object that the particle system follows. I have this script and it should stop the particle system from rotating with the player but it doesn't work. Am I doing something wrong? If I freeze my player's rigibody rotation then the issue is fixed but I need my player to be rotating.
``` public Transform trailTarget;
private void LateUpdate()
{
if (trailTarget == null) return;
transform.position = trailTarget.position;
transform.rotation = Quaternion.Euler(0f, 0f, 0f);
} ```
Is the particle somehow following the player?
Its(Quaternion.Euler(0f, 0f, 0f);) using as I know global coordinates. Maybe you can try set a same rotation as a parent instead?
When you say "it doesn't work" what do you mean?
What is actually happening?
HOLLLY pfp
i've never thought i would come across this
nice pfp you got there man, peak band
🤤
Its following the player's rotation which I don't want.
doesn't look like it's following the rotation at all
it's following the position of an object that happens to be on the rotating part of the ball
Step 1 here is switch your tool handle position to Pivot
so you can actually see where the objects are
Step 2 is move the position of the TrailTarget object to the center of the ball:
or do you want the trail on the ground, rather than the center?
Hey everyone! Y'all ready for some dummy questions?
What would you define as a vertical slice?
I want the trail on the ground
ok all you need to do is this then:
- Move the TrailTarget's local position to 0,0,0 (the center of the ball)
- Change your code to this:
cs transform.position = trailTarget.position + Vector3.down * 0.5f;
delete the line about transform.rotation, it's not needed and does nothing
Once it's working you can change that 0.5f to be something configured in the inspector somewhere - it's whatever the radius of your ball is
you can adjust it as needed to match the size of the ball
@wintry quarry Thanks for the help! works perfectly now ❤️ 👍
Im doing a moovment with animations but the diagonal line IDLE are not working
Wait how do you have colored labels in unity?
✨ASSET STORE✨
dang. never knew asset store included stuff like that XD
thx though
wait till you find out about odin 😉
Yo, I'm adding a script component to an object during runtime and then I want that script to change the sprite of the object. How do I do that? I can't preset the sprite in the editor because the script doesn't exist on the object yet
i might be overthinking it but you could just use SOs for this?
Make a function on the script that accepts a sprite parameter and call that function
cs public void SetMySprite(Sprite s) { mySpriteRenderer.sprite = s; }
yeah but if they are adding the script at runtime, he cant "preserialize" the fields 🤔
he can serialize it on the script that calls AddComponent
yeah thats what i was thinking
well i was thinking of using an SO and having the script on the object reference that
```cs
public class Example : MonoBehaviour {
public Sprite theSprite;
public void AddTheComponent(GameObject go) {
MyScript instance = go.AddComponent<MyScript>();
instance.SetMySprite(theSprite);
}
}```
my suggestion was to use an SO instead of a direct sprite field
simply if other run time scripts need to work with other sprites they can all get a reference to their respective one from the same field
if that makes sense
i guess i was overthinking it slightly but the idea is the same in principle.
basically at some point something needs to reference the sprite somewhere and pass it where it needs to go
yeah
it's all just a game of references and interscript communication
What would it look like doing it through an SO? I'd like to keep my script that adds the component clean if I can
it'd be the same except you'd reference an SO that then contains the sprite reference instead of the sprite directly
just an extra layer of abstraction
you can keep a list in either case
the field can do that too on the script itself
yeah
but i would say its maybe good habit though
ty both 🙏
its not nescessary i would just use SOs for stuff like that, easier to edit later rather than slouching through scripts, especially if you need to get references to the same sprites elsewhere
if i am in a lobby and force quit the game and then reopen it and try to create a lobby because i never left the other one i get rate limited. is there a way to destroy the other one in this example? maybe when reopen search if my id has an open session?
anyone knows the correct way to handle this guys?
#1390346492019212368
or if you are referring to unity's lobby package or whatever #1390346533127458889
im making a train game similar to the board game rush hour. and im moving the individual peices along a spline like this. but to move it im transforming the position, which means when my object is supposed to collide with a wall or another train, it just goes straight through the other object. is there another method i can do to move an object along a spline (or path) using the rigidbody instead of transforming the position
sorry this might not be the right channel to put this in my bad!
You would need to instead move the object via physics
Meaning you have to grab the next goal pos from the spline and use physics to move towards that
translation bypasses physics so will not work (meaning you cant use spline animate anymore)
@barren iris
yeah thats chill
fine with that
spline container/spline has functions to sample a position so thats easy
im a complete beginner, any tips on how to get started here
there are also functions to get the relative position 0-1 on a spine for a 3d position
i got this i think
float splineLength = splineContainer.CalculateLength();
progress += input * (moveSpeed / splineLength) * Time.deltaTime;
Yea if you have your own "spline progress" float you can increase it, sample new spline position and change the rigidbodys velocity (or use MovePosition) to move via physics.
If you detect the rigidbody stops moving then it "hit" something (or use physics events)
can someone take the time to help me with my wall jumping mechanic? My wall check object doesn't flip to where my character is facing and i have no idea on how to fix it
specifically how to make it so when my character turns around, the game object flips with it
well how are you turning the character around
moveInput.x = Input.GetAxisRaw("Horizontal");
i didn't ask how you are getting input, i asked how you are turning the character
if it is AI generated then i will not be helping you
my partner on the project wrote it 😐
then why not just ask them
discord? how do you even have the project
its through unity version control, i just signed in through the school email cuz i wanted to keep working on it
void Move()
{
moveInput.x = Input.GetAxisRaw("Horizontal");
moveInput.y = Input.GetAxisRaw("Vertical");
moveInput.Normalize();
if (moveInput.x != 0)
{
animator.SetBool("isWalking", true);
}
else if (moveInput.x == 0)
{
animator.SetBool("isWalking", false);
}
// Sprite Flipping depending on movement direction
if (moveInput.x < 0) // Moving left
{
spriteRenderer.flipX = true;
}
else if (moveInput.x > 0) // Moving right
{
spriteRenderer.flipX = false;
}
}
you have a school project with a partner and you dont have a way to contact them?
also
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
ik this was not a smart move on my end
i dont see why this is relevant
asking who wrote the code how it works is often the fastest way
i am aware
also you're going to have a harder time getting help if you don't even understand what is already there and working
Oh well this code uses the flip x option so you can know from this which way they are facing
If looking right is the default and flipx is false, they are looking right!
It is but if you did the scale -1 trick then flipping the sprite would be wrong
Anyway the code flips the sprite based on user input so thats why that works
So reading flipx will work to know the "last input direction"
or you record your own bool based on input
so would i want to flip the wallcheck using flipx in the else if?
or just determine which direction to do the wall check in based on the flipX property
change the direction in which you check for walls? yes
you can do something like this:
```cs
Vector2 checkDir = new(spriteRenderer.flipX ? -1f : 1f, 0f);
spriteRenderer.flipX ? -1f : 1f is a fancy way to do:
```cs
Vector2 checkDir;
if(spriteRenderer.flipX)
{
checkDir = new(-1f, 0f);
}
else
{
checkDir = new(1f, 0f);
}
i dont think this helps what im trying to do
why not
i dont think im explaining this correctly
show how you are doing this wall check
the sprites work fine
the advice given is not about fixing the sprite, it is about using that property to determine what direction your wall check goes (because presumably it is a physics query like a raycast)
its the direction to raycast to check for a wall
looking right? shoot to the right.
looking left? shoot to the left.
Wall check is an object on the player that detects if it is hitting a wall (which works.)
The problem is that the object doesnt flip to where the character is facing.
I can also send my walljumping block of code if that helps
how does it "detect if it is hitting a wall"
i certainly hope it isn't just a physics message (OnTrigger/CollisionEnter)
yea probably is
when the object comes into contact with a object with the wall tag and wall layer
which makes this harder for no good reason 😆
how
would it just be easier if i sent the script, me and this other coder literally dont know what we are doing and we are just following youtube videos
typically when someone asks how you are doing something, yes they mean in the code.
at least that's the case in a code channel. like here.
!code 👇 and don't ignore it this time
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
again dont know what im doing
the bot message?
its showing how to send code properly, either through pasting services (prefered) or using inline for smaller chunks
cant i just send the file like i just did?
what do the bot instructions say
or did it get hidden 0r something
no, not everyone can see/read it. they can't properly help . . .
ah ok
that's why the bot exists; to explain how to properly send code . . .
would you download random files people send on discord?
fair point lol
how do i post it with a scroll bar thingy on the side of it
or can i not do that
ok ok
Basic reading comprehension is a prerequisite for using unity
i think you are being awfully rude to me my friend
its big but thats the wall jump code
"its big"
So what did the bot message say about large blocks of code
i literally did what it told me to d
put three backquotes on the front and the end\
"smaller chunks"
i was told by boxfriend here that it would add a scrollbar
I said no such thing.
the pasting services are free and half of them dont require accounts, if you want us to help you, make it easy for us.
Again, reading comprehension
nobody wants to scroll up and down a discord channel just to see all your code at once
im sorry that im not making it easy for you guys, i dont know what im doing
read the bot message
please
there are links
go to the paste service, paste your code, send us the link
would be prefered as well but this works too if the issue lies here
oh alright gimme a sec
full script: https://paste.ofcode.org/4XU9xJd7N4E7tMCMMEPgmp
also thank you for letting me know that one of the links didnt require an account, that was one of the reasons i wanted to try discord first lol
i know there was some way to add some sort of scrollbar to the code on discord but i guess not
is "wallCheck" a child of the player?
yes
anything to fix it yet or still looking?
How can I generate two or more numbers within a range that do not repeat? Is the best way to use a list then remove the options as I pick them?
Yea best to make a pool, then generate random indexes for that pool to the pick a value
gotcha, thanks!
i'm reading up on Physics.RaycastNonAlloc and i'm a little confused as to what the size of the array does. i've tested a little and haven't found out any real differences based on values. what does this do exactly so i don't mess something up?
Because you make an array and re use it it's capacity defines the max amount of results can get back
That's why it returns the amount
Therefore make the array with a good size that you deem is big enough
so the size of the array translates to the amount of hits the buffer can store?
Yes the max amount
cool thanks ^_^
If it hit/overlapped 15 things but the array is 5 in size then you get just 5
unity really needs general help but did somebodys unity start behaving weird after 6.3 updates
rotating object in editor with gizmos rotates is really fast, small movement results in 700 degree rotation and such
only on rotating objects and on every platform (windows, mac, linux) 6.3.3 version
There's another issue too where if you're reversing the rotation gizmo it goes the wrong way for a bit.
im using 6.3.2 and im not experienceing these issues, but then also the latest version is 6.3.6 so maybe try that?
Hello everyone. Not sure which channel this question is for. I have a character model from mixamo that is floating above the ground whenever I move it during play. I'm new. Is this a common thing new people come across?
Thank you
Hi 👋 I've got a little issue... I'm making a script that should be able to use a void of another GameObject but after following and debugging a tutorial and I have an error constantly.
private bool isActive = true;
public GameObject player;
private void OnTriggerEnter2D(Collider2D other)
{
Debug.Log("Trigger touched by :" + other.name);
player = __gameObject.GetComponent<player_character_movement>().JumpRefill();__
if (player != null && isActive)
{
}
}
(I'm trying to translate my error from french)
Impossible to convert type 'void' into 'UnityEngine.GameObject'
Thanks !
factssss 🤘
Its telling you exactly what's wrong , you're trying to assign a function call into a GameObject type. This is pretty wrong
cs player = gameObject.GetComponent<player_character_movement>().JumpRefill();
The player = part is the problem. It makes no sense here.
Also they're not "voids" they're methods / functions. Void is no return type
And then how do I use the JumpRefill ?
- Get a reference to the instance of the other script
- Call the method on the reference
you're trying to do some weird frankenstein combination of these two. You sorta have the concepts floating around but all the specifics of how you wrote it are incorrect/out of place
Also naming a class player_character_movement is very confusing for everyone.
Yeah, I tried following a tutorial but it got me an error so I tried a bunch of things and did not really find anything
follow the tutorial
instead of guessing at stuff
If you got an error following the tutorial you did something wrong.
in the tutorial the guy does
var player = gameObect...
But for me it doesn't work
Your "player" should be storing a "player_character_movement" then call the method
they don't do:
var player = gameObect...
finish the complete line that is in the tutorial
and show what you tried
and show what error you got
When you fully check over everything, you will see that you did something differently
I mean, yeah the code works in theory but it does not work 'cause i need to use a OnTriggerEnter2D instead of OnCollision2D, what I wan't to do is this the same but it just doesn't work with collision because(I think) OnCollisionEnter2D works only if the GameObject isn't set to trigger.
What are you trying to do
If you want a trigger interaction, you would use a trigger collider and OnTriggerEnter2D
If you want a real collision, you use a non trigger collider and OnCollisionEnter2D
Neither of those changes all that much about the little code snippet you're having trouble with
I've made it so my character has doublejumps that can refill over time, but when I touch a certains object, it instantly recovers 1 double jump.
Here is the code that could work if I used OnCollision2D :
using UnityEngine;
public class JumpRefillScript : MonoBehaviour
{
private bool isActive;
private float resetTimer = 5;
private void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("Refill touched");
var player = other.collider.GetComponent<player_character_movement>();
if (player != null && isActive)
{
player.JumpRefill();
isActive = false;
Debug.Log("Refill done");
}
}
void Update()
{
if (!isActive)
{
resetTimer -= Time.deltaTime;
if (resetTimer < 0)
{
isActive = true;
Debug.Log("");
}
}
}
}
but line 10 has an error if in the void i put OnTriggerEnter2D
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
and don't just say "has an error"
show us:
- The exact code you tried
- The exact error you saw
We can't do anything without actually seeing the problem. A vague description isn't enough.
Ok, so I've played arround a bit more with my code and managed to get a code without any errors in it...
using UnityEngine;
public class JumpRefillScript : MonoBehaviour
{
private bool isActive = true;
private float resetTimer = 5;
private void OnTriggerEnter2D(Collider2D other)
{
Debug.Log("Refill touched");
var player = GetComponent<player_character_movement>();
if (isActive == true)
{
player.JumpRefill();
isActive = false;
Debug.Log("Refill done");
}
}
void Update()
{
if (!isActive)
{
resetTimer -= Time.deltaTime;
if (resetTimer < 0)
{
isActive = true;
Debug.Log("Refill recharged");
}
}
}
}
The issue is, when player and entering in the trigger i get this error :
cs private void OnTriggerEnter2D(Collider2D other) { Debug.Log("Refill touched"); var player = GetComponent<player_character_movement>();
why did you just throw your hands in the air here and do this completely differently than before
You need other.GetComponent<player_character_movement>()
the way you have it right now it's trying to get that component from your own GameObject, i.e. the one this script is attached to
you want to get it from the thing you triggered with
aaaah alr
you're also probably going to want to check that it's actually the player you collided with.
But that can come next
oh yeah I saw that. Anyway, it works now so thanks and really sorry if I'm doing things a bit randomly I'm still trying to get around and trying to undertstand what I'm doing and what to do
not sure what channel to put this in but how can i have components such as vertical/horizontal or grid layout group to stack upwards instead of downards vertically?
more of a #📲┃ui-ux question..
you can maybe set the spacing to a negative number?
am i suppose to hard code the distance at which my chunks switch to half resolution?
is there any way to like WaitUntil like in coroutine but in async void?
```cs
while (PhotonFusionWrapper.instance.runner.ActivePlayers.ToArray().Any(p => NetworkPlayer.GetNetworkPlayer(p) == null))
{
await Task.Yield();
}
i do it like this but im pretty sure the thread just stops lol
(im trying to wait until all players have their player prefabs spawned)
their question wasn't about networking at all
thought photon is network related and might be a better place
i looked at the time it was asked and assumed no one knows the answer so i linked the channel
if someone did know about async in general i think they'd be here though
there is this SO post
https://stackoverflow.com/questions/69282112/how-to-do-waituntil-in-async
but i can't verify the accuracy or quality of the answer since i haven't used async
even though its a networking theme, he still needs help about something BUT not network related help
so help him then
does anyone know how to generate either an image file or sprite asset at runtime?
Have you googled it? Decent amount of resources
I have but I guess I'm not good at looking
best I found was some Unity forum mod taking the conversation to DMs instead of putting the solution in the thread
I think I've got it now tho
Do you mean save the texture to files?
no I mean actually convert the texture into a sprite *and save it as a new file, but I've got it now I think
A texture is a sprite
it's not
How
textures and sprites are separate things
in unity asset terms, Texture2D is an imported asset, and Sprites are assets generated from that Texture2D
a sprite is a texture would fit yes but the oppsosite we can argue
yes, you can create sprites from textures
i just said that
that doesn't mean they're the same thing
In the context of files, it's the same thing
a single texture2d can have multiple sprites from different rects
Its sprite sheet
so that would be a texture that has multiple sprites, yes
Well, the point is that a sprite is not just something separate, sprite it's an area on the texture
how do I learn coding for unity? I mean I kinda can read the code and after uning my brain for 5 or 10 minutes it does start making kinda sence but how on earth would I as a beginner write a code like that
```cs
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
public float moveSpeed = 6f;
public float jumpHeight = 1.5f;
public float gravity = -20f;
private CharacterController controller;
private Vector3 velocity;
void Start()
{
controller = GetComponent<CharacterController>();
}
void Update()
{
Vector2 input = new Vector2(
Input.GetAxis("Horizontal"),
Input.GetAxis("Vertical")
);
Vector3 move = new Vector3(input.x, 0f, input.y) * moveSpeed;
// grounded check
if (controller.isGrounded)
{
if (velocity.y < 0)
velocity.y = -2f;
if (Input.GetKeyDown(KeyCode.Space))
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
}
// gravity
velocity.y += gravity * Time.deltaTime;
// combine horizontal + vertical
Vector3 finalMove = move + velocity;
controller.Move(finalMove * Time.deltaTime);
}
}
out of thin air. It seems like guessing magic spells for me.
This one is made by AI because no forum or documentation is actually explaining it
you would learn, and as you get more knowledge and experience, you can start synthesizing new code from your knowledge/experience
you can think of them as magic spells, sure. but mages don't guess, they know from study and practice
that's how you get knowledge and experience
yeah but for that to happen I need how to code in the first place. that code wouldnt spawn in my head just by looking at the blank VS screen
so you saying i want my player to move, type some pseudo code unity doesnt understand and magically it should work after some time? the documentation doesnt explain that step so how would someone learn that
there are beginner resources pinned in this channel, have you tried checking those out
no, that's not what i said at all
i looked trough them and they are a$$
"beginner" is a vague term. if by "beginner" you mean "someone who can't code", you would not write code as a beginner
you would first learn how to write code, and then you wouldn't be a beginner anymore
it's a long process, this is an entire skill on its own
you wouldn't learn masonry by building a whole fireplace without any prior knowledge or experience
i can write html and css, i went trough the whole w3school explaination on how c# works and i got a rough idea of the building blocks that come with it. storing values in variables and doing math but unity has their own functions that i never heard of and they dont explain or list them anywhere and assume everyone knows what they mean
they're explained in docs
that's what docs are for
no-one knows this stuff magically, we use the resources at hand
that's what the pinned resources are for
unity is using some etxra libraries and extra stuff, syntax and stuff are all the same
but if you are new, i´d recommend learning the basic of c# first
just console app or some win forms beginner projects
the basics are only that you do math with variables which you assigned values to. thats all what I know about C# so the bigger problem is to guess what functions unity is hiding. I had spend so much time just to find out you can use the character controller insdead of assigning movement to every button and joystick seperatley
you don't have to guess
you can check docs and/or follow guides or tutorials
insdead of assigning movement to every button and joystick seperatley
you still have to do this, input handling is separate from actually moving the character (but there are defaults provided)
I checked all docs that are pinned here and not one lists all unitys build in "slangs" that can be used in code. Its only when i watch a tutorial or ask AI where I discover new stuff
you will find out about the most used componenets over the time
ok mate, we can't read your mind. what in particular are you referring to, so we can actually provide targetted guidance
(also, by "slangs" do you mean specific classes/components, or patterns/idioms? that's pretty vague)
im not reffering anything im talking in general. No matter what I want to do in unity, its all assumed to be known. If I want my camera follow my player (which should be a build in thing because thats what 99% of all games do) I have to somehow code it
yes, all of unitys variables or whatever its called
or you use cinemachine hehe
the fields of unity's components are documented in docs
its all assumed to be known
no, it's assumed that, for anything you don't already know, you can seek that knowledge yourself
whats that?
guides aren't going to explain every single little detail. otherwise they'd all by 8+ hours and take months to make
they make some vague assumptions about your skill level and experience, and they might be wrong, but when they are, you can just seek this information yourself
and where is the best place? because everyone doing stuff differently and the docs just give an abstract understanding of it without explaining or providing the base code
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
depends on the specific thing and your past experience. "best" is impossible to define.
docs are the overall most accurate resource (unless you count source code) but they are, by nature, technical documents
if you aren't willing to go to that yet, look for guides or tutorials, like those in unity learn 👆 or pinned in this channel
everyone doing stuff differently
right, because there's tons of ways to do any specific thing.
or providing the base code
not sure what you mean by that. plenty of docs have examples
To be honest, the ability to search for information is no less important than programming itself
i have a feeling that you are not researching enough before starting development.
like as you said you started programming your own player controller than found out about the character controller
Them asking is researching to be fair
i feel like they're bringing a lot of unbased assumptions in without being willing to challenge them :/
because with google I always feel like hitting the wall. even for player movement which is like step 1 of bringing a game to life but theres no clear explaiation, or code to copy. Isnt moving a character the same thing in every game and should be a pick of a few different variations (first or third person)? thats the reason I use AI is because google just isnt a good place to look up stuff anymore
Isnt moving a character the same thing in every game
no
ok mate, just ditch AI. it's not gonna help you learn
Google is still a good place to look up stuff
No, in every game it can be implemented in its own way and only at first glance it may seem the same
@stuck parrot none of us magically understood programming randomly one day. we started as beginners too. we're recommending these things because they work
so whats the best workflow now. not knowing how do do something > googeling this problem > reading documentations, watching videos and coming up with ideas that eventually work? I understand that programming is not easy, and that unity needs code to work. But shouldnt game development be more of an creative and artistic task? I mean its fun to make 3d models, characters and bring them to like but the coding parts seems like labour
not knowing how do do something > googeling this problem > reading documentations, watching videos and coming up with ideas that eventually work
this is a pretty good idea, yeah. if you asked me to come up with something on the spot i'd probably say this too