Personally, I think it's more embarrassing to misinterpret a bunch of clear-cut words rather than a video I watched while half-awake. You've not only not payed attention to what I was asking for in the first place but never listened to what I was saying throughout the conversation. That includes what I was mentioning with tutorials and my initial statement of wanting it to slow down to a stop and not immediately stop moving.
#💻┃code-beginner
1 messages · Page 796 of 1
I literally answered your question. I told you exactly what you need to do to fix it.
#💻┃code-beginner message
But it seems you never read it.
Forward it
My bad, not what I'm used to seeing when someone forwards something
Nice assumption
Based on data
BTW I did see that AS I STATED AFTERWARDS and I've been working with it (though not that much considering how I've mostly been typing here)
So again, you didn't read what I typed
Here's evidence :D
And this is what I was referencing by "not what I'm used to seeing when someone forwards something"
Ummm @upper pebble MoveTowards(A,B) and Lerp(A,B) will move value A to B over a certain amount of time I hope this helps lol
Let's say you wanted to "slow down" once you release a button you could use one of those methods to change the value over time
E
lerp abuse detected
I'd go with MoveTowards over Lerp . . .
I already fixed the issue (It had absolutely nothing to do with what they mentioned)
jeez wth happened here
incompetent people who can't read or understand what I needed
alright, let's tone that down.
Yeah it can be like that VCBraindamage I apologize don't let this situation deter you from making great games brother
Sorry, it was a bit uncalled for but they were incredibly unhelpful
Don't worry, the people in the C# discord helped me with the issue afterwards and I got it resolved
That's good bro
i get that they didn't manage to help you in this case, but they are trying to help. the overall advice they gave is valid, specifically the point that trial and error generally isn't a great method of learning compared to reading and understanding to begin with
Yes
i'm seeing this as a learning opportunity tbh
the loop does continuously subtract 0.5, the problem is just that it does it all at once, and unity already has loops for doing stuff over time - Update/FixedUpdate
It's definitely easier to understand the way you said it. They may have mentioned that somewhere in the mess of text above but I clearly didn't see it or understand it
also btw, you can totally use tutorials that still use the old input system. the core logic will still be the same, you just change the input. the old system has been around for a long time, so a lot of tutorials will be using it
I usually don't use them because it can be a little confusing at times and the ones I did follow regardless ended up not having what I needed or were fundamentally flawed
One used some random movement system that caused collision bugs with hitboxes and had no easy fix
digi tried to get at it here, and they specifically mentioned a part in your code where you're already doing it correctly #💻┃code-beginner message
They were actually wrong about that part when I tried it
and you didn't reply to it, so digi probably assumed you missed it, hence why they linked to it again
they're correct afaict.
do..while on its own is a loop with a condition
Update is already a loop, so you just need to add a condition
Fair enough on that part, but it still doesn't excuse how they ignored my originial intention that I stated several times
#💻┃code-beginner message are you referring to this?
No. Sorry for not clarifying. It was me mentioning that I wanted to slow the movement down to zero rather than making it a sharp stop
that's what digi's solution would do
Yeah that's why I mentioned the moveTowards() yeah lol
if the velocity is currently non-zero, and the corresponding key isn't being pressed, reduce the velocity by a bit. keep doing that every frame. if it's 0, stop reducing it
Except it didn't. What's ironic is I managed to fix the issue by changing the linear dampening which I don't believe they ever mentioned. It definitely didn't help that they kept spacing out their answers and spamming different results which was wildly confusing
though yeah, movetowards would help you not overshoot and then get an oscillating/jittering effect if you end up at like, 0.25 -> -0.25 -> 0.25 etc
That's good VC
this is pretty much the same logic that lineardamping does, man
lineardamping is proportional to the current velocity, and that's about the only difference
If you found a solution that's good there's 1 million ways to achieve the same effect but as long as work as desired then good job!
The hardest part of game development programming isn't the programming but understanding geometry and algebra is what I find most confusing
although yeah, this absolute modification on each axis would mean diagonal damping would be a little wonky. you'd want to modify the entire vector anyways
anyways, using and understanding conditions within unity's message loops is a pretty significant piece of knowledge. you can get more use out of that knowledge in the future if you want.
ultimately, that's what we're trying to do - to help you learn, not just get a solution
I get that, but if you're going to try to explain something to an absolute beginner, you need to be clear and guide them at least a little. You did a great job of that. They did not.
we don't know how much you know or what you don't know
as an outside observer, it was obvious to me that you hadn't heard the analogy of unity's messages already being loops before. but that's not always obvious when you're actively in the discussion
I have been in this channel before and I have clarified to them that I am an absolute beginner
"absolute beginner" can mean a lot of things
and to be honest, "i've been in this channel before" doesn't mean much. i know ive seen you before, i recall your username. but i recall absolutely no info about your skill level
You're right, but it does also represent that I am extremely new and not that knowledgeable
so does that mean we should explain what mono behaviors mean or what files are? obviously no, right?
we see you're using those concepts already
and you are also using the concept of FixedUpdate as a loop with the ifs for your movement
man i'm not trying to argue here... i'm trying to make it easier to get help by pointing out where the gaps in assumption were
No, that would mean that supposed person would need to go do some foundational tutorials. I had already clarified that I had done some tutorials before for movement but they clearly didn't want to listen. My problem comes from losing the information I know because I get lost in what might work due to desperation.
right, so like, we don't know if those tutorials explain the concept of Update being a loop.
you're asking us to make an assumption that, while true for you, isn't true for everyone
or maybe they do and you've missed that - there's a lot of possibilities
I'll definitely be working on some other things to get a better idea of how to do things such as movement and get a better idea of what I could do in the future. At the same time, when I ask for help on something, I don't want to be told to do more tutorials or look at the manual when that isn't going to help me with my issue. The people beforehand clearly could not understand that concept and that is how the argument started.
ah wait, wrong direction. maybe they do and you already know, but you aren't applying that
I am going to deeply thank you for that analogy
in that case, a little nudge would be sufficient, but it'd still let the asker figure it out from what they know
(just trying to explain what digi mightve been going for)
I'd say the reason why I was putting so many loops in the update "loop" was because it's what I've seen in most- if not all tutorials I have looked at. You could likely chalk that up to force of habit but that IS why I fiddle around like this. They call it a monkey on a typewriter but it gives more clarity into what the issue is rather than finding a niche tutorial that just tells you not to
good tutorials will explain why, just like i've done here
i'm not going to participate in the ongoing discussion, but i would also like to point out that if you do not understand something that someone has said, then you need to ask concrete clarifying questions and not just immediately dismiss what was said or ask something incredibly vague, or even worse, get mad at the responder
If you have a Youtuber that has those tutorials I'd appreciate that as a reference
though, it is harder to figure out which tutorials are good or bad, as a learner, so i see how that might be easier said than done
i haven't really used any, so i can't recommend from experience, sorry.
(though there a few very popular channels that prescribe some not great practices, though i don't recall which exactly)
I definitely got a bit out of hand earlier but if they had any idea what they were talking about they wouldn't have kept ignoring what I was asking for and telling me to go look at more meaningless tutorials.
That's another problem I have with some of these tutorials. Many of the ones I need are niche and made by small Youtubers which, as I mentioned before, have questionable solutions that end up being buggy, unfixable messes.
oftentimes when someone is missing a core concept, tutorials can help a lot because they can supply multiple core concepts that might also be missing. answering every core concept question does get tiring, and it's why those resources exist
but yeah, what i mentioned isn't exactly a core concept, more of something to internalize, so average tutorials probably wouldn't explain it directly
I'd really love to see those tutorials that use loops in update.
it could be that your search queries are too general or too specific, but it's hard to say without more specific info. sometimes that's just the case 😔
i can't really get upset with a tutorial. whether good or bad, they made it to teach or help someone. some good, some bad, and some ugly; but that's why i recommend watching a few covering the same topic. you—hopefully—get a better grasp of the concept. it's seldom you find one that does everything you're asking for . . .
Ok, how am I supposed to handle an event where I mouse over an object in a 3d scene? It has a collider and neither OnMouseEnter or OnPointerEnter work.
for OnMouseEnter you must be using the old Input Manager rather than the Input System. for OnPointerEnter the component needs to have the IPointerEnterHandler interface where that method comes from and you need an EventSystem in the scene and a Physics Raycaster component on the camera
I was missing the event system
I’m losing my mind, do colliders have a characteristic where they don’t register by ray casts on the first frame they exist or something?
colliders aren't updated until the physics step which only happens on FixedUpdate frames. you can call Physics.SyncTransforms (or the 2d equivalent if in 2d) to force them to update immediately
Oh my god that was rhetorical, if this fixes my problem…
hey guys anyone here knows how to code a floating point vector system where game world adjusts to player position
cause of scale
Floating origin you mean? Did you try googling? This is not some common knowledge algorithm, but the idea is that you need to get the offset of your camera or character to the origin, then shift everything in the world by the negative of that offset.
yes so far i have come to the conclusion to do it periodically
based on distance
so as to not have much errors or anything
otherwise im locked in a very tiny space to work with
You can easily have some 10km world without any issues though
so what you mean is , find offset that is , if my character is 1k away from origin , i shift player to 0 and i shift the whole world to -1k
right
its just an empty space XD
No need to shift the player separately. It's part of the world, so it should be shifted along with it.
ah at the same time , just to move the whole world box then
i mean , all the objects with the player
Yes
Basically.
It's not as simple on practice though. Moving physics objects could cause issues. And some other systems as well
Youd need some extra setup for such objects.
ye gotta work on that , maybe make it so the screen refreshes instantly so player cant notice maybe
hi i dont know how to explain it but im following a tutorial as a beginer but in the tutorial his thing code is coloured and shows up mine is not
first pic is yt
!ide
💡 IDE Configuration
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
classic intellisense
make sure you don't have any compile errors
if ur using vs do u have the unity integration installed
I dont know if it changes anything
i think so how would i check
u can check on the installer
😭
when you go to the installer theres the installed versions, the first button on the right (I think its modify? unsure) lets you update to include depedencies and one of them is unity
that is a compiler error, you need to fix it
configure your ide first, so the ide tells you where the issue is
@lilac coral go through the instructions here
dawg hoew do i get to the editor for unity
Hey folks, I had a question about the input system.
If you use the Move inputs, you get a vector2 that can have a value on X, Y or both right ? But what if you only want the player to go only sideways or forward backward ?
Like in the case of a snake game, you don't want to go in a diagonal right ? How do you do that ?
You have to decide what you want to happen when the player presses both directions at the same time and then do that
So you arbitrarily decide on a rule when both keys are pressed ?
yes
It's your game, you get to decide how it works
Ok. Then another question, if I make an abstract class inheriting monobehavior, can I make the update method virtual or something to pass on to the children ?
{
Vector2 input = moveInput.action.ReadValue<Vector2>();
if (input.x > 0 && input.y > 0)
{
inputDirection = Vector2.zero;
}
else
{
inputDirection = input;
}
}```
Something like that would work for ignoring two directions ?
Input can be negative so it needs to be !=
Ah right
And for the update ? Can I change the method from private to protected and have it inherited ?
Right I can declare update as protected virtual no issue
Hello everyone. Im pretty much all done with my game, I just have 1 issue that I do not know how to fix at all. When Im playing on PC, the player moves fine, it doesnt collide early? I would say with the tiles but for some reason when I play it on my mobile, it collides with tiles WAYY easier (the videos that I sent explain it better) and I was wondering if anyone knowa why it does that and maybe could help me fix it. https://youtu.be/LKrtJtdku4E
https://youtu.be/fB6zbcak-r8
I have a slight issue with my code, im a begginer and kinda need help
how do i paste it in this format
!code
Posting 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.
use a paste site for big chunks of code
one sec
using Unity.VisualScripting;
using UnityEngine;
public class Move : MonoBehaviour
{
// L R, Jump
public float moveSpeed = 5f;
public float jumpPower = 5f;
public bool jumping;
public bool onGround;
public float jumpStartTime; // how long we want the player to jump for (fuel)
private float jumpTime; // tracks time of when player started to jump
public BoxCollider2D groundChecker;
float xInput;
float yInput;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update()
{
// Player CANNOT MOVE when midair
if (onGround == true && !jumping)
{
xInput = Input.GetAxisRaw("Horizontal");
rb.linearVelocity = new Vector2(xInput * moveSpeed, rb.linearVelocity.y); // Linear is positional movement, angular is rotational.
}
// button pressed = jump
if (Input.GetButtonDown("Jump") && onGround == true)
{
jumpTime = jumpStartTime;
jumping = true;
onGround = false;
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpPower);
}
// button HELD = higher jump (getbutton means when the button is held down)
if (Input.GetButton("Jump"))
{
if(jumpTime > 0 )
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpPower);
jumpTime -= Time.deltaTime;
}
if (Input.GetButtonUp("Jump"))
{
jumping = false;
jumpTime = 0;
}
}
}
void OnTriggerStay2D(Collider2D other)
{
if (other.CompareTag("Floor"))
{
onGround = true;
jumping = false;
}
}
}
what happens is when i jump the timer stops counting down, therefore causing my player to double jump until the playertime variable reaches the number its set to
the variable is currently set to 0.3 seconds, so whats meant to happen is the player is meant to jump higher depending on how long hes holding the jump button
right now that DOES happen but once the player lets go of the key, he can jump again until the value of the timer reaches 0, which isnt supposed to happen, the timer itself is meant to countdown regardless of me holding the button
any ideas?
hi,
I am making a game where you need to extinguish burning buildings.
every time a building gets burned down, the player loses a heart.
for the loss of hearts, there is a short animation where it ascends.
I succed on that, but it happens a lot that a building gets destroyed while one of the hearts is still being removed.
I added a boolean, IsRemovingHeart, for preventing another building from dying until the heart is completely removed.
It works, but now the last heart will not be removed.
can someone help me?
A tool for sharing your source code with the world!
A tool for sharing your source code with the world!
An idea is something like this:
jumpTime -= Time.deltaTime;
if (Input.GetButton("Jump"))
{
if(jumpTime > 0 )
{
rb.linearVelocity = new Vector2(rb.linearVelocity.x, jumpPower);
}
}
if (Input.GetButtonUp("Jump"))
{
jumping = false;
jumpTime = 0;
}
At the very least you can't detect ButtonUp while holding the button down. There are probably other problems as well, think it through.
maybe my approach is wrong then,ill keep experimenting
does this have to do w unity's new version tho? i tried looking up a solution on yt and they all seem to use my concept
Static classes is okay to use? For example, class SavePlayerSession, receives and handles data to save in JSON file
my player is moving very slowly ? how should i fix it?
yes
Have you checked: https://docs.unity3d.com/ScriptReference/Input.GetButton.html
The button cannot be read as released while it is held down.
wait its not the same as using keys?
anyone?
increase the speed
already did but nothing is happening , this errors shows evrytime
Thats not related to your player moving slow
i don’t know why you think it would be
i know its not related to my player but after giving box collider to the tank my player moves slowly and shows error of<input system package>?
if it’s not related to the player moving ask about that issue
if you have two issues you have two issues
have you seen this or not?
see the picture i send earlier
First of all delete said file and recompile
that screenshot has no relevance to movement speed
Can we see movement function?
ok my mistake ... i fixed the movement issue....
What was solution? You are using old input system
see the error in meta file.
that's not really an issue in itself
yeah
Isn't the reason he gets warning?
warnings aren't errors
and inputmanager is still perfectly usable
it's the reason for the warning, yes. it's not the reason for the issue that he asked about.
what to do with the meta file. issue?
@boreal sonnet Are you using txt for setting values for tank?
did you modify the meta file or anything? (maybe through merges?)
and have you been using the asset for a while, or have you just imported it?
given that it's just documentation you could probably just delete the .meta file and have it regenerate
it's probably not being referenced by anything
but then this error shows up
ok
Can someone explain why this is happening?
IEnumerator LoadLevelAsync(int sceneIndex)
{
PrepareGame();
SceneManager.LoadScene(sceneIndex, LoadSceneMode.Additive);
Debug.Log("LOADED SCENE: " + sceneIndex);
}
void PrepareGame()
{
Debug.Log("Current player is: " + playerPos.position);
Debug.Log("Player position set to: " + initPlayerPos);
playerPos.position = initPlayerPos;
}
PrepareGame sets the player's position to a specific spot
Then Additive load scene happens
So why doesn't it FIRST set the player where they're set to be and instead not do it at all at times?
When do you think PrepareGame() runs
Before the scene is loaded
(The player is not part of the scene that is loaded)
I'm not sure I understand your question but since you have a CharacterController, setting the transform position directly like that generally won't work unless you disable the CC
I'd guess the scene loading is totally irrelevant
Basically when I reload the scene, I make it move the player to the initial position (it's set at start)
That before the next level is loaded and it triggers the collider which calls the win screen (the red switch or anything)
Did you read what I wrote about CharacterController?
Yes, I'm just not sure how it works
How what works
The charactercontroller
I just move the playerObj with a transform reference
(In this case)
As I mentioned, that doesn't work since you have a CharacterController
I also mentioned how to fix it
Yeah trying this right now, just kind of taking too long to respond sorry
(me)
This worked
Thanks a lot
why is LoadLevelAsync using the synchronous loading method (and also seems to be an ienumerator that doesn't yield or return anything. i don't think that's valid.)
how do I make the jump more snappy? I want to increase the speed when going up
and any other suggestion to improve this?
2nd if statement checks for the linearvelocityY
usually you would have the jump be extended if you hold the key
often this is done by increasing the gravity after you release jump
to make it snappier you would increase the jumpspeed and potentially increase gravity
otherwise i would just play with the gravity and jump height until you like it yeah
animations and particle effects also will go a long way here
yes thats the next thing Ill try after im satisfied with this
and how do you check for button being released? my first time with unity and Im using the new input system so Ive not been able to find any tutorials
increasing the jumpspeed make the jump higher but not faster? why is that?
also reset the Y velocity to 0 right before applying any upward force (assuming you are adding force and not just assigning a value to the Y velocity)
It is also faster but FALLING will not be faster unless you increase gravity
is adding force better than changing velocity?
they're physically equivalent
the end result of adding force is a change in velocity
I want it to be little faster when going up but jumpspeed does not change that
jumpspeed changes exactly that
but you mentioned "snappiness"
and that will only come with increased gravity
Or make the player character smaller and decrease jump speed
large things jumping higher take longer time
as a designer like half of what you do is play with values
just play with the jump force, and gravity
if you cant get something u like with those two, then add the jump height control mechanic
jump force will only increase the height
gravity will increase the overall speed but will decrease the height
yo i am trying to make a clickable sprite but its not working and i dont know why this is the script:
OnMouseDown is outdated and doesn't work with the new input system
Instead of OnMouseDown You need:
- A collider2D on the sprite
- A Physics2DRaycaster on your camera
- An EventSystem in the scene
- To add the IPointerDownHandler interface to your script
Soooo how to learn?
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
hey guys, question - how would you handle a ceiling collision using a character controller? currently when i just the velocity just keeps me stuck to the ceiling up until it drops down with gravity.
You can use OnControllerColliderHit to detect the collisions and adjust your velocity
is it a good idea to make a scriptable object singleton to for example store a list of like 20 prefabs that should be accessible from most scripts?
as i dont need to change the prefabs and as an asset it stays throughout scene changes
As in a database? If it works it works. 🤷♂️
yeah database
i mean i dont really know how else because non-destroy on load singleton gameobjects feels super janky
if theres better methods i wouldnt mind changing
Why?
Could use a static class with lazy init.
would need to reference assets though
Load from resources
magic strings with lazy loading does not sound fun lol
Making the best suggestions lol
in some scenes i for example dont want certain managers, and i mean i dont necessarily need to see the object in hierarchy if its sole purpose is database
yeah thats what i use, resources with singleton scriptable objects
is it like a weird strategy or is it reasonable
Well, then don't make it a DDOL.
data design oriented layer? what is ddol
Don't destroy on loaf
oh ok
Have a separate database singleton in every scene you need it.
wouldnt i have to manually place that object in every scene though
Then just reassign the static reference.
i dont see how a singleton asset isnt just simpler to deal with
Yep. Or via code at runtime.
Maybe it is. But you asked what other options there are, so here we are.
Its good to know options, but i was wondering if there were options which were better in some sense, does a gameobject allow for more storage or something?
As Steel said, if it works it works. Don't think too hard.
ok that makes sense
Not really. There would be pros and cons for every solution.
If there isnt any blatant drawbacks im not aware of imma keep doing this then lol
You mentioned loading from resources. That's generally considered bad due to having to deal with manually inputted strings.
Also, poor control of what's getting loaded.
That being said, it doesn't mean you should stop doing it. It's just one argument against it.
With larger scale builds it would definitely be troubling, but im just loading in one single scriptable object from resources which exclusively holds scriptable objects for now
Is there some way to get the current state an animator controller is in?
Is it common or not,...... that my players rotate in a same place while being idle?
This is the coding channel. It's common if that's what you're making it do.
i'm not trying to make them rotate while being idle
everytime i move them they rotate...i haven't wrote the code ...it came with the when i downloaded the assets.
You'll probably want to ask the dev who made the asset or look through their scripts.
using UnityEngine;
public class BulletBounce : BulletModifier
{
public int maxBounces;
public float damageOnBounce;
private int currentBounces = 0;
private bool justBounced = false;
public BulletBounce(int maxBounces = 3, float bounceImpactDamage = 5f)
{
this.maxBounces = maxBounces;
this.damageOnBounce = bounceImpactDamage;
}
public override void OnCollision(Collision collision)
{
if (currentBounces >= maxBounces)
return;
// Ignore enemies
if (collision.gameObject.GetComponent<IDamageable>() != null)
return;
currentBounces++;
justBounced = true;
Vector3 incomingVelocity = projectile.GetVelocity();
Debug.Log($"BulletBounce: Incoming velocity: {incomingVelocity}"); //Usually something like ( +/-0.50, 0.00, 0.00)
//on a straight wall shot perpendicularly
Vector3 surfaceNormal = collision.contacts[0].normal;
Vector3 reflectedVelocity = Vector3.Reflect(incomingVelocity, surfaceNormal);
projectile.SetVelocity(reflectedVelocity.normalized * incomingVelocity.magnitude);
projectile.transform.rotation = Quaternion.LookRotation(reflectedVelocity);
}
public override bool ShouldDestroy()
{
if (justBounced)
{
justBounced = false;
return false;
}
return currentBounces >= maxBounces;
}
}
``` So basically i'm making a top down 3D shooter and I encounter this problem, when my bullet hits a wall the bullet seems to "stick" to it and slide along the wall, It also decreases the magnitude to really small values so the bullet does not keep any momentum. Bellow are the rigidbody values
If anyone knows what's happening your help would be greatly appreciated
Mb I fixed it, it was the physics material that had friction set to to a value above 0
Unity is so bad
Hi
do people really not like using switch-based state machines?
Is there a really easy way I can create my own Discord nuke bot? I don't want to nuke any servers with it, I just want to know for myself that I've accomplished something like this. That's one of my goals, simply to create such a bot, but I don't intend any harm with it.
How can I create such a bot without programming knowledge?
This is a Unity server and there's no off-topic here.
- get programming knowledge
why do you say that?
I've heard people say that online. Might be true for many states and/or combination of states, but there's no reason it shouldn't be used if the cases are simple and there's like 5 of them, right?
generally if you want to validate or question a claim, you have to provide the context and reasons given for said claim
The use of them will depend, yes, if you're going to have a thousand states.. a switch is not gonna cut it, it's not scalable or maintainable. If you're gonna have 10 states.. then, sure, go for it.
otherwise we're just disputing some random statement that probably isn't even the original claim
Hey, i want to make a hypercasual game where i drag my finger from one 3dobject, it spawns an obirope from that object and then i let it go over another 3dobject, the rope will attach to that one. I can't wrap my head around the steps i would need to go through to make a prototype of this
Can someone help me break this problem down
I come from godot. Is it normal to attach a lot of scripts to an object as components
I dont know what the good practices in unity programming are
Depending on what you count as "a lot" ... yes
Like 5-10
not a problem
Because you can only attach 1 script to another node in godot
once it starts becomming unmanagable (too much scrolling/ etc) then would be a good time to look at splitting it up
I see
Could you help me figure out the logic for my game
The click to drag sort of thing
tapping first object -> spawn obirope and assign tapped location to end of rope -> assign draggin pos to other end -> update drag pos -> check for 3d object on touch end -> assign new pos to rope end OR dangle/destroy it
Riight
the logic of that would be the same for any game engine
Interestingly enough it bacome a problen on my poor little laptop after 20 scripts with dozens of serialized properties each, though i feel that this was also thanks to odin inspector (it would drop my frames from ~150 to ~30 when i had the object selected and the inspector shown
I used an asset once, that had a heavily customised inspector, editor fps dropped significantly with anything selected that had it (even scrolling the inspector was sloooowww).
The entire asset was very, very, poorly made (repeated code, string searches, string searches for game object names, etc) and I wish I'd not bought it.
Any advice on some reads/video/repository study?
I'm at a point where I'm struggling on planning architecture within an unity project
https://gameprogrammingpatterns.com/ - not Unity specific, but can be extrapolated to be applicable to C#
My main doubts were on the full code architecture i.e how to plan it to not have to reiterate continuously over it (which I'm currently doing).
Probably I will give it a read though as I read it once when I started and I could find my answers there since I'm more experienced, thanks!!!
Yeah just doing it poorly is honestly a pretty reliable way to get better at it
I personally have my own package with generic, reusable ideas that i constantly use in projects which has been good for iterating on ideas in the same place and getting in a good headspace about architecture
hey douse anyone know how to fix the bug where i cant add modules it wont apear its just shows in the explore or pach notes
that sounds like you didn't install the editor via the hub?
i think so a tut was sending me to editer archive
but how do i make it add modules again it sounds risky replacing files
When you installed it, did you use the Install > button to do it from Unity Hub? Or did you manually install it yourself?
let me check
If you don't install a version through the hub, then you cannot use the hub to install extra modules.
You will have to go back to the download archive and grab the installer for the version you're using, then use that to add more.
do i need to back up my project first
no
that makes no sense, and doesn't sound right
A project is not affected by the install at all. You can completely remove Unity from your computer and the project is still safe, until you delete it, or have a tech issue with your h/w
and this is a code channel, so any further questions on this should be moved to #💻┃unity-talk
oh thank goodnes
ohh sure
hi is there a list of common code optimizations lying around somewhere for unity?
code optimization begins on your side
wat does this mean
Hello chat! I have been making cronus zen scripts and have been learning along the way. Im absolutely stuck on the menu. I've tried to follow everything I've found to integrate it through out the script but it constantly throws a redline error on a line that im 100% is correct. Rendering the menu useless. Anyone have experience in cronus zen?
no. there are a few common code smells, some of which might be relevant to your perf issues. but code optimization is heavily dependant on what's already there
what's the error
first off, do you even have perf issues? if not, no need to worry. if you do, then profile to see what the cause is
Such a list would be pretty useless in practice. Use the profiler to find the bottlenecks specific to your game, then look up how to improve those
The main will show no errors but when I put the menu and add the weapons and variables to it a redline error saying invalid space or invalid name "Weapons_Menu" or it will even reject const string_name "NIGHTMARE"
Its like the whole menu code is wrong and corrupting because my zen screen its self with bug out. I remove the menu and its ba k working fine.
uh is this related to unity?
Im using visual studio to build it and a compiler to check for errors
the people here wanting to help are proficient in unity. is your question related to unity? if not, we won't be able to help.
Didn't know it was specific my bad I'll leave
try a server specific to cronus zen, if one exists - you'd probably be able to get help there
Bunch of scammers, im good. Thought this was a learning community.
there's a discord server listed on their website https://www.cronusmax.com/
Scammers on cronus servers
well, try their forums then i guess, or maybe dive into docs yourself
They dont want to teach you. Only charge you to do it.
A tool for cheating has a community full of scammers? Shocking
lmao
I added double jumping and I have these issues that need fixing. When the player is double jumping for some reason it doesn't look smooth at all and when I move and jump its like the players momentum isn't carried over with the jump. Just feels weird. any ideas?
You're probably setting a new velocity directly when you jump a second time.
Your code is very explicitly removing all of the player's momentum when double jumping
if (!isGrounded && isFullJump && !doubleJumpUsed && jumpBuffered)
{
Vector3 v = rb.linearVelocity;
v.y = 0f;
rb.linearVelocity = v;
rb.AddForce(1f * jumpForce * Vector3.up, ForceMode.Impulse);
doubleJumpUsed = true;
}```
what do you think that v.y = 0f; bit is doing?
Did you write this code?
yes I thought that it would fix the stutter when the player did the double jump but forgot to remove it thanks for the heads up!
the lines before and after it can be removed as well if you remove that line
As for the double jump how can I fix this?
Look how when you move and do the double jump it stutters and not smooth at all and doesn't mix well when moving then jumping
could be to do with your velocity clamping possibly
if (rb.linearVelocity.magnitude > accelMaxSpeed)
{
rb.linearVelocity = Vector3.ClampMagnitude(rb.linearVelocity, accelMaxSpeed);
}```
try removing this temporarily
you want to treat your vertical and horizontal velocities as separate
Ok that fixed it but the reason why thats code is there is to stop the fast movement while in the air / more control
theres not much of a reason to clamp overall velocity
yep but like butteredcoffee is saying you're being too heavy-handed with the clamping and because it's an omnidirectional clamp, it is affecting the horizontal velocity as well
well clearly ur adding too much vertical velocity
also simply reducing the vertical force will make it jump less too
OK so now the jump is smooth but when I am moving and double jumping it doesn't really work together and when jumping and when getting close to the ground then going for the double jump how would I make it reach the double jump height instead of it moving up a bit.
Updated Script : https://paste.ofcode.org/fSR8sLjdmJNdzUyB42ZTZD
Question, can someone give me a brief bit of advice, I'm thinking about how I want to handle buildings in my game, and whether I want each interior to be its own scene, or just a hidden part of the current scene.
I already have a system made for transitioning between scenes via doorways, of course, but I'm curious if I should spool out another system for transitioning into areas within the same scene too.
What the issue? Not jumping high enough?
When moving and double jumping the jump height for the double jump is decreased but when I am idle and then double jump its normal. Watch the video to get the idea. #💻┃code-beginner message
You need to explain what is normal
I think you probably want to keep the zero-out of y linear velocity for a double-jump
It looks like since you’re falling then when you add force you’re adding to a negative y velocity
I would set the vertical velocity to zero if negative when attempting to jump
normal is what you see at the beginning when I am idle and when you double jump you go higher when moving and double jumping its not high
So you get a smaller visible impulse
Basically you've got negative velocity in the y.
That’s a good point as well. Might only want to zero-out if you’re falling
If you’re already going up don’t zero-out
Depends on what feels right for what you want
can someone help me with the new input system for getting my mouse to work with keyboard, the mouse left click doesnt work if i bind it to mouse, if i bind it to a keyboard input it works, and if i bind it to mouse and change some control schemes around to mouse and keyboard it works with the mouse but the movement keys start to stop and catch on nothing
thx
is the unity documentation a reliable source for a complete beginner?
talking about this
this is not a comprehensive tutorial that will teach you all of the necessary fundamentals if that is what you are asking
it would be better to follow a yt tutorial?
consider following a structured course like the pathways on the unity learn site
thank you
Idiomatic Unity - say there's a GameObject with a Hitbox Component that is parented to a GameObject with a Health Component.
What would the best way to communicate to the Health when the Hitbox determines it should take damage?
My first thought was something like public IDamageable damageable; on the hitbox, but that doesn't appear in the editor
by referencing the Component
correct, you cannot serialize interfaces like that, just use the component type directly, no need for an interface in this case
Hmm. Okay, but say I want to have a different type of damage listener. Like a damage logger or something. Would I have to create some base class DamageConsumer : MonoBehavour that Health and DamageLogger both inherit?
Or is that just more "bad idea"
I'm aware you're suggesting something like public Health health;
or explain it better so we can recommend something better
Okay
So IDEALLY I would like to have a Hitbox component that generically informs whatever component is provided to it so long as it implements an interface
I'm aware I could just provide the hitbox with a reference to the Health component, but that feels inflexible to me
use an event instead
An EventHandler?
Likely they're referring to a UnityEvent
no, there is almost no reason to use the EventHandler delegate. either use an Action or a UnityEvent
Alright I'll look into UnityEvent
you can assign all listeners via inspector it is a nice solution provided by unity
Oh, perfect
Great, thanks
Yes this is exactly what I need
What's the advantage to Actions? These seem to overlap, except UnityEvent also is assignsble in-editor. Is Action just considerably lighter so it's preferable for events that will only be programmatically assigned to?
Edit: that was Unity Action vs Unity Event, whereas you were asking about Action vs Unity Event
https://discussions.unity.com/t/unityaction-vs-unityevent/219790
Like this? ``` Vector3 v = rb.linearVelocity;
if (v.y < 0f)
{
v.y = 0f;
rb.linearVelocity = v;
} ```
This isn't what I was looking for, I want it so if the player is moving and double jumping the height should be the desired height. Even when I jump and when I get close to the ground and then go for a double jump it should go to the desired height.
Consider thinking about why it doesn't go to the expected height.
Ah, sorry. Yeah, this link doesn't really cover what I was asking
I'm just going to assume that Action is supplanted by UnityEvent
i hate to say but the answer is "it depends". without knowing anything about your game its impossible to advise
What kind of info would be needed? It's a turn based RPG, in the vein of FF7, I suppose?
if its all in the same scene it would be worse performance, unless you disabled the interiors or something. If you put it in another scene then you could just load what you need. Do you want there to be a clear transition (like in pokemon/zelda games) or do you want it to be seamless? Do you want to be able to see inside buildings from the outside?
without a clear goal theres no approach thats "better" it depends on what you want for this game
what problems are you trying to solve? performance? level design? game flow?
You only want to use UnityEvent if you want serialized subscriptions. Otherwise stick with event and delegate types
Sorry for the late reply. Should I track the peak height of the players Y velocity?
Mind if I ask a sort of related question - I'm going to move on to Input Actions so its not important, but not knowing what causes the following issue has been irrationally annoying:
bool a = Gamepad.current.aButton.IsPressed();
... Occasionally, it just gets stuck on a true or false state. eg, it goes true when pressed, then when released, it doesnt go back to false.
I must be using it wrong, but... how?
Where are you running that line of code?
Update
the line of code you've provided is like a one time check it checks the state of the button when it's called but if the state of the button changes and this line isnt called again a wouldn't change
It's just right there every Update. Now that I think about it maybe I should try FixedUpdate see if that makes any difference.
From what I've read, it seems like Gamepad class polls the device on a schedule, so I tried varying the polling interval and the application target framerate but nothing seems to stop it from happening.
Update() should be fine. You can use the input debugger to see if if it reads the same https://docs.unity3d.com/Packages/com.unity.inputsystem@1.18/manual/Debugging.html
Thanks, thats interesting! Even the input debugger doesn't always register the change in input.
Wonder if my controller is gubbed... I'll try another
I think windows has a controller input visualiser thing but yea try another one
I forgot about the visualiser too, thanks. Welp, its definitely my Unity project at fault
Input system documentation is quite detailed, it seems the controller polling rate is already high and can be changed
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.18/manual/Gamepad.html#polling
Thanks again, do appreciate the help btw; but I've already tried messing with the polling rate, to no avail.
Does anyone know how to keep unitys context while not opening the entire project in vscode. So for example If I open the scripts folder without unity it doesn't link for debugging and unity imports seem broken. But if i open through unity it opens the entire project. I only want to see my scripts folder.
no you need vs code to open/detect the c# project unity generated to get all features
Use search to find types/files instead (ctrl T, ctrl P)
I use this on occasion https://marketplace.visualstudio.com/items?itemName=rhalaly.scope-to-this
Hi everyone, I want to have a scrollable menu that has 1000+ different items in it.
I used a editor script to fill it with the items I need since theyre always the same just to test if it would be a simple issue but it takes too long to start up the project now since there are assets each one needs to get.
How would people recommend doing this / how is it usually done?
I been coding all day first time ever had to watch alot of videos and chatgbt to help fix things
Can you share any code or more info as to how this works? Is this UGUI or UITK?
If you created this at runtime you can create things over time to reduce impact on framerate
@grand snow is it good to use chatbgt to help with scripts?
seeing as this is the beginner chat and you spelt it wrong, NO
Chatgbt lol
I made a bunch of scripts today by watching videos and using chatgbt
For help
Did you learn anything? i guess not
A little bit lol
This is the code I used to generate the prefabs: https://paste.ofcode.org/7u2ZGe6pgsrHZRq5J5DTyW
This is the code of the prefabs: https://paste.ofcode.org/b4CfEMKNnG7sqGSngNufsS
the project is basicly a database of pokemon. Im not a beginner programmer / Unity user but I just havent seen a way before of doing stuff like this. XD
using UnityEngine;
[RequireComponent(typeof(CharacterController))]
public class PCBO4Movement : MonoBehaviour
{
public CharacterController controller;
[Header("Speed")]
public float walkSpeed = 6f;
public float sprintSpeed = 9f;
public float slideSpeed = 12f;
public float airControl = 0.6f;
[Header("Jump & Gravity")]
public float jumpForce = 8f;
public float gravity = -20f;
[Header("Slide")]
public float slideTime = 0.8f;
public float crouchHeight = 1f;
private float normalHeight;
private Vector3 velocity;
private bool isSliding;
private float slideTimer;
void Start()
{
controller = GetComponent<CharacterController>();
normalHeight = controller.height;
}
void Update()
{
HandleMovement();
HandleJump();
HandleSlide();
ApplyGravity();
}
void HandleMovement()
{
float x = Input.GetAxisRaw("Horizontal");
float z = Input.GetAxisRaw("Vertical");
Vector3 move = (transform.right * x + transform.forward * z).normalized;
float speed = walkSpeed;
if (Input.GetKey(KeyCode.LeftShift)) speed = sprintSpeed;
if (isSliding) speed = slideSpeed;
if (!controller.isGrounded)
move *= airControl;
controller.Move(move * speed * Time.deltaTime);
}
void HandleJump()
{
if (controller.isGrounded && velocity.y < 0)
velocity.y = -2f;
if (Input.GetKeyDown(KeyCode.Space) && controller.isGrounded)
velocity.y = jumpForce;
}
void ApplyGravity()
{
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
void HandleSlide()
{
if (Input.GetKeyDown(KeyCode.LeftControl) && controller.isGrounded && !isSliding)
{
isSliding = true;
slideTimer = slideTime;
controller.height = crouchHeight;
}
if (isSliding)
{
slideTimer -= Time.deltaTime;
if (slideTimer <= 0)
{
isSliding = false;
controller.height = normalHeight;
}
}
}
}
My movement Script
first link is broken.
Why do you have Start() work that way when it depends on a public field being set before? Seems like a bad idea when you already have a SetX function (which fails to update the pkmn var too)
I tryed to make it like black ops 4 and I had chatgbt to check it
Good point on the SetX function I didnt relieze I forgot to have it set the pokemon XD
But the reason I have Start work like that is because I have the scriptable object added before runtime and just changed sometimes in run time.
Ah that makes more sense. That design would probably need to change if you need to instead create + init elements over many frames
Manual initialization is just better when you need to control things
So with a Coroutine probably right?
just have it start on awake/start and end after X iterations / all done?
!code and do you have a question
Posting 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.
You would have some parent script such as "pokemon list" that is in charge of creating elements and initialising them with data objects.
The key is only doing some amount of creations a frame before you wait for the next. A coroutine or async function can be used for this.
Perfect thank you!
Ya is it good so far I have a bunch more I worked on but not sure if there good or not
Or the UI is redesigned to be paged so you can re use a smaller amount of elements
That could also work I just liked the scrolling design XD
It doesn't matter if we think it's good you didn't write it so what are you even going to do with that information.
I said I made it I watched YouTube videos all day and worked on it lol
I used chatgbt to check it
Lots of ways to implement this! (e.g. as you scroll you can dynamically load and unload elements)
Yeah I thought about doing something like that with reusing the same prefabs instead of having the 1000+ of them but couldnt get a concrete version working.
Ill try out the batch loading and see if it works well anyway! Thank you for the help!
unity has pool objects if you have trouble implementing such a thing.
It does take more than just moving and reordering elements (we have to pad the empty space or dynamically change the scroll position to keep up the illusion). Anyway hope you get it working
Hello everyone,
I am trying to implement a custom post processing renderer pass into my game but I have a problem. I want to check if the component is enabled or disabled but this code doesn't work? What am I doing wrong?
Component uses enabled and this checkbox only shows up if update/fixed update is defined
is this what you mean?
let me rephrase my question, currently my render pass is rendering no matter if the VolumeComponent is enabled or disabled. I check it like this in my RendererPass. I want to check if the second image's checkbox is checked or not in the RenderPass' RecordRenderGraph method. I hope this is better. Thanks
active sounds right but ill be honest the docs are not great at detailing render graph and volume stuff
Ill just leave this here, the description is a tad confusing https://docs.unity3d.com/Packages/com.unity.render-pipelines.core@17.5/api/UnityEngine.Rendering.VolumeComponent.html#UnityEngine_Rendering_VolumeComponent_active
https://discussions.unity.com/t/how-to-get-enabled-or-active-from-a-volumecomponent/935144/2 this is same issue I had nobody knows the answer thanks anyway
Aha then the description for active is accurate
meaning its not actually meant to be used for "should this pass be executed or not"
fuckin shit name thou
how can i give objects more than one tag?
my terrain can be 2 types (safe or danger), but i want another type (drillable) that both of the original 2 can be but i only want certain parts to be drillable
Use a component and track it yourself with enums or other things
Yes that’s the way. Otherwise the answer to your original question is “you cannot”
You can get crafty with how robust you make your tagging system, but otherwise could just make an enum with the [Flags] attribute so you can use a bitmask and have the nice check mark drop-down
That also means you’ll need to use a bitwise operator to check the tags, but you can make a helper function so it’s easier to read in the code
bitwise operators aren't entirely necessary to determine if an enum instance contains a specific flag, there's the HasFlag method
Oh yeah that’s right
!docs
hi all,
for a small project, i want to load a procedural mesh (1k-ish vertices) into canvas. the naive solution of pushing every individual vertex in OnPopulateMesh works well enough. sadly, this implementation is so slow that it causes noticeable lag. im pretty sure there is a faster way with AddUIVertexStream or FillMesh, but the documentation for VertexHelper and UIVertex is incredibly sparse, so im having a bit of trouble understanding what im supposed to do here. could anyone show me the way?
(please ping me if you choose to respond)
1k vertices is too much for ui. What exactly are you trying to draw there? Also, did you profile it at all?
a two-dimensional procedural map. the performance issue itself is pretty clear: with the individual vertex solution, youre pushing to the gui buffer with every single vertex, which creates a lot of garbage. i bodged a slightly hacky solution together with CanvasRenderer.SetMesh that is performant enough for my purposes, but id still like to know the 'proper way' with VertexHelper
Wdym by "pushing to the gui buffer with every single vertex"? That doesn't sound correct.
Can you share some profiler data as well as your code?
GPU buffers are not subject to GC collection, so you're probably misinterpreting the data.
very likely :P
i imagine that the AddVertex method is creating some kind of temporary data structure thats spiking garbage, but thats just a suspicion
Or you're recreating a vertex helper every frame
i dont really know how OnPopulateMesh works behind the scenes - again, the documentation is not helpful - but im just using the instance thats passed by the callback
If it's a minimap or something, you might want to consider drawing it to a render texture and displaying via a raw image in the ui.
yeah, i might eventually settle for something like that
Hey, working on a snake type game. I have an issue I'm not sure how to resolve it.
I want to spawn pick ups for the snake to eat, but I don't want it to spawn either on the snake or on an obstacle.
Just to spawn at a random position is easy, buct checking if a position is valid is another issue
what is the world is the unity player input component used for
i checked there offical input videos and there they directly used the input system in the script rather than adding using the player input component
it depends on how you represent the map. the easiest way is to first check each position and collect the ones that aren't occupied by the snake or food, and then pick a random position and spawn food on it.
The issue I think is that I have no variable tracking where is what. I just have the snake moving in space righ now
well, i'm assuming your game is grid based? you could use a List<Vector2Int> to hold the data about snake's segments. this will let you easily extend the snake and store data about its segment positioning
Yeah i have a list with all the snake transforms. I could indeed check the position of each segment before instantiating a pickup. But generating random numbers and checking availability seems inneficient.
it depends on how you implement it. if you simply roll a dice until a specific condition is met, then that is of course very inneficient because in the worst scenario you could NEVER meet the condition. that's why i recommend you to instead collect the positions that meet the condition (e.g. don't store food and aren't any of the snake's segment's position), and then picking a random one of those.
So I would create a list of all available choices, remove the one already taken and pick from those ? Yeah that can work
yeah, something like that.
you might also need to check if the .Count == 0, as you'll get an error if you try to index an empty list
Can you compare two Transforms ?
How do I align the circle with grid snapping it to the box's circle?
compare by what? position?
Yeah
yes, you can just check if TransformA and TransformB positions are similiar. just make sure to not use == because of floating points, it's better to check if the difference between two values is less than an epsilon (e.g. 0.001f)
Hello guys i'd like to "restrict" the x axis so you cant fully turn your camera around when you are sit but i'am really unsure on how to do it ( i did something for the y axis and it work but i just dont think it would work for the x axis ) https://paste.mod.gg/fanatlfevdme/0
A tool for sharing your source code with the world!
you can simply clamp the rotation. though you're sure it's an X axis? rotating left/right is usually done by the Y axis if i'm not mistaken
Make a variable yRotation and change the look system to work the same way with y rotation as you already do with x rotation
uhmmm i have no idea i thought the x axis was the left right axis so it would have make sense for me 😅
Hello, can I change the shape of a 3d object? Like putting a hole in a cube?
At runtime, not in blender
Not easily
Guess I'll do it myself
maybe you could try modifying mesh vertices?
You can cheat using the stencil buffer but doing realtime boolean operations is not easy and would be best via a pre existing mesh lib
Hmmm could you explain I don't know many of these words 😊
Something like this that offers mesh boolean operations (may not be perfect)
https://github.com/gradientspace/geometry3Sharp
And i refer to the boolean modifier in blender: https://docs.blender.org/manual/en/latest/modeling/modifiers/generate/booleans.html
@broken nest ^
Thanks a lot 🙂
Kind of a follow up question, is there a 3d object by default that's only one triangle? cos there's a quad with 2 triangles. Do I have to get blender for that?
No, you have to either: use a modelling tool (like blender), use probuilder or build the triangle procedurally via code
Thanks, how do i do it via code?
You can search up ”procedural mesh generation”, but it’s definitely not the easiest way. If you only need one kind of triangle, you should use one of the former options. Mesh generation is mostly useful for meshes that will change between runs of the game
Cubes have many triangles
thanks a lot guys
"Where is the best place to start learning Unity? I already have some experience in programming.
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
!docs
Hi all, I am new to code and i am already stuck. i figuerd i could use some help lol. Can someone tell me why my code is not working atm?
how exactly is it not working? what's the issue?
seems like you have an error - make sure to read what the error is saying and where it's coming from
if you're following a tutorial, make sure to follow it accurately
How do i setup visual studio again?
I followed the guide but component don't show highlighted and stuff
I did that already
read the entire page
Got it working i was missing something in visual studio
Hi im having issues with the Contain function on a script. Basicly whats happening is if the searchBar.text = "g" and the p.name = "gible" its not seeing that the name contains "g".
Why is this happening?
https://paste.ofcode.org/davrfPJQRD295LVw9kngNZ
First id check if the text from the search bar contains any other characters. You can use Trim() to remove whitespace.
use a debugger or logs to double check the string data
Ive been using debugger and what I put in above is what they have
Show us what you saw in the debugger
also make sure p.name is actually the field you want
name is the builtin one from UnityEngine.Object
oh yea, for scriptable objects its the asset name
im trying to set up bloom on the unity's toon shader but i cant make it work. i had followed the code monkey tutorial and a bunch of other tutorials with post processing and whatnot and nothing seems to work. and i have enabled post processing in editor, every other effect like motion blur works, but not the bloom. HDR is also enabled. Intensity of the bloom is also cranked up to like 50
thats how I want it to be
the object is not bright enough with regards to the other objects in the scene and the bloom thresholds you set
using UnityEngine;
public class BirdScript : MonoBehaviour
{
public Rigidbody2D myRigidbody;
void Start()
{
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) == true)
{
myRigidbody.linearVelocityY = 5f;
}
}
}
why wont the linearvelocityY work?
This should work just fine and i trust c# so lets presume its doing its job and there are infact 0 matches
therefore verify the data its looking though is what you expect
what do you mean by "work"? What is happening and what do you expect to be happening?
when i click the bird should go up, and i just get a ton of error
UnityEngine.Input.GetKeyDown (UnityEngine.KeyCode key) (at <e4b8a4a19a094df29d095a590f2c7cf0>:0)
BirdScript.Update () (at Assets/BirdScript.cs:13)```
Thing is thats what I thougt but its adding none to the matchingDatabase list at any point when that is one of the examples and it has g
Seems like a pretty self explanatory error
your code is trying to use the old input system
but your project is using the new input system
(the new system is the default in new projects)
How can I change that
if only i'd knew why
What's teh new input system
no matter what i do with the intensity and threshold - nothing works
this is a #1390346776804069396 question not a code issue
#💥┃post-processing or this
Must be that your all list is missing this data.
Also you should avoid copying the entire list and making a new list. You should clear the existing list and AddRange().
The screenshots I sent in show that my list isnt missing the data tho?
Also Ill fix the copying thing thanks!
This is from the same update
Then the issue is elsewhere such as the list you are adding things too is not what you are using to display results.
Its pretty clear that Contains() is working as intended so its either the collection you are searching or the destination collection you are adding things too.
Ill look into it more but Im like 99% sure its all right. Thank you for the help anyway!
Investigate each potential cause and when you can verify it works then we move on. You can even do a test with hard coded data such as the search value.
Its easy sometimes to fuck up a var name elsewhere and have weird things happen (ive done it myself many times!)
My example on dot net fiddle was to demonstate that yes we get the expected result from Contains() so that works as intended
perhaps check if there are any invisible characters in there
Already checked and doesnt seem to be
So I added in a Debug.Log before hand to see and it does seem to return false for all of them:
https://paste.ofcode.org/yVNHseMmW2wWjXq5tyH3qv
something else is up or these characters are some weird other unicode character
I'm guessing it's the good old wrong type for an input field instead of TMP_InputField
Howdy folks. For a few years now I've been plagued by an issue where, after loading the title screen of my game, and choosing new/load game, everything pauses for 5-6 seconds while the scene loads. This happens about 1 out of 20 times, as normal scene loading is instantaneous. Its a simple 2D game with very little in the way of assets on a 7800X3d... so this is quite unusual. No errors are being thrown during this time and the PC is otherwise idle.
I notice it occurs with editor->play and when released and installed on iOS and Android. On mobile the delays can take 20 seconds or more even in release mode. Its rare, so not too disruptive. But given things normally load instantly I've not added loading bars. And even if I did, given the length of the pause the bars wouldn't do much. So my problem is I've struggled to identify just why things are locked up for so long. Even deep profiler debugging hasn't been too useful in highlighting where all the CPU time is going. Curious if anyone had thoughts about how to debug such a thing?
use the profiler?
I'd mentioned I use the deep debug profile capability. It also locks up and is unable to give any insight into things.
Rather, Unity is so busy its not sending packets to the profiler.
Any idea what it could be? Ive been trying to find it but I cant
Also updated contain to use the trim and all but same result
oh "deep debugging" you meant deep profile, are you doing a build or in editor
What's the type of searchBar
I mentioned I do both. I run it in the editor AND I've deployed on iOS and Android.
Its a TextMeshProUGUI
It should be TMP_InputField
I've tried every combination of optimizations (most of which remove profiling obviously). Its random, and is rare, hence why its difficult to track down.
Input fields have an invisible control character
Can you copy paste one of the logs here?
I'd thought perhaps there was some caching going on. Because like just now, I loaded up Unity and it happened right out of the gate (which is why I thought to come ask about it). But it probably won't happen again today. Is there a cache I can go delete to see?
Library folder
Swapping it over touse the InputField instead fixed it! Thank you so much
What about on an iOS or Android device?
Library folder doesn't exist for a released/installed game.
I legit never knew this but I have basically only used TMP
yeah for release not sure where it gets put, I think you can print it out with the Applicationclass through logs https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Application-temporaryCachePath.html
this temp one tho
Thank you. I'll see if nuking that allows the pause to happen consistently so I can sort out what is up.
are you testing on real device or emulator
Real devices.
My iPhone generally outperforms my 7800X3D slightly, so the pause is present but 4 seconds to load isn't horrible. On my Android devices it can be over 10 seconds though. In some cases I believe it has locked up and then just pop, goes. And since the pause doesn't happen the rest of the day its like...well that sucks. Will certainly give a first bad impression to folks though if I can't optimize it out.
I think those two devices also have their own profiling tools you could also try those maybe ?
Android Studio and iOS has one forgot what its called
(needs xtools) https://developer.apple.com/library/archive/documentation/AnalysisTools/Conceptual/instruments_help-collection/Chapter/Chapter.html
Offers a complete list of Instruments help articles.
Hmm. I've not tried to get the native tools going. Given how debug packets stop being sent/received during the lockup to the Unity Profiler, I just assumed the native tools would get no updates either. Generally all higher level debugging is taking place over TCP/IP which is what seems to be getting trashed.
In my dayjob I do embedded development. There is benefits to having hardware level breakpoints haha.
ya true.. I'd still give it a try see if they yield some better results than unity over tcp
I'm honestly getting confused with rb.linearvelocity. when I hold the jump button to jump higher how can I get the exact peak height? I want to get the exact height and make it so if the player is at this height just for a few seconds the double jump will be available.
a hang time of a few seconds is crazy
how would you do it?
i wouldn't make double-jumping a timing skill check
but i don't know what you're going for
The player will sit at the same exact height for a few seconds?
What I am going for is a ground slam feature so the double jump will allow the player to have enough height for the ground slam feature I am going to add later.
could just have those be separate actions, and make the skill check in the output, not the input
if you time the double-jump poorly, you don't get enough height
if you don't get enough height, the ground slam might not work or might not do as much damage - but you'd still be able to input that, and fall to the ground faster
Hello again i want to rotate the player so when he sit there is a great view , i just want to center the camera i have tried a couple thing but it dont work on the player gameobject , is there a way to directly rotate with something like transform , vector
oh wait i just cant rotate the player
okay i found the problem
As i this is my problem and i also guess its the wrong way to move a camera is there better way than this ? **Vector2 currentMouseDelta = Vector2.Lerp(previousMouseDelta, m_lookAmt, smooth);**https://paste.mod.gg/eoodmqjoomic/0
A tool for sharing your source code with the world!
that's called wronglerp, it's framerate-dependant and asymptotic. if you want the same ease-out smoothing, there's a better alternative (along with an explanation) here: https://unity.huh.how/lerp/wrong-lerp
🤔 Unity, Huh, How?
Applying lerp so that it produces smooth, imperfect movement towards a target value.
Yes Thank you so i should still use lerp ?
i mean, you aren't lerping. it's reusing the math behind lerp with different inputs to get a different result
alright thanks
if (yRotation > 360f) yRotation -= 360f;
if (yRotation < -360f) yRotation += 360f;
```this part isn't super necessary, but if you'd like to restrict it to a range, you would need `while` instead, or better yet, you can use `%` instead to not have any looping
Thanks for the info! so I'm not going to make a exact height, just going to make it the higher you are the more damage you do and the lower you are the less damage you do. would I use the players Y velocity for this?
Why not just a raycast/cast down from player to ground
if you continuously accelerate for the slam, sure (probably with a terminal velocity corresponding to a max damage)
but that's up to your design
also up to level design for what you need to support
a raycast could also work but would break if you do it above a platform that moves out of the way before you hit it
The more ways I think of to do it the more issues that come with it. How would you personally do it?
everything in development has compromises you are willing to live with
there is no "correct way" you have to make it work for your design / tolerance to pros-cons with each solution
personally I'd start simple with a ray check if I have enough / min distance height, maybe check some Y velocity for enough momentum . Some ignore layers could help weed out moving objects unrelated if you need
could also store the y position you started and compare against the y position you hit the ground at
https://docs.unity3d.com/6000.3/Documentation/ScriptReference/Collision-relativeVelocity.html
for dynamic rigidbody is also an option for OnCollisionEnter
(thats for the damage amount - not initiating the slam in the first place)
Would I cast 2 separate rays? one for when when your high and the other one for when you are low
I meant the ray to check if you're at min height for a slam, if you want to check for example how much damage do the other suggestions, comparing values
is the slam a consistent speed ? is it faster/stronger when you're higher ? etc. those are also playing part into comparison
I want the slam to be faster / stronger when your higher and when you are lower its less fast / less stronger.
so yeah i'd start with a height check doing a cast from your current height to ground
Hello again any idea why my player is always suddenly teleporting when i'am sitting ? (this is my chair script but i'am not sure if the problem is coming from the chair tho https://paste.mod.gg/pynbrifblkig/0)
A tool for sharing your source code with the world!
How would I get the height? the player's Y linearvelocity?
you can compare Y values too sure, if you use a cast you just use raycasthit.distance
https://docs.unity3d.com/6000.3/Documentation/ScriptReference/RaycastHit-distance.html
guys, i created a build web gl for my game but when i try to start the server in local it doesnt finish loading. does anybody know why?
this is the repo where i started the server
idk if there are supposed to be more files
Hey yall I am new to all this shit and I am trying to upload a vrchat model to unity so I can put it in vr would anyone be able to help me?
Open the browser's JS console and post the errors to #🌐┃web if needed
this is a server for unity development, if you need help with vrchat stuff i recommend their own server
Join the growing VRChat community as you explore, play, and create the future of social VR! https://discord.com/invite/vrchat
can someone help me with the tilemap
idk why this happens
this isnt a coding question
most likely camera / pixel perfect needed
Hey! Currently Im having a problem with enemy attacking - primarily Ranged attacks not hitting near the player. The main issue is it going almost haywire, and going into different directions. Im thinking its because of rotation either in the bullet or the object transform, but I cannot find where my script would cause that. Attached are the two scripts that control the Enemy Firing:
EnemiesHandGunFire: https://paste.ofcode.org/TSXGphH4rZqQBRku6Nzp8E (Controls when the gun should fire - as you see there is a current issue with it firing multiple times in quick succession, but I'll focus on fixing that up later).
EnemyFiringProjectileScript: http://paste.ofcode.org/7sRXYbXdDuPFDPwJYt47j8 (Controls the actual creation of the bullets, the main thing that I think causes it. Is called by the EnemiesHandGunFire Script.)
Does anyone have any idea as to why this might occur? I've checked different ways as to fix it, including making the time between bullets extremely long and turning the gun (and attackPoint), but they haven't had success.
If you do help, please @ me. Thank you so much! 
so I have this to run different codes depending on having 1 or more elements in a list, for some reason else if condition causes stack overflow, is .count not good for this case?
if (Clip_Name.Count == 1)
{
RandomClip = Clip_Name[Random.Range(0, Clip_Name.Count)];
PlayAnimation(RandomClip, FadeDuration);
}
else if (Clip_Name.Count >=2)
{
if (PreviousClip == RandomClip) { PlayRandom(); }
}```
its probably PlayRandom()
show the entire code in context
thing is it worked fine before I added the conditions
probably something you changed, depends where you call this code & PlayRandom does
doubt its .Count itself tho
PlayRandom is probably constantly calling itself cause of condition causing overflow
the project is a bunch of cards(buttons), when clicked it adds to the list of cards, and I don't want it to repeat the previous card to I tried writing this
public void PlayAnimation(string AnimationClip,float FadeDuration )
{
Animator.CrossFade(AnimationClip, FadeDuration);
}
public void PlayRandom()
{ StartCoroutine(SearchPreviousClip());
if (Clip_Name.Count == 1)
{
RandomClip = Clip_Name[Random.Range(0, Clip_Name.Count)];
PlayAnimation(RandomClip, FadeDuration);
}
else if (Clip_Name.Count >=2)
{
if (PreviousClip == RandomClip)
{
PlayRandom();
}
}
}
IEnumerator SearchPreviousClip()
{
yield return new WaitForSeconds(2f);
PreviousClip = RandomClip;
}
I'll try again, I must've missed something
if same clip is chosen repeatedly, PlayRandom() calls itself forever
yiks
I'll see (still new to this lol)
do note that start coroutine doesnt pause the function its in , the code under it runs immediately without wait
ooof
maybe you can try
public void PlayRandom()
{
if (Clip_Name.Count == 0)
return;
string newClip;
if (Clip_Name.Count == 1)
{
newClip = Clip_Name[0];
}
else
{
do
{
newClip = Clip_Name[Random.Range(0, Clip_Name.Count)];
}
while (newClip == PreviousClip);
}
PlayAnimation(newClip, FadeDuration);
PreviousClip = newClip;
RandomClip = newClip;
}```
probably is a better way, my brain aint fully braining right now but give it a try lol
lol and thanks
np.
let me know if it works out
Wanted to also note without having a large spew of text on my first message:
The scripts are similar to my normal player scripts, which work without having the weird direction mess ups. Here are the player HandGunFireScripts and the FiringProjectileScripts in case you wanted to look at them:
Player FiringProjectileScript: https://paste.ofcode.org/NLZXBG6CmstaruCb7AEnGN
player HandgunFire: https://paste.ofcode.org/JzEenqDFU4P7nLYkNMQXg5
The last few times I've made a new Unity project, it's had compiler errors immediately upon creation, and I've had to remove whatever Unity packages were causing the error. com.unity.collab-proxy is the biggest offender. Is this a known issue?
I suggest removing anything that's adding deviation to the direction and get something to just fire forward first.
For the entire 2 hours I’ve been working on this I’ve haven’t thought of that or something remotely similar rip.
I’ll definitely do that and see if that helps. Thank you!!
someone pls help i've been trying to fix this for hours now i can jump but the game doesn't detect the raycast:
using Unity.Mathematics;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
public Rigidbody2D rB;
public float playerSpeed = 1.0f;
public float jumpForce = 5.0f;
public float playerHeight = 2;
void Update()
{
//playerMovement
transform.rotation = quaternion.Euler(0, 0, 0);
if (Input.GetKey(KeyCode.Space) && GetIsGrounded() )
{
rB.linearVelocity = new Vector2(rB.linearVelocityX, jumpForce);
}
if (Input.GetKey(KeyCode.A))
{
rB.linearVelocity = new Vector2(-playerSpeed, rB.linearVelocityY);
}
if (Input.GetKey(KeyCode.D))
{
rB.linearVelocity = new Vector2(playerSpeed, rB.linearVelocityY);
}
}
//groundedCheck
private bool GetIsGrounded()
{
return Physics2D.Raycast(transform.position, Vector2.down, playerHeight, LayerMask.GetMask("Grounded"));
}
}
!code
Posting 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.
also start off with basic debug lines
specifically in your grounded check and then in the jump function
I tried debug.log in GetIsGrounded() but it doesn't say anything in console
It probably isn’t even getting to GetIsGrounded() if that’s the case. Are you calling it somewhere?
Oh I see where you called it- I’m blind
right where did you put the log in GetIsGrounded()?
the line under return physics2d.raycast
now im fairly certain your ide isnt configured as it would point out instantly that, that line of code is unreachable
return ends the function right there, if you want to log the bool value of return Physics2D.Raycast(transform.position, Vector2.down, playerHeight, LayerMask.GetMask("Grounded")); you'd need to do something like
bool Grounded = Physics2D.Raycast(transform.position, Vector2.down, playerHeight, LayerMask.GetMask("Grounded"));
Debug.Log(Grounded);
return Grounded;
for example here what you had would have the ide practically yell at you saying hey no
also is your ground layer called "grounded"?
no it really is Grounded
and you assigned it to the ground gameobjects in the scene?
yes
what does the debug tell you then
i tried that code i dont know why but in console it says true
so its returning as true?
yeah it says true
you still havent explained* the actual issue here, you said the game doesnt "detect the raycast" but if its returning as true then it is?
so whats the problem
the problem is that i can walk and jump i added the raycast but it doens't work while i typed if (Input.GetKey(KeyCode.Space) && GetIsGrounded() ) and now its returning something
it still doesn't work
what doesnt work....
you still havent actually told us
whats supposed to happen and what is happening instead
first you said its the raycast but now you said its returning true
groundcheck so i can't triple jump
so when you added the debug it came back as true even if you were trying to jump in the air?
The ground check does work though, as you've said the log is saying "true" which means the GetIsGrounded is also returbing true
Don't think youll see this because I didn't ping ya, but this was exactly the reason. Thank you so much!
Is this what they meant? Hard to tell tbh, but if this is the case i would recommended adjusting the value after Vector.down as that's the length of the raycast
yeah i still have no clue what they meant
some people dont make it easy to actually help them
we arent mindreaders, we cant guess whats going wrong without knowing what is happening that isnt supposed to.
I try to add a raycast for a groundcheck so i can't infinitely jump i added that in the script but i still can infinitely jump that is the problem
great ty, i would start with the last thing i mentioned which is reducing the value of playHeight here since it's the value that dictates the length of the raycast
Edit: though the total height jumped looks like a lot more than the playereheight value of 0.5 from the video
hi
i have 2 players in my game and added a mechanic that if i click on a player it selects them then right click somewhere else it moves there.
i just wanted to add a visual effect like a "highlight" when i click on him. smth for like half a second.
how can i do that?
yk "highlight" isn't the best word for it. smth better would be a "glow"
An easy way would be some outline post effect
hmm. i think if its easy i can go with it. but it isn't really what i wanted.
wait a mom. i will search for an example
If you want a VATS like "highlight" then you can achieve that with a post processing effect or cheat and do it on the shader itself
still doesn't work i really really hate this shit maybe its better to rewrite the script??
nah nah, its smth very simple but im new and don't know still what args. to use for this.
here
Oh well just making a sprite "brighter" is easy with a shader
head to #1391720450752516147 to ask more/how
ok thanks
BROOO the problem was that i put the player layer on grounded accidentally 3 hours ago or something😭 tysm for your time♥️ @rough granite
I am trying to make it so when you double jump and between the red and blue lines I want the height check to trigger only around that specific height and I am going insane. idk if the y velocity value is right at this point .
you need a reference to your jump height, i dont think velocity would do you any good here, basically get a reference to your y offset from the initial point you jumped at and when its above a certain threshold it should allow you to double jump
Yea if you track the amount of jumps taken and the position where the first jump happened you can probably do this a lot easier
Agreed, just pick a minimum height needed to do a ground slam. when the jump starts, log the current position, then track the position (only while jumping, or better yet, in air) every frame, if it exceeds your minimum height threshold for a ground slam, then activate/allow the player to ground slam . . .
can i ask something ? to someone (its a very basic problem but idkn how to fix)
you can just ask yes
just ask; don't ask to ask . . .
im doing a blend tree with the float Velocity,
even if i start the game scene i try to edit the velocity by the blend tree but the float does not change
it change only if i manually input on the parameters
srry thank
show what you tried
yeah, we need to see the code to get an idea of what is wrong . . .
so the velocity it dosent change if i simple move the bar?
cause i just wanted to se some blend animations
everyone i saw on yt it dosent assign a script to move the bar and modify the float
did you see or watch what they followed to achieve that?
yeah
Learn how to animate characters in Unity 3D with dynamic animations from blend trees!
This beginner-friendly tutorial is a complete walkthrough of one dimensional blend trees and how we can use blend trees to create new animations for our characters using float parameters
ACCESS PROJECT FILES & SUPPORT THE CHANNEL:
💛 https://www.patreon.com...
his parameter move when he drag
idkn why mine dosent he dont have any script attached to his blend tree
this is a code channel
prolly #🏃┃animation
thanks
Today is my 19th birthday!
To anyone who is somewhat acquainted with fg generally like hitboxes and framedata and all that. Would using box colliders be better for hitbox and hurtbox detection or box cast?
Sorry fg as in frame gen? If so what's that have to do with hitbox collider types?
Ah lol
You think you could answer my question? I try not to @ random people but I couldnt help but notice you are aware of games like Melty Blood and so I thought you be kind enough to help out rq?
Yea dont do that
ok
To actually answer your question. Primitive colliders perform better than mesh colliders so always use those if possible (Box, Sphere, Capsule).
its not 2004 anymore so you are not forced to use boxes
Yeah I dont mean Mesh colliders
I mean if I should base my hurtbox and hitbox system using a box cast or use colliders. Like cast seems more customizable and fit better for stuff like hit box and hurt boxes in fg
I just dont fully know
Box/Sphere casts are for when you want to "sweep" the shape along a path and detect intersections
But triggers attached to objects moving over time should work just as fine (with the right settings)
Okay cool
One more question
While Im here
Can you change the color of colliders?
Like making specific groups of colliders in the scene red or white?
No but you can draw a gizmo yourself with different colours
Ohhh for some reason I just assumed that gizmos only work in tandem with cast
Ok cool thank you
Gizmos are the visual thing shown in scene view
Hi does anyone know if it's safe to assign list values in the inspector?
one time i did that with a list of color objects and unity domain reloaded or smthg (the game WAS saved after i inputted the color values) and the list reset and became empty in the inspector
I had to look through the .unity file in my github push history to retrieve the color values I set earlier so I can add them to the list in code
is this a common issue or just a bug? it was in 2022.3.8f1 btw
i like your pfp lmao even tho i havent played omori
I don't believe this is isolated to just lists? The inspector values may be reset with certain changes to the script. There are particular actions that would make it occur but I don't recall.
oh i see
is there a way to avoid that from happening?
or is the best habbit to just get references to everything in code
because when i searched it up online it seemed that everyone said that assigning stuff in the inspector is fine and efficient
no one really mentioned the possibility of the values resetting
If in play mode, nothing will be saved. Otherwise this will work just fine unless you did something weird
Assets and scriptable objects will keep their state and can be saved regardless of play mode
i dont think I was in play mode considering the color inspector values were pushed to my github repo at some point meaning it was prob across coding sessions
Then you must have done something weird to have this data loss. Did someone else modify a scene and override your changes?
I don't recall exactly when or why but if there's enough change, the inspector values are reassigned to their default values (they're re-serialized)
okay thanks I'll try and learn to use scriptable objects
I think it may be that
I might have changed the script to initialize the list in the awake method or something
Dont jump the gun when you dont know what you did before...
Modifications in play mode do not matter.
The only other thing I can think of is the use of [ExecuteAlways] meaning you modified the data in edit mode
Yea I think so too now
thanks for the advice ill be more weary about messing with inspector assigned values in code
Basically in edit mode that stuff is able to be saved so take care if modifying things then.
You can use Undo to make editor stuff undoable (i forget if things like Odin do this for you with Button)
At runtime (play mode) its not a concern at all (except for assets)
Woah that seems helpful thanks
If it's resetting outside of play mode, it may be due to some changes made to the members. For instance, changing the type of something exposed to the inspector would default the value. I don't recall if changing other signatures like the name of the member would though.
I'm not sure if you are supposed to expect data loss except when renaming without telling Unity what the previous name was
I am attempting to create Pong.
Pong has a "spin" mechanic where the ball receives some of the velocity of the paddle when it collides with it.
This requires me to accurately be able to discern when the ball is being hit by the paddle. My thought was to completely disregard RigidBody2D and use the Cast method to get back collider infomation.
However colliders don't seem to collide with objects that don't have both a body and a collider. And RigidBody2D kinematics seems to plow through other kinematics and is entirely unhelpful.
Am I missing something?
I'm aware of full collisions mode on kinematics, but they still penetrate colliders (and even collide with stuff behind them). I'm also aware of Physics.Distance, but It's rather unusable if I don't have complete control over every movement the body makes.
Ideally, I would like a body that collides with everything else in a predictable and sane matter that I have complete control over. That is to say, I can call a method on it and it will go as far as it can in that direction, stop if there is a collision, and report it back.
A Kinematic Rigidbody 2D can still move via its velocity, but the velocity is not affected by forces or gravity. A Kinematic Rigidbody 2D does not collide with other Kinematic Rigidbody 2Ds or with Static Rigidbody 2Ds and will only collide with Dynamic Rigidbody 2Ds. A Kinematic Rigidbody 2D behaves like an immovable object (as if it has infinite mass) during collisions, and mass-related properties are not available with this Body Type.
Yes, I have experienced this firsthand. It is a behavior that I find entirely unhelpful in my situation.
Is there a body that does as described here? #💻┃code-beginner message
The documentation promises something called a CharacterBody in 3D, which is a combination rigidbody and collider.
I have no idea how this thing works, but it implies that building what I want is possible.
Unfortunately unity is closed source so I have zero idea how it functions, and no guarantee that the tools to make it possible are exposed
You need to code it yourself, and you can still use a dynamic rb but override / control the velocity yourself
there are functions like Vector2.Reflect that are useful
Hmmm, so you want to move as though it's a kinematic object but want non kinematic collision detection?
Non-kinematic collision detection that I can invoke whenever nessicary, yes
Collider2D.Cast is FRUSTRATINGLY close to what I need
If you're just wanting kinematic behavior for movement, you could have some object with a kinematic rigid body and have some joint to connect it with a non-kinematic object
I... See...
Technically I suppose I could do that
It seems like a very roundabout solution for something that I don't imagine is a particularly rare want
Okay, perhaps I'm approaching this from the wrong angle.
How would a unity developer create the spin mechanic in pong?
It's looking more and more like Dynamic is wildly more general than I thought it would be.
I could certainly try to force a dynamic body to behave how I would like it to, but the concept of this sounds like a lot of wasted calculation. Not that it would matter for Pong, but I am ATTEMPTING to learn good practice.
Apparently I forgot to copy the block of code from the if statement, "else if" was repeatedly telling to re-run without randomising the clip, so PreviousClip=RandomClip the whole time without changing
It was simple and it slipped under my nose lmao
if (Clip_Name.Count == 1)
{
RandomClip = Clip_Name[Random.Range(0, Clip_Name.Count)];
PlayAnimation(RandomClip, FadeDuration);
}
else if (Clip_Name.Count >=2)
{
if (PreviousClip == RandomClip)
RandomClip = Clip_Name[Random.Range(0, Clip_Name.Count)];
PlayAnimation(RandomClip, FadeDuration);
}```
there's no reason to use Random.Range inside the first 'if' statement. if there is only one clip, then just assign the first item in the collection . . .
Oooooh right I did not think about that lol
Thanks
Is it normal to use an invisible 3dobject with a onCollisionEnter function to detect collisions or is there a better way of doing it
If by invisible you mean has no mesh renderer then yes
Can Somone Tell me how you can get better at scripting I cant do anythink how do I start😩🤌
it's a skill, you get better with knowledge and experience, you gain knowledge and experience through research and practice
It takes time to get better, just like with everything else in life. Depending on your previous experience and how you're approaching this, the learning curve may vary.
Are you lacking programming fundamentals or simply having trouble integrating with the Unity API?
I just don’t know where to start learning coding
okk
anyone know how to stop the piston from phasing trough? this is the code: using UnityEngine;
using System.Collections;
public class XYPushRetract : MonoBehaviour
{
public Vector2 pushOffset = new Vector2(-0.3f, -0.2f); // X, Y movement
public float pushTime = 0.05f;
public float returnTime = 0.1f;
private Vector3 originalPosition;
private bool isMoving = false;
void Start()
{
originalPosition = transform.localPosition;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space) && !isMoving)
{
StartCoroutine(PushAndReturn());
}
}
IEnumerator PushAndReturn()
{
isMoving = true;
Vector3 pushedPosition = originalPosition + new Vector3(pushOffset.x, pushOffset.y, 0f);
float t = 0f;
while (t < 1f)
{
t += Time.deltaTime / pushTime;
transform.localPosition = Vector3.Lerp(originalPosition, pushedPosition, t);
yield return null;
}
t = 0f;
while (t < 1f)
{
t += Time.deltaTime / returnTime;
transform.localPosition = Vector3.Lerp(pushedPosition, originalPosition, t);
yield return null;
}
transform.localPosition = originalPosition;
isMoving = false;
}
}
post your code appropriately please
!code
Posting 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.
Posting 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.
wait mb
is this supposed to be physics based
no i just use a collider for it
that's physics...
kk
do the player and piston have rigidbodies?
if so, they need to be moved via the rigidbody, not via the transform
piston is the child of the sphere, sphere itself has rigidbody
Buttons and sounds, make things play sound on click
Simple and might be fun
well since the piston has a collider, it should be moved via a rigidbody, but i think ive heard child rigidbodies not going super well. maybe you'd need joints or something
ye when i tried rigidbody on the child it jus broke the game, ty ill try that
I have a question about this line of code. Does it copy the list or does it grab a reference to it ?
List<Vector3> tempBoardList = _boardPositions;
reference
You can make a new list and pass another as an argument to make a copy
If the type of the object is a reference type, then you always copy a reference(excluding some exceptions). If the type if a value type, then it's a copy by value.
I figured it must have been a reference
I am really new to unity, and trying to use and create wind based grass for my terrain but can't do it, tried to follow a tutorial ,I don't understand , tried a script don't know how to use it
Ask in the right channel #⛰️┃terrain-3d or maybe #1390346776804069396 if it is shader related and also explain what exactly you have issues with
Or is it a code issue?
I actually don't know...more like a skill issue
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
thank you
I tried searching for procedural wind grass before and I know it's not on the Unity Learn Wiki
So i have the basic perlin noise terrain generator from the asset store, how do i make some cave and tunnel?
its easier to maker some cave model, and cut a hole in the terrain?
If using unity terrain, make a terrain hole https://docs.unity3d.com/6000.3/Documentation/Manual/terrain-PaintHoles.html
Then join up some other mesh
Im not going to look at these random scripts you sent though
this is a basic perlin map generator xd
can a terrain go to -y?
Terrain uses height maps which can only go up/down
To make a cave properly you need to use terrain holes to make a hole and then join up a real mesh or other terrain.
If it is a procedurally generated terrain, I would assume it would be quite difficult to smoothly connect the caves to the terrain holes. Especially if you want to enable terraforming or other such advanced features, you probably want to look for other ways to generate proper 3d terrain like the marching cubes algo.
Yeah continous terrain generation struggles with caves and overhangs, youre just displacing a plane on the y axis in certain spots
Youre either going to have to do what rob said, cut out a hole and join it up with a cave mesh
Or use discrete voxel based terrain generation, which can create caves and overhangs without issue
Use a small voxel size and some kind of reconstruction algorithm like marching cubes or dual contouring.
how can I remove an object programatically in a build?
so like if its a build, get rid of debug objects
oh wow so after all that its just a tag 😅
i thought i needed some special script
thank you!
hello, I was making project and studying form Unity official studying program and I switched to scene1 to scene2 and after switching back to scene1 it doesn't works and animals that were moving are gone and I can't place them either while running game either, how can I fix it?
looks like your code is trying to access an object from one of the earlier destroyed scenes
without seeing the exact code causing this issue, we can't say much more
but you're probably doing something like having a DDOL object that is keeping direct references to objects in the scene it starts in which is being unloaded
there is a lot of code, I can show you
one very helpful thing would be to see the full error message that you screenshotted above.
It will contain a stack trace telling us the exact file and line number where it's happening
you mean this?
(when you have it selected the fullmessage will show at the bottom of the console window)
yes
actually this looks like an error in the editor/inspector
like perhaps you had an object selected that was unloaded
yeah I'm thinking the same because I did this earlier in lesson 1 and now in lesson 2 it happened this, switch from scene 1 to 2 then back to 1 and bam secen 1 doesn't works
but scene 2 works well, I deleted scene 2 but it didn't help
it's really hard to say without seeing your project
the code and scene setup will have some issue
I can show you no problem
a project contains animals coming down at random directions, player moves left and right and shoots pizza to feed them, if animal and food makes contact they both get destroyed, if animal gets past player animal gets destroyed
should I send screenshots of codes I've written?
!screenshots
No
Be mindful, if someone requests your code as text, don't send a screenshot!
!code
Posting 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.
thanks I'll keep that in mind
Hello team, I was wondering if anyone has a example script or game source files
