#archived-code-general
1 messages · Page 124 of 1
so you want to be able to rebind "W" to do something else
and still have "A", "S", and "D" be part of the movement composite
Yup
i've never touched input rebinding, so i don't have any advice, unfortunately
oh okok no problem :))
In composite building if you press e. g. A and W buttons simultaneously - they gonna both be triggered.
In non-composite building f you press all the buttons together - works just one that you have pressed a few milliseconds first
it's like if and else if
yes
Composite:
// you can press all 4 in Update for example
if (W) ...
if (S) ...
if (A) ...
if (D) ...
Non-composite:
if (W) ...
else if (S) ...
else if (A) ...
else if (D) ...
okok
so how am i supposed to still have them composites but have them rebind separately?
what do you mean?
I do not get
like i saw tutorials where they rebind all of the keys at the same time
like one button and then rebind wasd in the same time
they change isComposite value I guess ??
or isPartOfComposite
yes but i dont want that
why do you say it then?
im so sorry i dont know how to explain
if you cannot explain - I cannot answer
write in your own language and then translate into English
that does not make sense
you're making the flashlight point in the direction from the camera to the center of the world
what's wrong with transform.forward = camera.transform.forward?
ok so i saw it in a tutorial because i was trying to rebind my keys. And then i saw that they did the wasd that way wich is not what i wanted to do. I wanted to do it separately so i tried to find something like that, wich i didnt find. So im trying to ask peoples here because i dont know where i can get help
ok, that's a nice story, but what exactly you need to do?
And the main question is : Im trying to have one button for each keys of wasd and not one to rebind all of them at the same time
but because its composite it doesnt work and i dont know why
why cannot you make it not composite?
or I don't understand something?
because its in vertical and horizontal axes and we need them together to work
I guess you should create one composite binding for W and S, and another for A and D then
yes but if i do that i will still have to do ws and ad on a single button
like one button for ws
and one for ad
Up is a binding, as is ZQSD-WASD
it sounds like you need to rebind Up
rather than trying to rebind ZQSD-WASD
you separate them
is it possible to make the wasd not composite without losing the fact that i can do horizontal movement?
yes, you make horizontal (A & D) and vertical (W & S) movements
my bad not horizontal diagonal *
you'd just put the two inputs together in your code.
yes, I guess they wanna move horizontal as one composite and vertical as another
to make sure we're all on the same page here
the problem is that, when you try to rebind a composite binding, you have to rebind all of the parts of the composite at once?
what do you mean?
like is it possible to not do a composite at all and still do diagonal (like if i press w and a at the same time)
i.e. if you try to rebind your movement input, you have to set the Up, Down, Left, and Right keys
they gonna create two composites how seperate horizontal and verticals movements I guess ??
i dont want composites at all
i don't think anyone here is on the same page right now
but you have said...
yeah, me too
you should explain what you wanna do
explain with if, if else, else maybe?
i will come in a few minutes
okok
You guys should make a thread
this should really go in #🖱️┃input-system
i switched on the other channel
which quality setting does the editor use? Is it the same as PC standalone
it should be whatever is highlighted in the Quality menu
okay
How would I make it so that code runs when an object interacts with the solid part of a platformEffecter2D? Using onCollisionEnter2D still registers even when the object just passes through and doesn't actually collide with the solid part.
can I use Render Pipeline Assets if Im not using the standard pipeline?
the scriptable render pielines used those, yes
no I mean
If i am using the standard pipeline
sorry mispoke
if im not using any special pipeline
then no, because you're not using a scriptable render pipeline
right, there are no scriptable render pipeline settings, 'cos you aren't using a scriptable render pipeline
ah
but I cant create one?
well, no, because you aren't using a scriptable render pipeline...
the settings menu always shows that, AFAIK
Hey I wrote something like
public static void Change(Vector3 pos, int amount)
{
Terrain ter = Terrain.activeTerrain;
TerrainData terrainData = ter.terrainData;
Vector3 converted = ConvertWordCor2TerrCor(pos);
int x, y;
y = (int)converted.x;
x = (int)converted.z;
int[,] prev = map;
map[x, y] = amount;
// Assign the modified map back.
terrainData.SetDetailLayer(0, 0, 0, map);
}
It sets detail on terrain, but now I need to set not only one point but points surrounding too, and additionaly return a 1 if the detail map changed (is diffrent than was before). Can anyone help? I have no idea how to do it honestly
how do i stop a running coroutine?
put it inside a variable
el goog
it's not that you're makign the coroutine "a var"
you're saving the result of calling StartCoroutine
and then using that to stop the coroutine later
that's all
alright, thank you
why do the wood logs show up in the scene view but not the game view
they are probably behind the camera and not infront
not code question btw
I want to understand how saving on a json file works in unity instead o just memorizing it, what i understand so far is usually you make a class with all variables you want to save like health, score etc. Then you make an object out of that class and save it. For loading you can load data from the file to the object.
Did i understand it right? or Im missing something.
pretty much
cool thanks
the same like in PlayerPrefs
much better though
So the thing that seems to be causing all the lag is Semaphore.WaitForSignal
which one is much better?
.json for normal projects of course
its following this pattern where it does a bunch of things, waits 50 ms, and then does all the rendering
like this
deos anyone know why it is waiting?
oh yeah true.
if you need to save one value like score - u may consider using PlayerPrefs
or what it is waiting for?
not really recommended even for 1 value
yes, even though
yeah right now im using it to store my score, much easier to use. but not fleixable at all.
json?
PlayerPrefs lives in your registries and it sucks being ported across versions
no PlayerPref, right now Im converting it to json based system cuz the game is getting bigger
json is better to work with , you can also later on store that directly in a document based databse since they usually accept POCO's
POCO?
where is multithread rendering in player settings
I cant find it
when you prepare to save to json you're making a POCO
oh got it
anyone?
these aren't code specific questions @static matrix
ok then where do i go
probably in #💻┃unity-talk
ok then
I am trying to save the initial position of touches so I can calculate which direction the user is swiping, if they are swiping. I am saving them in a dictionary with the touch as they key, but when it tries to access the touch it says that it doesn't exist. Does anyone know why this could be? Here is my code https://wtools.io/paste-code/bNxl
You can use objects like a touch as the key for a dictionary right?
Anyone have an idea on this
check it's z position probably ??
I was trying that , it didn't seem reliable... I was thinking of using an empty game object somehow
what do you mean by "it didn't seem reliable"?
once it's position equals or is more than something...
The z is the rotation.. I added it in to a new quaternion , I'll try looking at the objects tranform.rotation with the vector 3
quaternion x/y/z/w values are NOT euler angles
they are the four components of the quaternion
you want .eulerAngles
what's the problem here?
if (transform.eulerAngles.z >= smth)
{
// whatever
}
transform.rotation.z is the third component of the quaternion, not the rotation around the Z axis. transform.eulerAngles.z is the appropriate value.
ok, using eulerAngles may be good then 🤔
I'll give that a try
that code is not correct.
yes, as @heady iris said, try
if (transform.eulerAngles.z >= smth)
{
// whatever
}
Ok , so the issue may not be the z position it may be the code , will post one sec
how can I clear a json file? can I just do this:
string json = JsonUtility.ToJson("");
File.WriteAllText(path + fileName, json);
File.WriteAllText(filePath, JsonUtility.ToJson(new { }));
thanks
don't say it until you are sure that works
if I do this It will just add "" to the file instead of replacing it?
I wonder if it can be in json 🤔
you helped and Im thanking you no matter if i works or not
webgl build just shows nothing with universal rp 🤦
but you can do it I guess. { } is empty object
not this channel I guess
I'll try, Your solotion is working btw
I hope
ok , sorry had to tend to my chickens ... the first script is suposed to overide the rigidbody 2d physics, the second script is the seesaw object where I call it when seesaw z rotation = 25
https://pastebin.com/AxZ5H9LM
https://pastebin.com/W4jCFjNP
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.
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.
what channel should i ask help in?
your solution works as well, I don't see the reason of asking that question too though 🙄
#🌐┃web ??
yeah i just tried it works, What question?
that one, you already knew the solution 😌
imagine an object on the seesaw I get the normal behavior (black circles on fig 2) . i want the red circles
what are those circles supposed to mean?
Its an object on the seesaw
The tennis ball falls and the cannon ball arc's up and to the right ( as normal physics will allow )
I want it to go up and to the left .. opposite of natural physics ( red circles in above image )
I don't really understand
maybe you can draw it?
with lines
mess with the masses
masses are still "normal physics"
oh, I see
yes, you wanna...
yes, that's how normal physics works
in case black ball won't collide with that tube
No the first black ball goes up and to the right
sorry?
Tennis ball falls and launches the cannon ball the opposite of the black arrows
like that you mean?
I don't think changing physics is a good idea
my acrprojectile script shjould over ride that
do something with your scene
or maybe that's because of that tube?
@tawny mountain even though, if you need it, look here: https://stackoverflow.com/questions/65980814/recommended-strategy-for-overriding-certain-rigidbody-collisions-in-unity
The easiest way might just be to take full control. On the correctly timed press, disable the RigidBody and the Collider. Then just move it yourself to the target location. It's really hard to get precise control over a RigidBody -- every FixedUpdate(), it might be picking up force from collisions, and there can be many FixedUpdate() calls between Update() calls.
Shit , I'm looking at physics and I could just lerp between positions maybe. Current position and target position
HI :p
i'm studing inverse kinematics for some time, but idk how to render it
for a single leg creature i used linerenderer
but now i have 6 legs
im using FABRIK in my IK
six linerenderers?
i I thought about that, but idk if a single object can have 6 linerenderers
in other simulation i did a jointRenderer script with one linerenderer for each joint
but it seems to be very expensive for the computer to render
the docs suggest using separate renderers for separate lines
i wouldn't think six lines would be too bad!
how can i do that?
i know this is a bad explanation but: is there a way for me to create an array of "conditions" (ie script variable here) that can be accessed and then be used by another script? kind of like the condition menu from the animator but for c#
separate game objects with a line renderer on each one
not specific enough.
Do you just want to create a list of dropdowns?
not really? more like a list of script variables but from other scripts
describe what you want to do
not "have an array of conditions"
what are you creating?
ok so basically i have a door that i want to open but only when all switches are turned on. i was thinking the best way to do this is to have the door reference the switch scripts of each switch and see if they are on or not.
ah, ok
referencing arbitrary variables on other components isn't really practical -- that'd involve reflection
since you'd be able to get any variable from any component, pretty much
sounds like you have a much more narrow use-case, though
i think the neatest way to do this is to just have a list of Switch objects
where Switch is the component on the switches
you can then access their "on" field
if you want to make it more general (maybe there are switches and locks and pressure plates), you could instead have the various devices reference the door
eulerAngles.z isn't the rotation around the z axis either. That's not how euler angles work.
yes, if you've rotated around all three axes, then the result may be non-intuitive
for an object that is only rotating around the Z axis, the interpretation is correct
hey guys help me out, I am using rendure texture to make a scope of a camera, but in game the result is a bit darker can some one help me out with this?
you have any post processing?
nope
Use an unlit material
You're probably using the standard shader which is lit
This also isn't a code question
cool it fixed, thanks
sorry my bad I am used to only ask code questions
it was automatic
-.-
i found what i think is a better method than linerenderer
i use a prefab of the leg segments
this prefab rotate towards the target point
and i can say my brain is very big
Yall know how to get SetActive functions to work on an Image
Instead of gameObject only
image.gameObject.SetActive(false);
what???!!
Public image example
example.gameObject.SetActive(false)
@gray mural like this?
yes
you should set its gameObject component to false
GameObject.SetActive
should be used with GameObject then
only game objects are activated or deactivated
Behaviors can be enabled and disabled.
If you wanna get technical you could make a class that implements a Enable() method
But i think it's useless for most things
well, I mean, you can make any method you want!
c# sucks
cirnophobic
hey guys how can I get a angle from -90 to 90 relative to a transform and a target?
I am not understanding how
I am using cs Vector3 targetDirection = target - transform.position; float angle = Vector3.Angle(transform.forward, targetDirection); float clampedAngle = Mathf.Clamp(angle, -90f, 90f);
but the values allways come positive
even if the target is above or below the transform
you want SignedAngle
thanks man
Hello I am having an issue where an npc in my game is supposed to sit down after reaching a table, and for some reason there is a velocity applied right after sitting down
I am not sure where that velocity is coming from
https://medal.tv/games/requested/clips/1dLBD8DtHi_90E/d1337SjgfblD?invite=cr-MSxsd20sMjYzNjQxOTcs
private void CustomerSit(GameObject sitPos)
{
transform.position = sitPos.transform.position;
print(transform.localRotation);
Rigidbody rigidbody = GetComponent<Rigidbody>();
transform.localRotation = Quaternion.Euler(0, 0, 0);
transform.rotation = Quaternion.Euler(0, 0, 0);
rigidbody.velocity = Vector3.zero;
rigidbody.constraints = RigidbodyConstraints.FreezeAll;
print(transform.localRotation);
Animation customerSitAnim = GetComponentInChildren<Animation>();
animator.SetBool("isOrdering", true);
ChooseRandomItem();
sitting = true;
}```
Watch Bug Help 12/6/23 and millions of other Requested videos on Medal, the largest Game Clip Platform.
Could you give an example of how you intend to use this system, maybe with pseudo code? I dont think I fully understand your goal with it
Just a guess, but you could try sleeping your rigidbody and zeroing the velocity before you set the position, or try using a coroutine to zero the velocity tthen wait for the next frame before setting the position, it could be still moving in between FixedUpdate when you apply the position so the velocity doesnt get to zero yet, but again thats just a guess, not sure for certain
alright, will try that out thank you!
unfortunately didn't work thank you for trying though ^^
I have implemented undo/redo for my tools, the key is ctrl+z and ctrl+y. The problem is that the undo/redo keys are the same as undo/redo unity. What do you suggest?
Change shortcut? is there any way to use ctrl+z, ctrl+y for my tools without conflicting?
It is not editor
It is in runtime.
I think it should exist an api to stop undo functionality
Undo.IncrementCurrentGroup();
Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
but I think it is better to use different shortcuts
What you actually want ? What is the end goal ?
Is there a way to make interface variables show in the inspector (Serializable?)
no, since they don't derive from UnityEngine.Object and aren't one of the other types that can be serialized
you probably want to make an abstract class that derives from MonoBehaviour and implements the interface
it's definitely a pain-point
With custom Editor.
makes sense.
actually, can you point me to an example of that?
me?
no, sim
oh
I guess you can make an Object field and then just check that you put a valid object in?
(i.e. one with the right interface)
sounds like a lot of extra work imo. Ig I'll just put that variable in my self without a interface.
I've done it multiple time. In fact, we have a whole Custom Editor for the default editor which enable us to add custom attibute
Like Odin
Things like do a function on button, restrict string value base on condition, bitmask field, etc.
And, we have the possibility to show any variable/function.
right, but how would you do this specific thing?
i.e. exposing an interface field in the inspector
I'd just use different shortcuts in the editor, probably the easiest
You can do any Editor-UI related function without a serialized property.
ex: https://docs.unity3d.com/ScriptReference/EditorGUILayout.TextField.html
ah, I see
For the part of retreiving/exposing an interface, you can use Reflection + Attribut.
so you'd show an Object field and then make sure whatever you put it in matches the interface?
i know i've seen something like that before
You can do that for sure, but I do not see what it is gonna do with exposing paramters of an interface.
parameters of an interface?
I was thinking more something like MonoBehaviour : IInterface and expose the value of the function inside.
Result*
maybe we're thinking of different things here...
i am thinking of letting you reference anything that implements an interface
(more likely, reference any unity object implementing an interface)
public interface IInterface {
[Inspect] string GetValue();
}
public class MyBehaviour : MonoBehaviour, IInterface {
}
[CustomEditor(typeof(MonoBehaviour))]
public class MyBehaviourEditor : Editor
{
public override void OnInspectorGUI()
{
//Do reflection things there
//Draw the field
DrawDefaultInspector()
}
}
ah, so you're talking about drawing extra things in the inspector from an interface field
okay, different thing
i'm pretty sure Yamoshi was looking for this
so that if I had, say:
public interface IFoo {
public void Foo();
}
public class FooClass : MonoBehaviour, IFoo {
public void Foo() { Debug.Log("Foo"); }
}
public class FooClassRedux : ScriptableObject, IFoo {
public void Foo() { Debug.Log("Bar"); }
}
public class SomeComponent : MonoBehaviour {
public IFoo myFoo;
}
i could drag in either a FooClass or a FooClassRedux and both would fit in that myFoo field
when we make a script unity generate some stuff in a file called Assembly-CSharp.csproj
which is an xml file if im not mistaken which filled with a lot of info. Is there a way to change its default values so whenever that file is created use some other data instead of its default data?
why?
Not a place for such things. Also, how many hours did you put into it ?
[Do not] Ask or answer questions using unverified AI-generated responses
although i'm not even sure what the point of this is
5 hours
Ouch, AI is still far.
the game has a system of levels and a system of spending bullets and life, and when you die, everything resets
because whenever it generate the file, for taget net framework version it uses 4.7.1 by defualt by for some reason i have net frame work 4.8.1. And targeting the wrong version makes my auto correct not work while im writing code
ah, I had a similar problem once
honestly I'm extremely frustrated to spend all the time explaining the error and explaining how such a thing has to work within the game, and it's amazing how gpt can't solve a simple problem in the coding and ends up causing more problems in the place
i didn't actually solve it
Unity has full control over your project file (csproj extension) you should not modify it manually
it's a large language model. it generates text that it thinks is likely to follow the prompt text
oh
too bad he's stupid sometimes lmao
A little question, is it the same to write:
public class Entity : MonoBehaviour, ITarget
{
public void DealDamage(uint amount, DamageType damageType, uint numberOfHits, bool ignoreShield, bool ignoreArmor) {//effect}
}
and
public class Entity : MonoBehaviour, ITarget
{
void ITarget.DealDamage(uint amount, DamageType damageType, uint numberOfHits, bool ignoreShield, bool ignoreArmor) {//effect}
}
With this as the interface:
public interface ITarget
{
void DealDamage(uint amount, DamageType damageType, uint numberOfHits=1, bool ignoreShield=false, bool ignoreArmor=false);
like does it change anything in term of access?
pretty sure the second one is an error
the default access modifier for interface members appears to be public
you can do protected, but that's a bit weird...I think that demands explicit interface implementation?
okay, thanks!
Hey I have a question regarding movement with the rigid body of a character. Right now, My movement script looks like
void NormalMovement(Vector3 movementDirection)
{
// Calculate the movement amount based on the current speed
// Translate the player's position based on the movement direction and amount
Vector3 newPosition = transform.position + movementDirection * currentSpeed * Time.fixedDeltaTime;
playerRb.MovePosition(newPosition);
Debug.Log(movementDirection);
// Rotate the player to face the movement direction
if (movementDirection != Vector3.zero)
{
Quaternion targetRotation = Quaternion.LookRotation(movementDirection);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, rotationSpeed * Time.deltaTime);
// Play correct animation
if(currentSpeed == sprintSpeed)
{
this.GetComponent<PlayerAnimationHandler>().Player_Ani_Sprinting();
}
else if (currentSpeed == walkSpeed)
{
this.GetComponent<PlayerAnimationHandler>().Player_Ani_Walking();
}
else
{
this.GetComponent<PlayerAnimationHandler>().Player_Ani_Jogging();
}
}
// if not moving, play idle animation
else
{
this.GetComponent<PlayerAnimationHandler>().Player_Ani_Idle();
}
}
Where the movementDirection is calculated in the FixedUpdate(), which is also where this movement code is called:
void FixedUpdate()
{
#region Normal Movement
if (normalMovement)
{
// Check if the player is running or walking
if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
{
currentSpeed = sprintSpeed;
}
else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
{
currentSpeed = walkSpeed;
}
else
currentSpeed = jogSpeed;
// Calculate the movement direction based on arrow keys or WASD
Vector3 moveDirection = Vector3.zero;
if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W))
moveDirection += Vector3.forward;
if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D))
moveDirection += Vector3.right;
if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S))
moveDirection += Vector3.back;
if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A))
moveDirection += Vector3.left;
// Normalize the movement direction if it's not zero
if (moveDirection != Vector3.zero)
{
moveDirection.Normalize();
}
// Move the player
NormalMovement(moveDirection);
}
#endregion
The issue is it seems like the player needs time to "charge" before it starts moving. I can see that the movementDirection vector is properly being calculated. However, it takes a few seconds of holding my key down for my player to begin moving. Additionally, once it starts moving in a specific direction, there is no delay in continuing to move that direction. ie if my character finally begins to move after holding W, i can let go of W and hold it again and it will instantly begin moving again. However, if I try to move in a different direction, I will have to wait for it to "charge"
I dont think this is a code issue as it calculates the movementDirection properly as well as working as intended once the player finally begins to move. Is this an issue with the rigidbody setup?
!code for formatting
📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
my code is formatted
read the code command
Large Code Blocks
Likely due to other code or one of your other components
You didn't share your Rigidbody setup so hard to comment on that
If I turn off "is Kinematic", it is responsive (but jittery)
But since you're using MovePosition it's unlikely
The vector that is being inputed into MovePosition is what I expect to see, and the debug message prints the same vector when the player is stuck vs when the player is not stuck
Is this some sort of issue with the mass of the player? the drag?
mass only has an effect on forces added to it, and your player has no drag from your screenshot
Why is it when "isKinematic" is disabled, the movement is perfectly responsive (but jittery)?
As mentioned above I think this is probably an issue with your other components
What could effect the rigid body?
How can the animations affect the rigid body?
When those animation things are commented out it still persists
there are a lot of things that can make it jittery, tbh i dont really know why u have a kinematic rigidbody with rotation frozen on each axis to begin with
Even a desync between camera and player can make it look jittery, while the player is moving perfectly fine
My point is that the code is by turning off the isKinematic it shows that the inputs are being handled properly. I'm not sure why my player needs to hold down a key continuously for a few seconds before it moves. And when i let go and press the same key, it continues to move. However, if the direction vector changes, it takes a few seconds again
Off the top of my head I can explain why it moves after release (albeit it shouldn't be much), however the delay doesn't make too much sense to me.
You're using MovePosition
https://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html
Rigidbody.MovePosition moves a Rigidbody and complies with the interpolation settings. When Rigidbody interpolation is enabled, Rigidbody.MovePosition creates a smooth transition between frames. Unity moves a Rigidbody in each FixedUpdate call.
However, based on your code, could you not just use Unity's default CharacterController to avoid these issues?
There is a thing in python called Dictionary which allow you to save 2 data for each thing you put in like this:
"Name" : "Alex", "Age" : 20 etc
Kind of like a json file.
Is there anything like that in c# so i can store some data?
yeah, a dictionary
yeah\
then how you define it?
Though that just looks like a class with variables as there's different types as values
can't I define it like this somehow ["Name" : "Alex", ...]
newDictionary.Add(30, gameObject1);
newDictionary.Add(31, gameObject2);
newDictionary.Add(32, gameObject3);
newDictionary.Add(33, gameObject4);```
cool thanks, and the GameObject can be any type of data right?
you can use anything as the key/result
nice ty
that example just uses integers as the key and gameobjects as the result
got it
If you wanted any type of data you would use object, but that's not a great way of programming, instead you would just use a class or something that's actually defined:
class Person
{
public string Name;
public int Age;
}
...
var alex = new Person
{
Name = "Alex",
Age = 20
};```
oh that is a Dictionary?!
No
I have one like that in my code, I want a Dictionary inside of it
if I run this code
File.WriteAllText(Application.dataPath + "/save.json", save);
Where is the file supposed to be once the game is builded ?
Here ? Becasue I can't find it.
in your assets folder
thats in the editor
!api
💻 Learn in detail about the scripting API that Unity provides https://docs.unity3d.com/ScriptReference/
i mean here
Why not just look at the docs, which tell you where Application.dataPath is.
yeah the one you have inside of your project folder
Win/Linux player: <path to executablename_Data folder> (note that most Linux installations will be case-sensitive!)
this is what is says but in the data folder there is not save file
Factorio 😧
can I ask you something off topic?
but i don't care abot that one, i care about the one that should be generated when i run the game
Have you run the save code then?
i guess, it does run in the editor
i hate how the game does not behave the same in editor and once builded
You should check that it runs via logging or the debugger, as it should be that folder
how do i do that ?
Either connect the debugger to a development build and use breakpoints
or add a Debug.Log and look at the player logs https://docs.unity3d.com/Manual/LogFiles.html
any way i am really confused by a thing, are unity games just the files in the folder you build the game or there is something else ?
They're just in the files in the folder where you build it.
but why are player prefs not delted when you delte the folder
Because player prefs are not in the folder
and generally people save to the persistent data path, not the data path.
You do not distribute the player prefs.
no but it would make sence if you delete the game the player prefs get delted too,
that is just leaving files in my computer without me knowing
Welcome to Windows
Windows is very permissive about where programs put files
how can i change the result of a key?
Debug.Log("The script Save File generator is running");
When i run the builded version is this getting printed in a file ?
or add a Debug.Log and look at the player logs https://docs.unity3d.com/Manual/LogFiles.html
What do you mean by change?
replace the result with another data
if you want a new result then just add a new entry
dictionary[key] = value
no I want a new result for an existing key
thanks
are you trying to replace the value at runtime?
yes
so the logs say
FileNotFoundException: Could not find file "C:\Users\edora\OneDrive\Desktop\Simulation\Factorio Logic Simulator_Data\save.json"
So i guess that the function that generates the file is never started because another script is trying to get the file first blocking everything else?
should i make the function that generates the file in the void start of the script ?
Or, check if it exists before you try to use it
I dont know if this is a bug in Unity or not, but I have merged 2 different strings (nameString and descriptionString) and added it to the TextMeshProUGUI component. However the name and the description are overrided.
This is basically what I have done:
string newString = nameString + descriptionString
TextMeshProUGUI textComponent.text = newString
that looks like there are two text component one on top of the other
no i correct my self
i have no idea what is that
I agree, but there isn't 🤷♂️
I have, unfortunately it doesn't fix it
I was thinking there's an invisible "new line" like \r, that wasn't handled correctly
only thing that comes to my mind is to fix those two red error, they problablyu don0t matter but maiby they do
some one had the same problem
and was the \r
Seems to be my issue, where does the \r come from?
Usually doing things on Linux or certain editors. It can also come from pressing Shift + Enter
The nameString is taken from an text editor with hundreds of names, maybe this could be the source of the issue?
Likely.
probalby every line ends with \r, i guess you took the line from the file and thats why
Usually lines in files end with \r\n which would support all platforms
Thanks everyone, I should be able to fix it now
That's the windows line ending
Linux uses \n alone
Even Console.WriteLine uses \n to my knowledge
_>
using \n alone should just be fine
Probably Environment.NewLine
You're right, I believe I got it backwards.
\r\n for non-Unix platforms, or \n for Unix platforms.
pretty sure if u write line1\nline2\r\nline3 to a file you'll still get all on its own lines
Correct.
The bit inside the code tags was from https://learn.microsoft.com/en-us/dotnet/api/system.environment.newline
The sauce
should i make a voxel engine via using a 2D array noiseMap and then evaluating the height based on an AnimationCurve or use an array that gets all dimensions of the map and then store that
or should I use the first for the surface and the latter for the underground
anyone know how i can get a sort of 'device position' for my mobile game, i want it so walking IRL walks in game
Did u google for it
https://docs.unity3d.com/ScriptReference/LocationService.Start.html
Although be wary of location based stuff, it will be inaccurate a lot of times and this is not in your control. Sometimes it will seem like you teleport, or jump large distances due to just some inconsistencies. You may also want to handle cases where users are in a car or going too fast
Anyone know how i can play Admob ads in my mobile game at random times?
Interstitial btw
Hey does anyone have any experience with optimization of behaviour trees? Running into an issue where the number of active behaviour trees are actively starting to hurt the performance. Currenly i'm storing the running nodes by the ID of the subject(simple int) for the behaviour in a sorted dictionary, but somehow it does not seem like a great performance gain over a regular Dictionary. Any pointers to points of optimization would be appreciated!
You want the integral of the straight line which is the area under the curve. (The amount of space that has been accumulated at the point X) (The inverse of the differential) The differential is the function of the tangente (The curvature at the point X) of the curve.
Here the concept applied to velocity and acceleration: https://www.cliffsnotes.com/study-guides/calculus/calculus/integration/distance-velocity-and-acceleration
helo im looking for a helping material what i wnat to do is hide my varibles if my bol is true.
E.g 3 varibles Lock, Name, Password.
if my lock varible is true then idont want to shoe my name and pass varible i know it can be done using custom editor but i cant find the right material to do so
has anyone ever tried coding a programm for the hololens (using MRTK) in unity version 2019, where a cube spawns in front of u and u can do stuff like make it bounce via gravity and physical material? maybe additional speech input? we need sth like that for a school project and I was just wondering
https://gdl.space/vepinitaho.cs I spawn Objects but sometimes they collide with each other and then they fly out of row how can I change that? ( the Objects are moving forwards)
I want this to activate the outline component on a raycasted object and then disable it when no longer raycasted. But it doesn't seem to be working
Look at your code, it makes no sense
You're only doing anything when the Raycast hits
What about when the Raycast doesn't hit anything?
You need to handle that case
Hello, I am having some issues exporting my android game, can anyone help?
Solved, thank you
Ask your question.
Oh no worries I already fixed the issue
It's just the first time that I'm making an android game so I don't know how to use it
Oh but I have a different question
How can I test my games on mobile?
Most videos say that I need to use Unity Remote 5, but I can't find it on the play store
General OOP question - if you have a vehicle base class say and you override with a car class, a tank class etc. Is it valid to put an enum or something in the base class as a fast type check, to avoid doing endless if vehicle is car, if vehicle is tank etc? when you only have the vehicle class to hand? I dont know what cost type checks incur...
actually C# pattern matching seems to make it redundant 'is' is fast and you can even switch on class type
If you find yourself doing those checks often then you've probably missed much of the point of doing polymorphism in the first place
It is bad practice to have an Enum to define a type. It usually means that your system is not flexible/modular enough. In fact, this might be the worst thing to do in OOP.
If you show what you are actually trying to do, we might be able to give some suggestion.
Yes I agree with you 2, it is a sign of poor design in most cases...
It was because I have a filter class with huge variation in inputs depending on type - the UI needs to change based on that. So it is not like I am calling a Move() or DoWork() function, I have to get full type info to setup the UI
Can't have a SetupUI() function?
I'll agree it's sometimes more convenient to use the switch
I still see no reason to not have correct polymorphism/interface.
no maintaining data/UI separation
well one way anyway
Hello everyone, anyone come up to very long compile problem today ?
Just as long as you understand what's going on, I'll not shame you for it lol
ah I'm not sure I will ever reach C# perfection - but if it works in the end it may be the best I can do eh. If anyone has suggestions on bibles for best code tips...
Is your architecture something like that ?
yes
but actually the UI bit is combined - ideally I guess TankUI->Tank CarUI->Car would be better
There is two things here:
UI contract. (What other people see and can do on the UI)
UI capacities. (What can be done in the UI)
In your UI, you can have the capacities to show ammo by example.
However, only the TankUI will do the drawing of the ammo.
yeah my vehicle stuff was an example but that is the point - one class type can have a very different UI, while still being a vehicle
This is why, you should work with capacities and contract and make the actual drawing inside the specified UI.
You give the capacities to show Ammo, show Speed, show Durability. However, only the TankUI will actual make the call to those functionnality
yes, I always make it work, just not always in the best way - if you have any reference to this kind of "capacities and contract" method let me know
Hello everyone !
Is there a quick way to add the 60 scripts that are in a folder to a prefab ? (other than clicking 60 times "add script" in the inspector)
Select them all an drag and drop
But 60 is a lot of components for one object
I do not have reference, I'm only saying things I have learn in class.
However, you can look in Design By Contract and read on what is an interface. (Hint: It is a set of capacities, a contract)
https://en.wikipedia.org/wiki/Design_by_contract
Also, the reference I gave might not be good actually, it is more the formal approach than the design approach of designing by contract.
It tries to solve the question: How to make a bugless program where what we want is more how to design functionnalities in isolation, with the usage of interface. Maybe something like mocking in Unit Test is more close to what I actually refer. (You do not need the implementation of an interface to write a test)
well formal/correct approach vs getting-it-done is a delicate balance. If the code gets too bad you waste time refactoring, if you take too long trying to make it the best, you never get it written!
Apparently turning OFF a collider in a trigger will call OnTriggerExit, but turning ON a collider in a trigger will not call OnTriggerEnter
that's odd
It was more of a "Perfect" approach which is totally not what we are doing. Things you do in Medical/Space programmation.
what is the correct way to initialize the first object after setting up the bindings in the installer?
the following produces a warning:
public override void InstallBindings()
{
this.Container
.BindFactory<TileBehaviour, TileBehaviour.Factory>()
.FromComponentInNewPrefab(this.tilePrefab);
this.Container
.BindFactory<WallPartBehaviour, WallPartBehaviour.Factory>()
.FromNewComponentOnNewGameObject();
this.Container
.Bind<WallBehaviour>()
.FromNewComponentOnNewGameObject()
.AsTransient();
this.Container.Resolve<WallBehaviour>().CreateWall();
}
Zenject Warning: It is bad practice to call Inject/Resolve/Instantiate before all the Installers have completed! This is important to ensure that all bindings have properly been installed in case they are needed when injecting/instantiating/resolving. Detected when operating on type 'WallBehaviour'. If you don't care about this, you can disable this warning by setting flag 'ZenjectSettings.DisplayWarningWhenResolvingDuringInstall' to false (see docs for details on ZenjectSettings).
like ok i get its bad practice but what is the good practice

i could circumvent this with .NonLazy() but i dont want to move business logic into the constructor
I’m new to unity so I have this hell of a easy question. I made a square and want it to move, how do I code that? I know I can just go search it up in YouTube but could I also get an explanation of how it works? I want to know what each text means in the code in case I want to change it oater or use it again. Anybody? 
To truly understand something, you need to experiment it.
Start by following a tutorial, then try to adapt it. (Direction, Speed, etc.)
Any recommendations for a tutorial?
If you want a description of what the fuction/line does, you can ask in #💻┃code-beginner. However, you will understand even better by searching on Google.
!learn
🧑🏫 Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/
Ok mate! Thanks! 
Is there a way to increase gravity onto rigidbodys? My character controller jumps are too floaty rn
What is the limitation of the new keyword? In the docs it says that override extends and new replaces, which makes sense, except you can very easily do this:
class foo {
protected virtual void action1()
{
Debug.log("Action")
}
}
class overrideFoo : foo {
protected override void action1()
{
Debug.log("Action2")
base.action1()
}
}
class newFoo : foo {
protected new void action1()
{
Debug.log("Action2")
base.action1()
}
}``` and get exactly the same results
it affects the behavior when you have a variable whose compile-time type is of a parent class
and whose run-time type is actually a child class
with new, the run-time type is ignored. you just get the method on the parent class.
with override, the run-time type is used. you get the method on the child class.
so:
foo x = new overrideFoo();
x.action1(); // calls overrideFoo's implementation
foo y = new newFoo();
y.action1(): // calls foo's implementation
I’m trying to male a third person game, what tutorial would you recommend me mate?
https://docs.unity3d.com/ScriptReference/Physics-gravity.html
Try 16. This is what I use.
oooh I see
thank you for that
That's a subtle but important distinction I guess
basically, virtual methods allow for polymorphic behavior, since you can override them
non-virtual methods do not
Hi everyone
I'm kind of lost on a project. How would I make it so I can rotate an object around another one following the mouse?
{ ...}
bool isGrounded()
{
float ExtraHeight = .03f;
RaycastHit2D raycastHit2D = Physics2D.BoxCast(Col.bounds.center, Col.bounds.size, 0f, Vector2.down, ExtraHeight, LayerMask);
return raycastHit2D.collider !=null;
}```
I'm using this code for my 2D Jumping. However, I can't figure out how to make it so you can only jump when on the floor. Players can still jump on walls. I have LayerMask attatched to the tilemap I'm using for the collidable objects.
so that the object "aims" at the mouse?
No
it must be that raycastHit2D.collider is not null - so what is it?
When I move the mouse I would like to rotate the object around another one
So if you moved your mouse a planet rotates around a sun (or that kind of thing)?
Yes
That king of thing
But without having to clicking
Something like that
The object rotate to match the mouse angle compared to the object it's orbiting on
Ah yes, I see.
But it stays focuse on the object
I know rotate around makes it rotate around the object but I don't see how we can match the mouse angle
- So you need to get the mouse position in world space.
- Get the direction from the object thats being orbited, based on the mouse's position.
- Multiply that by the distance you want the object to be from the object thats being orbited and set that as the new position
Premably you're using 2D?
hmm? Should I have it return isGrounded = true?
No 3D
But I can just fix it by setting the z to the difference between the camera and the object
that wouldn't make sense, you need to use the result of the raycast
Wouldn't the rotation of the moving object get broken?
I mean it wouldn't point to the object it's orbiting on anymore
alright, I'll try that. Also, just out of curiosity, are there any issues that could come up by opening my project in a newer version of unity? I'm getting unity on my desktop. The version I used on my laptop was 2021.3.17f1
You can change that too, though (you can use transform.forward = myObjectIAmOrbitting.transform.position).
With 3D it may take a bit more toying with, off the top of my head I'm unsure how the World Space coords of the mouse would work.
okay, so the object follows the mouse and points at a target
bingo
er, not quite
targetObject.transform.position - transform.position
you can also use transform.LookAt(targetObject.transform.position)
I was about to say!
targetObject.transform.position - transform.position?
Yes.
If you add that vector to your position, you get the target's position
Therefore, it is a vector pointing to the target
Oh I see
target - source + source = target!
in general, to get a vector between two things, just compute to - from
Unity compile times are driving me insane!
Hey, this line
controlEditor.obstaclesObject[indexOfRight].name.StartsWith("barrier")
does this error:
StackOverflowException: The requested operation caused a stack overflow.
UnityEngine.Object.get_name () (at <ba783288ca164d3099898a8819fcec1c>:0)
someone knows why?
What is obstaclesObject a GameObject?
a list of gameObjct
I wouldn't have expected name to cause a stackoverflow.
i google what s a stackoverflow error
It's essentially if you call a method within a method they're "stacked". The stack is only so big.
For instance this would cause a stack overflow.
public void MyMethod()
{
MyMethod();
}
but something good is that the error is everytime
ahhhh ok thks lol i know why i forget this part
That screenshot doesn't show much xD
look the bottom and the up
Ah! That'll do it.
and what s the limit?
depends on stack size
Thank you I'm rotating around it now 🙂
I'm not sure it has a definitive size. But you really aught to not toy with it!
and memory usage each function call
Where possible avoid nesting methods.
Now I just have to constraint the movement
So it's always at the same distance from the object
yes it s just less than 100 times for me
Usually you can rework this into a do { } while(); or a while() { } loop
That's based on your method being the first. Unity calls your methods, and then Unity has more methods calling those.
heuu... i guess my code won 't be a problem . Thks for the help
You can do
myDirection.normalized * myFixedDistance
If that helps.
ok it works fine now
public delegate char OnValidateInput(string text, int charIndex, char addedChar);
This method (from TMP_InputField) is happened when player presses the button
public OnValidateInput onValidateInput
{
get
{
return m_OnValidateInput;
}
set
{
SetPropertyUtility.SetClass(ref m_OnValidateInput, value);
}
}
I am really bad in those delegates, but how does Unity know that it should execute this method, when I press key button?
Because I cannot find it anywhere. And yes, it should be somewhere in the code I guess ?
Is it not specified in the inspector?
no.
context please: what class is this defined in?
I just want to find it in the code
is this a MonoBehaviour you wrote? does it implement any interfaces?
I have written it.
This method (from TMP_InputField) is happened when player presses the button
in TMP_InputField
oh, this code is from the TMP_InputField class?
i am having trouble following you
yes
what do you mean?
then m_OnValidateInput is a delegate that gets invoked when input is provided
I thought you wrote this code at first.
the input field decides when to do that
I would have thought it was added here:
It could have been done through code)
are all delegates called, when input is provided or ??
this wont work
you need to do AddListener
yes, that's handled by the input field
it responds to input being provided by invoking the delegate
You're right, that's normal events
this method works without listeners (& @potent sleet)
i do not understand where your confusion is coming from
I have debugged it
the input field invokes the various delegates when the right conditions are met
that's very normal
was talking about something else
If you're certain it isn't done in the inspector, just find all usages of the delegate name.
It'll have to be declared somewhere >_>
I want to find kinda this line of code ??
if any kind of Key was pressed
then onValidateInput method should be executed
that makes no sense
does TextMeshPro give you source files, or does it give you a DLL
That'll be inside TMP itself
if it's the latter, you ain't seeing it
yes, I have been trying to find it with Ctrl + F, but I did not succeed.
what do you mean? I do have access to source files, or ?
are you talking about this
https://docs.unity3d.com/Packages/com.unity.textmeshpro@1.3/api/TMPro.TMP_InputField.OnValidateInput.html
Where TMP makes that call will be inside TMP.
What will be in your code is where you do AddListener(myDelegate)
OR it is defined in the inspector
yes, I do
is there something particular about it or is this like an XY problem ?
nothing special about delagate event
TMP should not see, when player has pressed the button, cause it we cannot type anything in TMP. It should be defined in TMP_InputField, or am I missing something?
I just want to find it.
I cannot do that
what for tho?
I went and looked. When I asked my IDE to show me TMP_InputField, it had to decompile something to show me the class.
I am trying to make my own InputField to solve XY problem we were talking with other people in #archived-code-advanced. But I have lack of knowledge in Events, delegates and other (everything actually). So I am investigating original TMP_InputField to incerase my knowladge and be able to do the same things.
That's why I need to know how those delegates are used, I guess ??
The source is not provided.
TMP doesn't "see" unless you tell it to, the same way as you tell Buttons what to do when you click.
it is ??
i can tell you that it looks something like this...
void SomeFunctionThatChecksForInput() {
bool changed = /* something */
if (changed)
if (onValidateInput != null)
onValidateInput(newText, /* other args */);
that's it
isn't that the course?
If you wanna see how UnityEvents work you can use the documentation https://docs.unity3d.com/ScriptReference/Events.UnityEvent.html
yeah, I could not find it with KeyCode, Event.current and other
why would KeyCode be in there
if (Input.GetKeyDown(KeyCode.Backspace))
{
// do stuff
}
if you're just asking "how do I use delegates"? that's a relatively simple problem
InputField class is 5000 lines
I am probably not asking how to use them, I am trying to find the exact usage of them in original code in order to implement something like this then
holy shit
almost
Just use the documentation https://docs.unity3d.com/ScriptReference/Events.UnityEvent.html
It has an example
I have already used all of them (for Events I mean)
think they are saying they want to make their own Input field not actual events
But they keep saying
I am trying to find the exact usage of them in original code in order to implement something like this then
!!!
yes, that does not help me
meaning how TMP is using those events to achieve a similiar results ig
yes, in TMP_InputField
here's slightly more detail
You can read it on Github? https://github.com/needle-mirror/com.unity.textmeshpro
it checks if the new text equals the old text
if not, it calls OnValidateInput for every single character
mildly terrifying
there you go
https://github.com/needle-mirror/com.unity.textmeshpro/blob/master/Scripts/Runtime/TMP_InputField.cs to be more exact
that's just GitHub file from textmeshpro that we all have in Library => PackageCache
they are custom class that inherit event
This is the source files. It's the exact usage that TextMeshPro uses
is true TMP_InputField class is literally in Library Package Cache
looking at it now
yes, I don't think they provide information how TMP_InputField sees, when key button is pressed
it's all in there
yeah, there is no difference between looking the file on GitHub and File Explorer
in File Explorer even more comfortable I would say ??
look when you "insert" new char
it does all this
etc.
all the implementations are here
yeah, I have discovered this method already
That was a wild ride.
so what exactly you're confuse on
you keep mentioning about keycode tho lol
line 1700
has all the keycodes
Insert() is only called by Append() that is called by KeyPressed() that is called by ProcessEvent() and OnUpdateSelected() that both do not have any references
References to what?
!code
📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
probably because it's an event
if you look at the new input system is the same thing
i'm trying to use JsonUtility to read a json file, but it is ignoring my JsonProperty tag
yes, but why is it there, when it's not even called?
how do you know?
?
if you use OnMove(InputValue value) on the new input system you'd see the same thing
for example
on new input system "Messages"
oh, ok, it can be called by user then
I mean it can still recieve the event without the reference
Delegates can interfere with static analysis.
It's no longer obvious where an invocation takes you.
(which is why they're so useful in the first place)
yes, the question is "where?"
and that's probably my initial question🤔
Dun dun dun
Hello, can you guys help me with a problem? I am trying to compare the value I get from the game, with a number ( here 0.5 ), but somehow this doesnt work. In the Debug.Log I can see the number updating without a problem but somehow when I try to compare them, it is not working.
you're not calling your method anywhere
The Method is on a button that I've made, and thats what I meant, if I press the button I always get a debug.log but the if question is not working.
which debug log is working then ? randomName?
yes
that one is working fine
Debug.Log(Index.Value)
so I know the button works at least
📃 Large Code Blocks
Large code blocks should be posted as 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 get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.
oh sry
well I dont think so, because I always get the same index value from the update function
yeah because two of the fingers arent connected
Does this have anything to do with the comparision: NullReferenceException: Object reference not set to an instance of an object. RPS_Game.Update () (at Assets/Game_Itself/RPS_Game.cs:19
well yeah thats the same script
lol
all errors will result on some unpredictable flows of program....
literally can't reach the rest of the lines @weary quiver
code goes from top line to bottom
if something is broken in middle it wont keep going
other scripts May work but this one wont
So I tried creating a Mario style jump (the longer you hold space the higher the player jumps. But when I run my code and I press space my whole unity editor just freezes and I can't interact with anything. Code: https://gdl.space/azekecadoc.cpp
Thanks in advance!
Ps: I hope this question format is correct
while (Input.GetKey(KeyCode.Space) && midJump)
this will never change
if Update never returns, then the game is stuck.
Sounds like you need a coroutine.
the engine cannot change other stuffs including reading the keyboard input during this while loop
welp, seems like if I put the line in the void update, it works.. now I am kinda confused
which line was 19 ?
Debug.Log("Index: " + Index.Value.ToString());
also sounds likea band-aid fix if you don't know the true cause
This one here
hmm search in hirerchy for this script
like so t:RPS_Game
tell me if you find copies with missing inspector fields
Index is null somehow..

that'll do it
would it break something, if I put all the other fingers "scripts" on the button?
or it will work just fine
I mean like fill the spaces out
not really a good way to do it but should work fine
you only need 1 script no?
don't put scripts in UI elements tho
it's bad practice imo
forgot about that channel thanks
yeah but you don't wanna have scripts hidden in UI for this exact reason
anyone got any idea why all my models are frozen?
make a gameobject that is literally just ScriptsManager or something, holds your important scripts
its works in level 1 but not 2
okey
it's paused
you probably have Error Pause enabled in the console
you have console errors
thanks bro
have you enable error paused?
wait
open the Console tab
wdym
you have to fix the actual error thats pausing it
now ur just putting a bandaid over a gushing artery
no, if it pauses, then the scripts have errors needed to be fix
its a useless error
shooting the fire alarm does not put out the fire
really? what is it?
any error can lead to unwanted behaviors..
because i deleted my moving platform but the script is still somewhere
its harmless
so find the script
it tells you which one it is throwing
Also, thanks for the help ^^
thanks!
any idea why I get these errors when trying to build an asset bundle?
private void BuildHUD()
{
var hudBundle = new AssetBundleBuild
{
assetBundleName = _manifest.Name + ".hud",
assetNames = new[] { _hudAssetPath, _manifestPath }
};
const string localOutputPath = "SpectatorHUD/Build Output";
var outputPath = Path.Combine(Application.dataPath, localOutputPath);
Directory.CreateDirectory(outputPath);
BuildPipeline.BuildAssetBundles(Path.Combine("Assets", localOutputPath), new[] { hudBundle },
BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
EditorUtility.RevealInFinder(outputPath);
}
you cannot make a game build with editor scripts
so preprocess?
put it in the editor folder no?
when I press space the player gains infinite velocity even tho the if requirement isn't satisfied. I can't figure out what causes this https://hatebin.com/jvckmqywuz
which if requirement you speak of
also GetKey gets called a bunch of times even if you tap it once
if (PlayerPos.y <= PlayerStartPos){ this is always true
no? It prints it's false?
¯_(ツ)_/¯
Like it logs it's false but it keeps adding velocity
you are applying an impulse force every frame
that is going to be framerate-dependent
is there anything better than an impuls?
what are you tryign to do here?
accelerate the player gradually?
or give the player a 'kick' that gets them moving instantly?
like the mario style jump
so hold down space for higher jump
Also I fixed it
It just isn't smooth sadly
I would suggest starting with a big impulse
to instantly get you flying upwards
then add a continuous force
void OnJump() {
rb.AddForce(Vector3.up, ForceMode2D.Impulse);
}
void FixedUpdate() {
if (jumpHeld) {
rb.AddForce(Vector3.up);
}
}
something like that
Does anyone know why this code throws StackOverflow error?
private new void Start()
{
LookForEvent();
}
private void LookForEvent()
{
StartCoroutine(LookForEventCoroutine());
IEnumerator LookForEventCoroutine()
{
// yield return _waitForEvent;
yield return new WaitUntil(() => Event.PopEvent(_currentEvent));
while (Event.PopEvent(_currentEvent))
{
print("Event is popped or whatsoever");
}
}
LookForEvent();
}
the LookForEvent method calls itself
oh, wait, yeah, I did not mention it
that was dump
thank you, this one works ok now
private void LookForEvent()
{
StartCoroutine(LookForEventCoroutine());
IEnumerator LookForEventCoroutine()
{
// yield return _waitForEvent;
yield return new WaitUntil(() => Event.PopEvent(_currentEvent));
while (Event.PopEvent(_currentEvent))
{
print("Event is popped or whatsoever");
}
StartCoroutine(LookForEventCoroutine());
}
}
you could also just use a while loop in the coroutine instead of starting the coroutine recursively like that
How can I play these animation using Code? Like I made an closed animatio for the entire hand, and I made a mask for each state I want, and I want to basically be able to play the specific animation where I want.
I've got a situation where "time" can be non-linear (you can scrub through playback to get the state of something at a specific time) and I want an animation to be starting at some point in time after when it should start. I have the timestamp of when an animation should have started, I have the current time stamp, and I have the name of the animation that should be playing at this point in the timeline. I need to play that animation at the proper normalized time to where it would be at that timestamp. Easy enough to find what that normalized time is, it's the InverseLerp of the current timestamp minus the start time from the clip's duration.
Only problem: How do I get the duration of a clip by name? I can get the current state info, but entering the state, getting the info, then getting the length from that in order to play that animation again from a new start point seems clunky and awful, and usually with Animator controls that means I'm doing something the hard way.
You might be confusing animation with animation layer. You do not need different layer for playing each individual animation.
If you want to do that, you should implement your own Animator with: https://docs.unity3d.com/Manual/Playables.html
sorry for the long time to reply, had to do things. But what would returning the result of the raycast do? I'm using isGrounded as a prereq for jumping. All the game needs to know is that there's a platform below it, not what's below it
you probably gonna do foreach loop through all clips
private float GetClipLength(Animator animator, string clipName)
{
foreach (AnimationClip clip in animator.runtimeAnimatorController.animationClips)
{
if (clip.name == clipName)
return clip.Length;
}
}
I'm not really sure what to say - the code you showed is very straightforward, you're using a raycast to check if there is a ground below the character, and if that raycast result exists, i.e, it's not null, it's returning true
you've found that it's returning true when you think it shouldn't be
so that result is not null, so what is it?
that's the question to ask yourself and find out
I've found that it's printing null when nothing is touching the object attatched to this code, and printing UnityEngine.CompositeCollider2D when colliding with any object, but the problem is that it's returning not null even when the object isn't below it.
i.e, the player can jump when against a wall, floor, and ceiling, not only when on the floor.
Hello everyone, I need help with my gun
My gun is doing a weird 360 movement to follow the cursor and it flips as the player moves left and right
could someone help me?
if the idea is to seperate the gun from the player, the gun would be floating
sounds like you need to make sure you're only checking below
isn't that what the Vector2.down in the raycast does?
that's the direction the box travels in, but how large is the box?
Is there a way to have multiple 2D sprites n the same Z, define an order for them, and have it so this order is maintained when you look "behind" the sprite?
Like the order is reversed.
Cause you flipped the sprite around.
what do you mean?
I didn't understand sorry
you can have them with the same z position, but it just gonna be lagging
test it
lagging?
do you mean Z-fighting?
and crawl on each other
that's controlled by Col.bounds.size right? I can't figure out how to define it.
probably
just try to implement it
I guess it should be in 2D too, in 3D for sure though
can someone help me with this please?
thanks:>
the problem is in your script
I do not see any problems though
I can't define it as a Vector2, what should I define it as
the gun is doing a 360 motion though, its not sticking to one position and the other issue is the flipping
it's following your mouse position, yes
it is correct, but the way it follows it is not correct
what's incorrect?
https://www.youtube.com/watch?v=NKF-FkDzE-s
take this video for example, skip to the end and look at how his gun follows the cursor
I can't use his script because I have my own shooting script
Consider donating to help me keep this channel and website alive : https://paypal.me/supportTheGameGuy 💖
or Support me on Patreon : https://www.patreon.com/the_game_guy
In this video im gonna show you how to fire 2d gun and also add effects to make it look cooler, And add a recoil to our gun to add a nice feel to it.
In this tutorial i will ...
yes, what's wrong?
it's shaking a bit, yes
that's one more method
his is not rotating in like a 360 way, mine is like out of position and isn't rotating correctly
with the gun being flipped when the player moves left and right
you can fix gun's position and make him borders
kinda
if (transform.eulerAngles.y <= 30f && transform.eulerAnger.y >= 60f)
{
// just then you gonna rotate it
}
and just do not flip the gun with the player
I cannot help you anymore, I need to sleep, good luck
does anyone know what syntax I have to use to define the size for the boxcast?
I'm trying to define it using Vector2(1,1) but that's not working
2D boxcast?
yeah
that's the page I've been trying to use for reference, but I can't figure out the syntax
the declaration tells u exactly what syntax (you mean parameters?) it uses
syntax?
it says Vector2 size, but when I try Vector2(1,1) it doesnt work