#archived-code-general
1 messages Β· Page 399 of 1
If it's not code related, perhaps ask in a more appropriate channel #archived-lighting or the more general #π»βunity-talk
Unity have spent many years migrating to new .net, just wait a little more shall we π€£
thx
dude im on my phone, unity is on my pc i dont have unity on my phone
how about discord on your pc
Nah too lazy to install
im really not sure what the issue there is
Or open whatever
sounds like a you problem; don't make it all of ours too
you don't even need to install discord
There's the browser Discord option as well
Edit: wrong target for reply
you can open it on the browser
Oh
Okay txn didnt know
Hi everyone I am stuck on my dev may I have some help plz ? Its about to aline my player gameobject to the animation (the animation has Root T modifications)
!ask
:thinking: Asking Questions
:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #πβfind-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.
-# For more posting guidelines, go to #854851968446365696
see the last point specifically
You'd go to the appropriate channel, provide the necessary information and anyone who's available (and willing to help) will give you suggestions.
@vestal arch Why my brain told me interface is not an inheritance, because any class can have any interface and any number of interfaces. When inheritance it is like a tree, so I would rather say class can inmplement many interfaces rather then class inherit from many interfaces
lol, lmao even
i have no idea what you're trying to say
Okay parent can have children, each chield can have many own children that is inheritance. but with interface any of this class can implement same interface
if you accept polygamy you can have as many parents as you want
if you accept polymorphism you can have as many parents as you want
Decompilation is not allowed to be discussed here
okay
When I have SplineContainers passed in as prefabs into an object, can those pefabbed splines transform be modified in any way or should I instantiate them directly in the scene, correct their positions and pass them into the container that way? It works when dragged in (they automatically take the parent's transform) but not when passed in as prefab
private void UpdateSelectionIndicator()
{
// Calculate the index of the selected button based on currentRow and currentCol
int index = currentRow * HERO_COLUMNS + currentCol;// Get the button corresponding to this index selectedButton = characterSelection.buttons[index]; // Update the position of the selection indicator (anchor to the top-left of the button) RectTransform selectionRect = gameObject.GetComponent<RectTransform>(); // Set the selection indicator's parent to be the selected button (this should be done only once) gameObject.transform.SetParent(selectedButton.transform, true); gameObject.transform.localScale = Vector3.one; // Set the anchor and pivot to the top-left of the button selectionRect.anchorMin = new Vector2(0, 1); // Top-left corner selectionRect.anchorMax = new Vector2(0, 1); // Top-left corner selectionRect.pivot = new Vector2(0, 1); // Pivot at top-left corner // Position the indicator at the top-left of the button selectionRect.anchoredPosition = Vector2.zero; }
How can I convert this to make it work with netcode? SpawnStateException: NetworkObject can only be reparented after being spawned
UnityEngine.Debug:LogException(Exception)
Unity.Netcode.NetworkObject:OnTransformParentChanged() (at
Parent of RectTransform is being set with parent property. Consider using the SetParent method instead, with the worldPositionStays argument set to false. This will retain local orientation and scale rather than world orientation and scale, which can prevent common UI scaling issues.
UnityEngine.Transform:set_parent
Parent of RectTransform is being set with parent property
It seems weird you would be instantiating a UI element that has a NetworkObject in the first place
something is very wrong with whatever you're doing
Hey guys. My Unity project works fine, but when I build it, I get this:
Here is the important part of the log file
Using Unity 6.25f1
I really don't know how to fix this serialization issue. I've tried reimporting everything to no avail.
Looking at the logs seems like pretty much all monobehaviours are misbehaving...
Thi might imply that you're using conditional compilation(incorrectly). Share one of the mentioned scripts.
!code
Posting code
π Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
The error actually explains that.
I mean it was working fine in singleplayer before I started to make netcode object lol
I checked all mentioned scripts. I also ran a search through the whole project for any #if EDITOR, but couldn't find anything
I'm using newtonsoft's JSON for serializable calsses, but I have done so in the builds prior as well
It doesn't have to be the script itself. It could be one of it's serialized fields. Anyways, it's hard to say anything without even seeing the code.
how can I figure out what the massive holdup is here? I don't understand how one line can take 17k ms but when i drill into it, I don't see 15k+ ms of that accounted for.
Waiting for async operation to complete might imply that it's waiting for background threads to complete. It might be helpful to look at other threads.
@verbal hazel Hmm yea if this is async scene loading then await it or handle it correctly to not block...
once i go into play mode, everything is deleted from my scene besides my canvas. how do i fix this?
Seems like a silly question - but anyone know how I can easily delete item 0 from a list in the inspector without manually re-linking all the other items? (order matters so I can't just drag the nth to the 0th position)
You're starting from the wrong scene
If you wanna test "Level 2" then you have to load that scene (probably when you finish level 1? or continue from the main menu)
Select the element and click the -?
Or select it and press del
Oh! I thought that always deleted the nth element.. TBH I didn't even realize you could select a list item
Worked great, thanks much.
thanks it works now
also my lighting only works for level 1 for whatever reason
how are you creating your lighting in scene 2?
(and how are you doing it for scene 1?)
sounds like you're either not bringing your lighting into the scene, or you have different camera settings on 1/2
i just copied what i did from scene 1
I can't really tell what you're showing me.. but on one of the lights, you have a global light, and the other you have a spot light? And those objects are both in level 1 and level 2?
snap a pic of your hierarchy when you're editing level 1 and level 2 - and highlight your lights
i'm about to go AFK though so might not be able to help you .. but maybe someone else'll see what you've done.. but I suspect you've deleted your game objects, either by loading the scene, or something else
Is nullability generally used in Unity? If I enable it my ide lights up like crazy, however I don't really want to have things be null without specifically typing it as so
Just enabling nullability, doesn't mean that reference type would get an instance assigned magically. It just enables errors at compile time, which is exactly what you see in your ide.
References would be null, unless you explicitly assign something to them.
Right, I'm just curious if most unity developers enable it
I don't think so. It might be useful in simple programs, but games are way more complex and nuanced.
I guess it's also partly a preference thing.
We have it enabled in our project
It's a little annoying around serialization, and UnityEngine.Object subtypes' fake-null
but it does help to weed out basic logic errors in normal functions
when I'm trying to convert the render pipeline
It asks me to save scene for some reason
You probably created a new scene and didn't save it?
Or used the sample scene. It's known to cause all kinds of issues.
Ohh
Indeed
For some reason my scene suddenly changed to a new scene
any good soul/mathematician that would spend some time with me finding a good exp progression in my game?
I had the sample scene completely reset on me once. Good practice is to scrap the sample scene and create a new one
Sometimes after a restart or a crash it'll open this "default scene" with nothing in it. You just have to find your saved scene in your assets and open it again
By default it opens your last active scene IIRC, which is why people are sometimes surprised that they lost all changes where in reality they didn't
Is there a limit towards unity's instantiate?
So I made a for loop that supposed to loop 5 times and the instantiate code inside it
However it only spawns 3 of the game object for some reason
hey is anyone familliar with people playground if you do pls dm meπ
If you have a question you should post it in here. Nobody is going to DM you
No
If this is happening, the code's behaviour intentionally spawns 3
If you want help, share the !code and somebody can point out the problem
Posting code
π Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
I found out the reason towards that is because a code that detects collision and removes the object after a certain collisions
and sometimes they collide with each other and causes them to reach the max collisions when spawned
if i were to go about adding weight to my object how would i . by weight i mean the ability for a player to sit on a pulley and that actually affecting them and bringing them down or up?
ight is anyone experienced in coding a mod in people playground it uses C# language
And also here it would help if you actually post the question https://dontasktoask.com/
oh alr thanks
I don't know what People Playground is, but generally discussions involving modding something are not allowed here
hmm i dont mean by cheating by the term modding i meant like adding more variations to the game it includes coding
hi guys just started unity, is it allowed to ask dots/ecs question here? thanks!
Modding doesn't have to be cheating specifically. This server doesn't allow discussing altering a game like this
But again, if you want help you'd have to post your question
I currently have a chest, which I want an animation to play, when I enter the BoxCollider, how can I access the animation?/Play it when the box collider is triggered
The script is only for testing rn
reference the animator component and set a float/bool/int to change to play oncollisionenter
Ill just ask if you guys dont mind. Would this be considered bad practice for ecs? I am using theese properties for my netcode entities fps controller.
I am really new to this, but I am sure, you can inherit from a class which has these variables
hi thanks for answer but Im curious can you please elaborate? Ive always thought that unless working with managed types, you shouldnt use classes for unity dots?
yeah, for ECS you should avoid inheritance
you should probably ask at #1062393052863414313
but one alternative is to have tag components instead of one big component with all of the bool values
or enableable components
gotcha thanks
having them as separate components makes it easier to query
already did but its been inactive, thanks anyways!
hey it alright to ask another question? nothing too specific just about how I should approach the architecure of the code
an advice of sorts
that's a bit too broad, but I would say to keep managed and unmanaged code as separated as possible
no i mean I have another question, is it alright to ask u?
of course π https://dontasktoask.com/
so i guess my question would be an extension of this. Since I'm using a client side prediction for character controller, wouldnt it just be right to update these properties in client side? I am wondering since because when i'm updating these properties in predicted simulation system groups and while they do update in both server and client they often differ in results or in other words its not synchronize.
So, this is my code and setup for the chest, the player character has the Tag "Player", Idk what I am missing, any clue?
is there a openchest parameter in your animator window
yes obv
and is the transition set to use the openchest parameter
click the plus sign in conditions
makes sense....
also if you want no smooting frames btween animations set transition duration to 0
kk thanks, it seems to be looping tho, it could be my code
could be
it certainly was not, thanks for ze help
also for similar questons ask them in #π»βcode-beginner
Ok lmao, I thought general was fair, since I know how to code, I just dont know all the classes, functions/methods yet
It depends on the context. Composition means breaking the behaviour into smaller replaceable components(not necessarily unity components).
You're asking a question that is much too general. What's the specific use case you are trying to address?
Is the user a game developer?
End user/player of your game?
What's the feature and how do you want them to provide an implementation? In the form of C# code?
Then use interfaces or base classes. This has nothing to do with composition though.
These are 2 completely separate things. I'm not sure how exactly you put them in an x or y statement.
Whatever fits your needs. An interface would allow them to provide an implementation for whole objects. The same thing with delegates might require you to implement many interfaces for each method you want the user to be able to override.
Unless I'm misunderstanding what you have in mind.
What's with people deleting messages after a conversation started? Just leave them lol
i'm trying to add logitech SDK to my unity project, but its saying its not existing, can i fix this issue or just cant do anything without writing my own integration ?
also, the DLL is here
i have modified no script from the Asset Store pluygin
that is a native code dll, how is your code accessing it
Looks, fine ,what I would expect
this is the import setting for a standalone build, switch to the editor tab (the one to the left)
yeah it was already ready for it
Why am I getting a type mismatch when I put a part of my character's rig in my public Transform property?
you cannot reference scene objects in an SO
so i searched and found nothing... i'm lost as what i need to do now.
Did not know that, thank you
I cant see anything obviously wrong, is this a free sdk?
its the one Logitech give on their Asset Store page
link?
which unity version are you using?
that's not good, not a LTS
let me just have a look with Unity 6
alr
Is load order (and consequently instance IDs) deterministic in a built project?
certainly not
I suggest you read the reviews of the asset, it looks like it does not work out of the box and needs some extra work from your side
oh
Good to know, thank you!
Any recommended ways of uniquely identifying objects deterministically?
By... referencing them?
Its possible for the DLL to not be made specially for Unity ?
should not make a difference. But I saw others downloaded a different dll direct from Logitech
tbh, looking at the asset I'm really surprised that Unity even accepted it for the Asset Store
why ?
doesn't work, throws errors, relevant documentation is non-existant. All big red flags
i mean , it might have used to work in the past, it just dont work anymore
well, that is not the impression I get from the reviews
hasnt been updated since 2018 so idk
that should tell you plenty
You either successfully made the most insane insight on the design problem I was running into, or that was a misunderstanding from my context-lacking question that conveniently worked out
Either way your answer got me to a solution, thank you!
I have a projectile gun and I'm experiencing a wierd bug that didn't happen before I applied the bullet pool
For some reason sometimes when I try to shoot the gun it's flying off to a different location first
before proceeding to fly with it's original direction
and the position that it's flying to seems to be the position that the bullet pool created the bullet from
this is the bullet if I just enable it without doing anything
Show the code where you spawn/launch the bullet
The script that I applied is here
GameObject currentBullet = BulletPool.bulletPool[bulletType].Get();
currentBullet.GetComponent<CustomProjectiles>().Reset();
currentBullet.GetComponent<Rigidbody>().angularVelocity = Vector3.zero;
currentBullet.GetComponent<Rigidbody>().linearVelocity = Vector3.zero;
currentBullet.transform.position = attackPoint.position;
currentBullet.transform.rotation = Quaternion.identity;
//Rotate bullet to shoot direction
currentBullet.transform.forward = directionWithSpread.normalized;
//Add forces to bullet
currentBullet.SetActive(true);
currentBullet.GetComponent<Rigidbody>().AddForce(directionWithSpread.normalized * shootForce, ForceMode.Impulse);
currentBullet.GetComponent<Rigidbody>().AddForce(fpsCam.transform.up * upwardForce, ForceMode.Impulse);
The custom projectiles reset function seem to have no effect on it cause I tried to disable the script and it have no changes to the outcome
Sometimes it works perfectly fine shooting towards the angle that my camera is looking at
and sometimes it just fly towards the other position before flying according to the angle of my camera
Firstly you should not be mixing Transform and Rigidbody. Use one or the other
Secondly, for the love of God, cache the Rigidbody reference
Using both sounds reasonable for immediately getting the bullet into the right position -- but, notably, the rigidbody's position and rotation aren't being set at all here
If the bullet has interpolation enabled, it will ignore the position and rotation that got set here
exactly, so, as it's coming from a pool, the previous values will apply until the next physics update
So I should assign the reference to a variable first?
ideally you'd do this
It sounds like you do have a component already..
But I have 3 different bullet of the Bullet type
I would use rigidbody.position/rotation instead of transform to teleport it into place
So add a Ridigbody reference to CustomProjectiles
So what?
Like I have a Explosion Bullet, Thunder Bullet and Split Bullet
I presume you have three different pools, then
And directly assign the bullet's velocity instead of adding forces might make a difference
These three types can all inherit from a Bullet class
basic polymorphism
each kind of bullet can have its own special reset logic, if needed
So i need to make them inherit?
What I did until now is that all of them share the same script with different values
Let me try it
Another thing to try is to wait until FixedUpdate before spawning the bullet, but that might be noticeable
do both!
this will ensure the bullet is in the right place during rendering
I don't know exactly when an Interpolate-enabled rigidbody moves its transform
if it goes after you, then no harm done
Right, I'm just not sure if it'll get positioned correctly on the frame that you spawned it
what would be the best solution for slope movement? im using triggers to detect the ground(its very effective lol) but i have no idea how to apply that to slopes, i really have a hard time doing it ,_,
Okiee it works now
But there's still a slight error
I like to use spherecasts for probing the environment around the player
like due to the bullet having a trail it is now kind of obvious towards the player that where it's coming from
You'll need to fuss with the TrailRenderer.
(assuming that's what you're using)
Diaagonal spherecast from the center of the body is what I landed on
For my own movement system
interesting
I exaggerated the angle here abit
yepp
so do I disable it first and only enable after I set the positon or?
This made implementing vaulting/climbing pretty easy
so you have for example 4 spherecasts around the player near the ground or..?
Not sure if thats a criteria for you tho
It should have a method to clear its points
owhh I see thankss
Use as many as you need
Or, well, as few as you need
Useful for restarting a trail from a new position.
well there ya go!
Put all of this into the "reset" function on your bullets
Make the method virtual in Bullet and override it in the specific bullet classes
@soft escarp The good thing about spherecasts is that it gives a smoothed/averaged normal when hitting a corner. A raycast does not
That way, a bullet with five extra trail renderers can go and reset all of them
and the code that spawns bullets doesn't have to care at all
I forgor
you've tried to call Clear() on the GetComponent method itself!
π
Also, no, bad! Make that Bullet class! 
I forgor the ()
The spawning code shouldn't have to worry about all of these intricacies
i think that spherecasts are way better for ground checking than raycasts, after all your character is not a stick
but it didnt work out for me(no skill lmao) so i just used triggers to detect ground
i think i will need to go through every layer of hell and back to do slope movement(just because i dont know what im doing)
public abstract class Bullet : MonoBehaviour {
[SerializeField] private Rigidbody rb;
public virtual void ResetBullet(Vector3 spawnPos, Quaternion spawnRot) {
rb.position = spawnPos;
// etc.
}
}
public class CoolBullet : Bullet {
[SerializeField] TrailRenderer trail;
public override void ResetBullet(Vector3 spawnPos, Quaternion spawnRot) {
base.ResetBullet(spawnPos, spawnRot);
trail.Clear();
}
}
e.g.
One important thing to know is that if your spherecast starts inside another collider, it won't detect it as a hit
So you need to make sure that the spherecast starts completely inside the player's collider
A tiny bit smaller, preferably
alternatively, you could offset it backwards a bit
so the origin is inside of the player and then adjust the offset?
(or maybe do both)
I see thanks
but I need to rewrite the code though
Yes, I guess. What do you mean with adjust the offset
Offset from the player's bottom anchor, yeah
Well I only clear the trailrenderer after I set the object to active
GameObject currentBullet = BulletPool.bulletPool[bulletType].Get();
currentBullet.GetComponent<CustomProjectiles>().Reset();
Rigidbody tempRb = currentBullet.GetComponent<Rigidbody>();
tempRb.angularVelocity = Vector3.zero;
tempRb.linearVelocity = Vector3.zero;
tempRb.position = attackPoint.position;
tempRb.rotation = Quaternion.identity;
//Rotate bullet to shoot direction
//currentBullet.transform.forward = directionWithSpread.normalized;
//Add forces to bullet
currentBullet.SetActive(true);
currentBullet.GetComponent<TrailRenderer>().Clear();
currentBullet.GetComponent<Rigidbody>().AddForce(directionWithSpread.normalized * shootForce, ForceMode.Impulse);
currentBullet.GetComponent<Rigidbody>().AddForce(fpsCam.transform.up * upwardForce, ForceMode.Impulse);
However the trail is still not being reset
You want this, no?
They re calling it
Also why continuing to GetComponent the Rigidbody when you already have tempRb
Oh somehow I misread that as calling Reset()
whoops
I missed out
Yeah I called the TrailRenderer.Clear
Maybe I cleared it too soon or smth?
oh yeah, one thing to watch out for
What if you toggle emitting and/or enabled off and on again?
Reset is a special method name for Unity
On the trail renderer
That method gets called when you reset a component, as well as when you initially add one
let me try it
You're clearing the trail renderer before the object's transform gets moved
The rigidbody moves the bullet from wherever it happened to be to the correct position after this code runs
I thought so too
That's why you should set the transform's position immediately
just make sure it agrees with the position you give to the rigidbody
So I sure put transform and rigidbody?
Okiee
Yes.
Lemme try it
That puts the bullet in the correct position instantly, and also tells the rigidbody that it should be in that position
Order of operations can be very important
@zenith acorn Just a word of advice, when using object pooling you should reset them to their start configuration when you put them back into the pool not when you take them out
owhh okiee
Thanks for the suggestion
I'll definitely change that
Hi,anyone know how I can keep the remaining particles alive after the projectile gameobject that they are attached to is destroyed? I already set up the script so they are being unparented and still alive before the parent is being destroyed. But that somehow makes them still disappear and snap to the collision point instantly. The simulation space is set to world...
Did you check the heirarchy whether they are unparented or not?
yes I check it during runtime and they are succesfully unparented
code would be helpful
What scale does the projectile have and what is the scale mode of the particle system set to?
And yeah, show the code
I just copy the whole code here in chat?
no, use a !code paste site
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.
as Confucius once said; the error in your code may be after the red error lines
If Confucious said that he was wrong
wait I believe Ive found the problem! When i disabled the collider for the projectile, then it worked for some reason
But does it ever hit anything if you disable the collider
oh yeah no that's why. So it was never destroyed... sorry. Pulling my hair here. Posting the code
A tool for sharing your source code with the world!
also apart from fake confucious quotes is there a more elegant way to get the gameobject of a collider than
"raycasthit.transform.gameObject.TryGetComponent"
going through transform seems a little goofy
That's actually not going to give you what you want
If the collider has a Rigidbody in one of its parents, RaycastHit.transform will be the transform of the Rigidbody
RaycastHit.collider is the actual collider you hit
- Vehicle <-- rigidbody
- Door <-- collider
hit.transform would be the transform of Vehicle even when hit.collider gives you the collider on the Door
if that isnt giving me what i want then what can i do to get the gameobject a collider is attached to through a raycasthit
There is no other collider than the parent. Still doesnt explain why the particles disappear
i already told you how to find the collider you hit
it's pretty trivial to get the game object from that..
Is there a reason you are making this extra parent for the particles? cs // Create a placeholder object to keep particles alive GameObject particleParent = new GameObject($"{ps.name}_Detached"); particleParent.transform.position = ps.transform.position; particleParent.transform.rotation = ps.transform.rotation;
Can't you just set its parent to null?
Seems like you just want this.
// could just have the ps in world sim space anyway
var main = ps.main;
main.simulationSpace = ParticleSystemSimulationSpace.World;
ps.Play();
// unparent from the object
ps.transform.SetParent(null, true);
// nuke the ps object
Destroy(ps.gameObject, main.duration + main.startLifetime.constantMax);
Notably, this could cause the local scale of the particle system to change
And particle systems default to a scaling mode that only cares about the local scale
Also, reparenting without worldPositionStays will reset the... world position
The default is to keep the world position.
Hmm ok, it looks like the particles all suddenly snap to the collision point... I'll check the worldposition
// Ensure the particle system continues in world space
var main = ps.main;
main.simulationSpace = ParticleSystemSimulationSpace.World;
// Detach the particle system using worldPositionStays
ps.transform.SetParent(null, true);
still didn't change anything... :/
You can't just change the simulation space at the last second like that
All of the existing particles will now be in the completely wrong position
it's always set to world position in the inspector
Pause the game immediately after impact and select the particle system
there should be a window in the scene view that shows you info about the system
see if the particle count is zero or not
what would you lads say is an okay way to deal with queueable varied actions in a game styled like the sims franchise?
this is a fun topic
I am genuinely taken aback by the speed of that reply
was still typing out the details lol
it's still spawning particles, just at the collision point
ha, go ahead :p
Okay, but did the number of particles abruptly go to zero?
(or at least go down)
i want to make sure that's not somehow happening
i.e. after clicking an NPC (or actor) you are now in an "action mode" of sorts. clicking something raycast-enabled will now bring up a radial menu from where the actor can pick relevant actions
ground:
- go here
- drop object here
_ _
building: - perform [work] here
- drop off item
- wait here
Seems about the same
that kind of stuff
I was thinking of handling it with an inheritable BaseAction script or something similar which I could queue up in the actor's Actor script component
you've declared the same field twice
or you have two copies of the class in different files
yeah -- and you might compute a sequence of actions to perform a larger task
I was working on an RTS a while ago where telling a unit "attack that thing" would cause it to:
- Try to execute the Attack action
- Fail, because it's too far away, thus queueing a Move action in front of the Attack action
- Wander over to the target
- Try to execute the Attack action
- Fail, because it's at the wrong angle, thus queueing a Rotate action
- Rotate to the target
- Try to execute the Attack action
- Whack!
My current project uses goal-oriented action planning to let the AI figure out how to achieve things. It generates a BrainMoveAction to move to a place, then a BrainActivityAction to perform the "attack" activity
This is a lot less involved, but it does mean that you're not figuring out a coherent plan all at once
divide complex actions into smaller basic ones, and treat the big action as a sort of pseudo state machine?
I recently added a way to give entities commands, actually
You right click on a target and get a list of every activity that makes sense for that target
then the entity is asked to make a plan that makes that activity possible
it was very fun to see that in action with very little legwork
Hello, it appears that Collider.attachedRigidbody is not being automatically set to a new parent's rigidbody. I have been implementing a magazine for vr use and I have added manual insertion of bullets to the top, but here is where the problem comes. The bullets get parented to the magazine in an empty transform and have their rigidbodies saved in a component "ComponentRigidbody" that also performs DestroyImmediate on the rigidbodies. The colliders of the bullets should therefore automatically attach themselves to the magazine's rigidbody, but they don't.
and the list of "action that make sense" are manually assigned, I assume?
nah, the activities are generated by all of the entity's modules (e.g. a grabber module to let it pick up things in the environment)
so on click you fire off multiple checks to populate the list rather than assigning things yourself
The more abstract you get, the cooler the system is to describe to someone...and the more of a pain in the ass it becomes, too
π
hm so assuming I click the ground for an interaction, I would first attempt to make the navmesh check if it can go there and, if not, it will not populate the radial menu with a "go to" action
so, coming back from my Architecture Astronaut hellscape
Yeah, that's basically what I wind up doing -- if you click on nothing, it figures you just want to move there
So you'd have a new "action" called MoveToAction
You'd put that on your queue and then immediately engage the action
eeh I don't know about clicking on nothing since I wanna be very strict about what is movable terrain and what's just there for the sake of being pretty or set dressing
by "nothing" I mean a spot without an entity
.enabled = false; .enabled = true; fixes this, but whenever parenting the bullet out of the magazine, and adding the rigidbody back to the bullet, the same problem occurs and that's even when doing the re-enabling.
I want the game to be somewhat moddable in the future, and map designers may want things to not go somewhere
You could make the action just tell the entity's NavMeshAgent to move there
or you could have the entity ask its current action how it should move
(I recently switched to the latter)
sorry for bumping you away uldyr, I think I'm just about done brainstorming here
Try running Physics.SyncTransforms() after modifying the hierarchy
thanks for the different perspective fen. I was thinking a way more rigid approach to this
Otherwise, I'd expect nothing to happen until the next update
Ok, ill follow you up on anything soon
One handy thing about this approach is that AI-controlled characters will work very similarly to a player-controlled character
The only difference is that the latter has its action queue filled by player input
I like turning everything into an Entity where players and NPCs differ only in input
as long as it's an easy to expand system I'll be pretty happy
as-is I'm only creating a foundation for a couple of possible projects it could branch into in the future
Parented to the magazine, DestroyImmediated the rigidbody, Physics.SyncTransforms(), still nothing
Here i print the Collider.attachedRigidbody references of every bullet in the magazine
Can you share the !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.
waiterino then
this should be in the order of execution
I can answer any questions related to any method calls
ok and here is the thingy, there is another component called AssemblyRigidbody that is put into the root of transforms that are going to have ComponentRigidbodies made for their children to save their rigidbodies for whenever the children get parented out of the root
I am aware now that UpdateStoredBullets() is called before the two blocks of code in the middle, but the fact that for the previous bullets that get their Collider.attachedRigidbody printed out with the print being null means that there is a problemo regardless of sequence atm
I'd be very leery about using DestroyImmediate in non-editor code
I wouldn't be surprised if that's what's preventing the attached rigidbody from correctly changing
Regarding my previous problem.. If I just added a slight delay (0,1) before the projectile was destroyed then Unity apparently had enough time to detach the particle systems completely.. so now it works
I tried using regular Destroy, it didn't help, and i know that it messes with what my system already tries to do. I have the glock that i use in unity have an AssemblyRigidbody component attached to it that will save the childrens' rigidbodies, and with regular Destroy, the transforms get updated once by the rigidbody causing offsets
The parent changes immediately.
That sounds very odd
Although whenever running for the first time, everything does work in the sense that the glock parts (slide, barrel, spring assembly) have their colliders attached to their parents' rigidbodies
Yeah i know. I got the idea when I tried to grab the projectile and unparent it when pausing the game while it was in air, and then it worked fine. Still don't understand why, but that's part of game dev I guess
Hi, and merry Christmas.
I'm wondering if anyone has experience with potentiometers as inputs for Unity?
This is what I'm working with.
Potentiometers are model rv24yn 25f b502 0701c 321 - company called OMTER
Is there a question?
Yes, I'm wondering how potentiometers are used to move a target's X and Y position.
It's not working very well.
ah, so you do have valid input from the device?
although it appears to be either -1 or 1 on both axes
how are you receiving the input?
The gun is connected via USB cable. Using Unity's new input system.
If anyone is interested... I traced these graphics in Adobe Illustrator and saved them as SVG.
Anyway, I'm attempting to figure out the controls.
Could ask in the dedicated channel #π±οΈβinput-system
Good idea, thanks!
Explain that you have -1..1 and nothing in between
i imagine that has something to do with the fact that the binding path specifies it is "XinYeDigital"
digital input would typically only be -1..1
well and 0
@heady iris lmao, I have fixed it by simply having implemented a "SyncComplexColliders" method that does .enabled = false; .enabled = true; on all of the ComplexColliders of a given GameObject. I do this immediately when parenting a new bullet to the magazine and i found out that i needed to do it one fixed update later when removing a bullet.
Thank you for having at least mentioned Physics.SyncTransforms()
If I wanna have some UI in my 3d game that's placed near units in the world (ie, "popup" info dialogs that appear above the unit, regardless of zoom/location of the camera), should I do that in the world, or just on the canvas and figure out a raycast location? Is there a standard way of doing this?
(health bars comes to mind)
Oh, and I also didn't want to deal with having that UI rotate towards the camera
Depends what your needs are. For healthbars you can do something like this pretty easily: https://www.stevestreeting.com/2019/02/22/enemy-health-bars-in-1-draw-call-in-unity/
but if you want to display something more complex, I'm not sure it'd be worth it, so yea either worldspace canvases or some math on a screenspace canvas.
SteveStreeting.com
Recently I needed to do something pretty common in many top-down games: render a whole bunch of health bars for enemies on the screen. Something like this:
Obviously, I want to do this as efficiently as possible, preferably all in a single draw call. As I always do before I start something, I did a quick search online of what other people are do...
you can use in-world sprite renderers too which works ok, but IIRC there are some gotchas with sizing
Yeah, when I think this through some more.. I don't think I want UI floating off screen if the camera isn't looking at it so .. I'm gonna need to roll my own with raycasting
ie, if there's an active unit that's offscreen, I probably want some sort of triangle at the edge of the screen that the user can click on to snap the camera to that unit
And yeah - I read this article a few weeks ago, I think. I don't have many units (~20?) so I don't need to go nuts with the canvas optimization.. but it looks like he's doing what I was hoping to avoid - ie, calculating the rotation and handling the rendering manually
my poor man's version will just slap them in a higher layer (instead of doing them in shaders)
part of why I like that post is that he explains his reasonining for why he's doing it this way, which is useful even if you decide to do it another way
yeah.. I'll read it again more closely today
if you just have 20 things I would probably just use worldspace canvases since that sounds like the least amount of work and it probably won't matter
yeah
the normalization of the items towards the camera is nice
didn't think of jus grabbing the camera's .forward property and calculating a normal vector on each ui element
I'll have to see if it works seamlessly with cinemachine but I imagine the cinemachine vcams have the same properties as normal cameras
at a minimum, a .forward vector i can use
TextMeshPro comes with an object that renders in the world without needing it's own canvas. Are there elements in IMGUI that have the same? (I suspect not, and that I need a canvas for these)
TextMeshPro is based on TextMesh, which is exactly that
isn't IMGUI the immediate mode one that doesn't need a canvas at all?
I don't think TextMesh is really part of UGUI, but it does exist.
the TextMeshProUGUI component renders in the canvas, but tmp also comes with the TextMeshPro item which renders in the world (really nicely, might I add)
I have some aftermarket UI libraries though, so.. yeah, nevermind - I'm gonna need to make a canvas for this
Yes and Unity has a TextMesh component that is equivalent to TextMeshPro
Oh, I remember that.. it's been years since I used it
(not gui)
yep, and you could mix that with sprite renderers to create an in-world, sprite based gui
but you'd lose out on all the scaling features that canvas comes with
Now I'm wondering if I should just do this all in UI (instead of in the world) and just... manually calculate the location in the screen to show this stuff instead of trying to do this all in the world
also totally valid
Yeah.. and like I said, I have this aftermarket shit (which I like) which probably would be a hassle to figure out how to make work without a canvas
soft masking
there's some notes about using it with canvas shadergraph
hm.. will ponder what I wanna do.. but I think I just wanna find the quickest way, it's just for a demo
hello guys please feel free to check my projects on itch.io and i hope that you can support my work by a little donation and thanks a lot β€οΈ
https://hedi-dev-studio.itch.io/
not here
Any coder wanna make a top down rpg?
(use unity forums for collab seeking)
And also.. you're gonna find yourself pretty quickly banned by crossposting it as much as you are...
Alr
you could make a #1180170818983051344, but not like this blatant ad
hey yall. having issues with builds in Unity 6. Basically, it does make the build, but then it hangs on "Running Backend", basically indefinitely (I tried it last night when i went to bed and it stayed there for 8 hours, haha)
the weirdest thing is, the build does get made, like I can then run the built game and everything. Its just, I have to force quit Unity.
not a code question, but did you check the logs?
The one in like App Data/etc/etc? Editor.log? I did but i dont see anything useful in there, no visible "error" or anything like that
is something up with unities default camera?
its only at 90fov, but feels very fish eye, or am i crazy
Not sure where the code question is... but field of view is vertical
whoops yeah not really a code question
just feels like the centre is zoomed out and the edges are more distorted to account for that
but have no real way to test this against anything else
yeah that might be it
maybe every other games fov is in horizontal
Is there any way to run AssetBundles in play mode (without manually using the editor menu)? I keep running into the error:
InvalidOperationException: Building AssetBundles while in play mode is not allowed, please exit play mode first.
Also if anyone knows, I'm trying to upload a cert.pfx to my server build, and I'm having troubles getting it into a build... I cant push a DefaultAsset when referenced.
why are you trying to build an asset bundle in play mode?
It's a potential solution to having an object be pushed to a build. My logic is have it bundled with my build and 'instantiated' once built.
I also can't get addressable's to work again because it's a DefaultAsset
a DefaultAsset won't have any actual content in it
perhaps a TextAsset could help you there?
I'm thinking it will have to be...
That allows you to add arbitrary text or binary content
Alright thanks so much.
I don't understand this
it doesn't sound like you want to be trying to create asset bundles in play mode, for sure!
(and that's what unity is complaining about)
I'm trying to push a cert.pfx file with my server build. Unfortunately its not really recongized as a text file. And I'm not sure if my transport will read a text file.
The .pfx is a combination of pirvate and public keys and is in binary making it more secure and it can hold both the public/private key.
I might try the .pem file and see if that works? As its in text.
yeah, I'm vaguely familiar with the formats
Assuming you have code that can parse the format, just include the keys in a .txt file (if it's a text-based format)
The extension is irrelevant; you're going to reference it as a TextAsset
If it has the extension .pfx it wont enable me to do that
You won't be reading it directly from a file. You'll grab the .text property from the text asset
The extension does not matter.
None of the files in your Assets folder actually exist in the built game or in asset bundles
They're imported into internal Unity formats and eventually packed into archives
Can a .pfx file have its text extracted though?
File extensions are meaningless
The only thing that matters is whether the format is text-based (meaning you're meant to read it as a Unicode string) or binary (meaning that it's a completely arbitrary series of bytes)
Do you have code that can actually parse a .pfx file right now?
Alright I shall push a cert.txt file as a TextAsset and see what happens?
My transport bayou reads a .pfx file? But potentially .pem files also.
Not sure if it parses it, or presents it to the browser.
I actually have no idea.
Straight answer, no.
hmm, it looks like Bayou expects to be given a path to a certificate file
If that's right, this means you need to put a file on the user's filesystem
Correct. It's usually in the directory of my server executable when it's on my VPS. But I dont have that luxury when using deployments (Edgegap)
I just push a docker file.
So the cert needs to be INSIDE the game?
And accessible.
does it need to be included in an asset bundle?
I figured that would be a solution.
The first thing that comes to mind is using StreamingAssets so that the file is directly copy-pasted into the build directory
It seems weird to include secrets as part of the built game though
right, but I still wouldn't have that be part of the actual build
I'd insert the secrets separately
(and at that point you can just put them wherever you want)
Thats placing the cert.pfx in the StreamingAssets directory?
Correct.
How so?
Tried that. Didn't work.
This would have nothing to do with Unity at all.
You'd just...put the file in the container as you build it
Hmmmm. I'd have to look into adding docker commands. Maybe I can include it with docker.
Secrets should never be part of your actual build. They should be installed separately.
I think what I'm doing is called being a cowboy
You're right
It'll be easier this way, too π
(actually, ideally, the secrets don't go in the image either -- you'd insert them as you start the container up)
Been a hot minute since I seriously used Docker, though
Alright. I'm sure theres a docker command to include the cert with every build/container.
OKAY! I feel alot better, I'll give this a shot.
Thanks so much @heady iris
this might be stupid but is there a way to refrence a script like you can with a gameobject?
you can do public gameObject obj; and no matter what object you select obj.transform.up will always do the same thing
can you do a similar thing with a script?
It has to be attached to something in the game, convention is an empty game object ?
You can store a reference to any unity object type
If you've got a class called Foo that derives from MonoBehaviour, you can store a reference to any instance of Foo
This could be on a prefab or on another object in the scene
how do you declare a script?
you don't "declare a script"
public Foo something;
this declares a field named "something" that can hold a Foo
i realise what i was looking for was an "interface"
Hi all! everytime I save a script file in visual studio, Unity displays a "importing assets" for about 25 seconds.. anyone knows what I could do to avoid this? (I'm using Unity 6 and I already tried disabling the auto-refresh of the asset pipeline)
Auto refresh should be responsible for that.π€
would it be considered bad practice to use a single IJobChunk for physics based character movement in Unity Entities with NetCode? (input is on seperate system btw just to be clear)
hey guys, i am trying to get my ads work in my game but i keep getting this error
Assets\Scripts\AdsManager.cs(72,45): error CS0426: The type name 'Builder' does not exist in the type 'AdRequest'
[20:03]
No one seems to know how to solve this, i ended up joinig here
aaandd this is the code
i'd really appreciate some help 
dunno whats going on.
You mostly have not the right library or you need to update.
They're already in #π»βcode-beginner. Please don't crosspost.
So, there's a lot of different ways to do this, but I want to know what would be ideal for me.
What is the best way for me to handle triggering effects based on an animation playing?
I basically want to be able to associated animations with specific triggers at specific points during the animations. It needs to be done to an extremely large number of animations, and it needs to be able to trigger a variety of unique effects.
Should I;
-
Use Bones to drive the triggers, that are observed via code (easier to work on in the original animating side, feels inefficient though?)
-
Use Animancer's Event system to try and add the events to the animations in Unity itself? I don't have the fancy extra-price version, so I'd be fighting with the Unshared States of the older version.
-
Use Unity's animation event system? (I've heard it's kind of bad?)
-
Make my own custom system from the ground up (I am an adequate enough programmer to do this, but I'd rather not if I'd just be making an inferior version of something better that already exists)
-
Use some other (free) third-party package to do it? (If so, which one? Does anyone know?)
This is for a turn based RPG, where I want to be able to trigger stuff like unique effects, hitboxes, SFX and particles at specific points of an animation.
If you use Animancer, you should use Animancer solution as a rule of thumb.
That being said, Unity Animation Event System does work in most case. Without knowing more about your project I cannot say if it is a good idea or not.
Gotcha. So Animancer's event system is pretty good then?
No idea.
Usually, you want to double down on the asset you use.
...So you're just suggesting it because it's there? Ahh.
Otherwise you get multiple way of doing the samething and it can be hard to work with it.
I've used the standard Animator for a lot of project. While there is issue with it, Animation Event was not one of them.
Right now, I mostly try to wrap all of Animancer's components in my own middleman classes since I don't like some of the ways it behaves. I'll look into Animancer Events, then, and see how well I can use it in my workflow.
@dlich and @steady bobcat thanks for the tips yesterday about my performance issues. I think I've tracked it down to how I was loading my addressables. You guys pointed me in a direction I hadn't thought of. thanks π
I like it
I mostly use Animancer events. I only use the normal animation events in like...one place, for footstep sounds
I think, at least.
Anything I should know, to avoid nightmares and terror?
Any ides about making hitmarkers that allign with where the hit occured?
Use the hit position to instantiate or move a hit market to that position.
if i have a system where my players has to snap to a position to do a takedown animation . how do i smoothly reach instead of just teleporting
Lerp or movetowards the target position in update
But if its being cover it just ends up glitching with the terrain
"cover"?
Cover as in like behind an object
So player-box-enemy
So when leaping the box gets in the way
Lerping
I don't understand how that's related to the original question.
If you have difficulty explaining the issue in words, record a video.
Or use proper translation tools, assuming it's a language barrier.
So if a player is taking down an enemy it checks if it can with a trigger collider now if it teleoports to the kill position its fine but if I lerp the movement and there is an object the player will collide with the object and get stuck there.
Whether you snap or lerp or tween, you first have to confirm the space where you're moving the characters is valid and unobstructed
And alter the position and rotation before it when necessary
Alright
I'd say most commonly in those situations you first align the characters to face each other, then move either of them next to the other so the animation aligns and connects
There's no obvious solution what to do if the level geometry allows there to be obstacles in the way or a sloped ground underneath
Most games where that kind of fighting occurs keep the environments sparse to make it simpler
But references help here a lot, like how Dark Souls games connect the stab animations
Another technique is to only visually move the characters to do the animation, then lerp them back afterwards so obstacles are effectively ignored
I think Skyrim and Dark Messiah used that one
Since my game is 2d would it be smart to just freeze the player and do a little animation on screen for a kill and just unfreeze one the animation is done
It sounds simpler
It does but I would prefer to have a more seamless transition so I'll mess around with the info you gave above and try to figure out Smth if not I always can do that
could i get a hand
i have this problem where my attack hitbox just lands the hit on the dummy before i even click attack
you'll need to provide much more information than that!
you're gonna need to provide more details
incredible jinx
yep
got it hold up
imma screen rcord firzzt
also i followed a tutorial for the player attack script
heres the health bar function
with the death function and take damage function
It seems that you have a script inside the NPC that detects the collider when it collides it will deduct the health?
If you're only enabling it after you click you should first disable the collider first
how would i do that
could it be that you set de/active the damage collider only when you are attacking?
there is the tick beside your collider?
oh im stupid mb
now since i have it disabled
i just have to renable it in script when i letf click right/
yeah
I thought your script already does that
no
yes
or set the activity always, just based on the attacking bool
or when it ends deactivate
ye
Isn't that inefficient though?
thats what im thinking
ye, but more ways to do it π€·π»ββοΈ
the problem is
it should be working by acitvatting and deativating
thats what the script does
yeah
but its not
did you assign the collider?
ah i see
i think its because im deatcitvting the script attackArea
not polygon collider?
I guess so?
im so confused
You should make a polygon collider variable
and assign it
to the polygon collider
ye
thtats what im doing rn
but i think i found the original reason why
ye i fixedit
yunno why?
basically the get child function
i had ground check as the first child
not attackarea
i just had to swap them
omfg
took me like 1 hour
u see the get child line?
This is why using things like GetChild or GetComponentInChildren sucks
If you need to refer to a specific thing, then you should just use a serialized reference.
[SerializeReference] private AttackArea attackArea;
how can i make the player move a little in the direction the player was moving before it stopped in the air?
it feels like im hitting a wall when jumping and stopping in air
If you are setting an RBs velocity directly or modifying a transform directly this is the expected outcome, you can mitigate this by adding the velocity every FixedUpdate until it reaches the desired speed instead of directly modifying the velocity or by using AddForce for movement.
im using AddForce but this was my result
You switched to AddForce or were you originally using AddForce?
does anyone know why this is happening when i touch my ground tilemap?
show !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.
So I'm calculating the move direction by projecting my move vector onto a slope but for some reason this causes incredibly sensitive horizontal movement (looking even slightly left or right will cause the player to move more horizontally on a slope than they would on a flat surface). Is there a way to prevent it?
Sorry for no attached examples I'm having issues getting stuff working but I'll send some ASAP
Are you normalizing the vector after the projection?
A tool for sharing your source code with the world!
I'll need to see what you're actually doing, of course
I was but was told off by the unity docs
normalizing alone would be inappropriate, yes
that'd give you a completely fixed magnitude, no matter how strong your move input is
I sent my code somewhere before here let me try find it rq
ignore any remaining "wallsliding" code im getting rid of that for now
i was and i am using addforce
@heady iris #archived-code-general message
Here's the only changes
- projectedDirection isn't normalized anymore
- linearVelocity is set to
projectedDirection + Vector3.up * targetnow
also, in what way is it now "really sensitive"?
What happens if you remove the projection entirely?
i'm gonna go ahead and guess that this is actually purely visual and is caused by the animations using sprites with differing pivot points
enable gizmos in game view to be sure though
Unity finally opened!!!! I can take a recording quickly
Linked to that message is the movement with the projection removed
hm, well I'll give it a check
(also i'm bouncing in between here and vrchat so i will be away for a few minutes)
It's literally EXACTLY how I want it but the capsule struggles to stay upright
ping me when you have that new recording
Alright
actually you're right, i set a pivot point for an image, but forgot to do the rest
thanks
(it was 3am i was tired)
Okay so you were originally using AddForce and the problem is now fixed? (I'm guessing you were either modifying the transform or were overriding the velocity of the rigidbody)
One thing I don't like about this code is this part:
float target = (targetHeight - playerBody.position.y) / Time.fixedDeltaTime;
playerBody.linearVelocity = new Vector3(relativeDirection.x, target, relativeDirection.z);
You're handling the Y axis differently from the other two axes. But you're also trying to allow for movement on a slope
Instead of giving the Y axis special treatment, you should be applying this correction based on the surface normal
@heady iris
First clip is with projected movement which causes slow uphill movement and weird sensitivity with horizontal movement
Second clip is exactly what I'm going for (always consistent movement no matter what exactly like source engine games) but has the downside of sinking a tiny bit when going uphill and being a bit too high when going downhill
Sorry I don't understand can you explain what you mean in layman terms? How should I apply the correction based off of the surface normal?
The idea is it's a floating capsule so I kind of shouldn't have to deal with slopes or stairs etc, and it works but there's the issue on the second clip
i just noticed that your code is completely ignoring projectedDirection
that's probably not helping
When you're standing on flat ground, the surface normal happens to point straight up
That's not what it's like in my new code (differences listed here) but projected movement still causes an issue
ah, forgor
Your code is valid in that case. Your movement vector is purely in the X and Z directions, so it's okay to ignore the movement vector's Y component
But this doesn't work on a slope
Your movement vector should contain X, Y, and Z components
And if you need to push yourself out of the ground, you may also need to move in the X, Y, and Z directions
This is the same reason you have to use Vector3.ProjectOnPlane to calculate the movement direciton
Ohh yeah I completely get what you're saying now
Should I project the correction of the capsule's height onto the normal?
Instead of messing with components, try to stick entirely with things like Vector3.Project and Vector3.ProjectOnPlane
Multiply the correction factor with the normal vector, yeah
you wouldn't be projecting anything in this case -- you have a direction (normal) and a magnitude (correction factor)
You'd use Vector3.Project if you needed to find out how much of one vector aligns with a second vector
(ProjectOnPlane calculates that, then removes it from the original vector!)
Also, to get consistent move speed, you need to fix the magnitude of projectedDirection
If you aren't looking perfectly parallel to the surface, projectedDirection will have a smaller magnitude than relativeDirection
Some of the vector got lost
You can fix this by normalizing the result, then multiplying it by the magnitude of the original vector
(You should only do this if the resulting vector is non-zero)
projectedDirection = projectedDirection.normalized * relativeDirection.magnitude;
Wait I'm a bit confused again. Why would I need to push out in different directions or do projection if the only goal is hover above a certain point by a certain amount?
Also it seems like that did help substantially with movement on slopes but unfortunately the horizontal issue is still there and slope movement is really close but not as fast as flat ground movement
if the only goal is hover above a certain point by a certain amount?
I don't know what you're talking about here
I'm not talking about how to do the height correction here
I'm talking about the movement direction
Oh, I see.
Sorry I don't think we were on the same page lol.. what're you thinking rn?
You're making the player float a certain distance above the ground
Yeah to avoid handling stairs and slopes and stuff similar to how Valve did it
I thought this was a correction to push the player out of the surface
That would depend on the ground angle
But this does not
Ah right yeah sorry lol should've been clearer
Just to clarify if you look at the 2nd clip do you kind of see what I was explaining?
no
yeah -- without projection, running downhill will cause you to fall off the ramp
and running uphill will shove you into it
I'm not clear on the "horizontal issue", though
sry for a reply after 30 minutes but i was doing something else
Horizontal movement seemed a bit more sensitive based on the angle of the slope if the movement was projected but I think it was kind of a given issue since I'm well.. projecting..
as in, you move too fast?
Which direction is this in? Down and up the slope, or left and right on the slope?
I think the issue is down and up the slope feels too slow because I'm projecting on the normal (where left and right wont be influenced since it's only angled upwards) but left and right on the slope feel weird because they're going at the normal seed
This suggests that part of your code is still giving the Y axis "special treatment"
The Y axis isn't my issue with projected movement because the jitter issue is fixed using that
Wait I just had an idea
What happens if you completely got rid of the velocity that's based on (targetHeight - playerBody.position.y)?
The capsule would fall to the floor and die lol
If projectedDirection is correct, then you shouldn't need any correcting factor to move around at a constant height
barring small errors as you reach the slope
I think I know why the 2nd clip has the jitter issue. I need to find a way to take into account the velocity the player is travelling at
Because it's trying to reach what would be the perfect offset from the ground when there's no velocity
But it's reaching the perfect offset while the player is moving so it looks like the player is sinking / raising on slopes
I wonder if I can just add the projectedDirection's y onto the targetHeight
Ok no nevermind I just shoot into orbit
Does this explanation make sense btw? Sorry it does in my head but I don't know if it does to anyone else
No what? I'm trying to see if your problem still persists, does it?
Does your code still throw out projectedDirection.y entirely?
(the code shared earlier constructs the final velocity vector using target for the Y component)
Yeah it literally just throws out projectedDirection as a whole because it didn't really help
Don't add it to the target height -- but do consider adding it to the velocity you calculate
Imagine you're moving up an 89 degree slope.
Almost all of your movement is in the +Y direction.
If you discard that component, you have almost no velocity left
projectedDirection *= speed;
projectDirection.y += target;
basically
projectedDirection helps because it accounts for the verticality of the slope which I don't really want to do so I don't really feel like projectedDirection will help me
I don't want to adjust the speed or moveDirection at all for slopes since it doesn't work with what I want (source movement pretty much) but I need to compensate for the moveDirection in the targetHeight
Suppose you're trying to move at one billion meters per second
Would it make any sense to completely discard the Y component of your movement direction?
that's probably going to lose a lot of your speed...
The idea is the y component will never be used because the floating part of the movement handles that for you
No, it does not!
It might if you weren't projecting the movement vector
Because, in that case, you'd get your full speed on the X and Z axes
Then it would snap you down to the ground very quickly
Yeah that's what I want
Calculate how much extra Y velocity you need to correct your height and add that to the movement vector
Don't replace the Y component entirely
Right now, you're losing a significant chunk of your speed when moving on a slope
This is why I think it's a very bad idea to ever give an axis "special treatment"
Do not think of movement as an "XZ thing"
That's only valid when on perfectly flat ground
This isn't what I want though because I never want y velocity to be factored into stuff. It's a casual VR RPG so there should be no build-up in y velocity ever. You should only constantly snap to the ground or start falling if you're not close enough to snap. IIRC movement in VRChat is pretty similar to what I want
I'm not saying to cause Y velocity to "build up"
I'm saying to not completely ignore the Y component of your attempted movement
You are currently ignoring it.
This will make you go down slopes slowly.
I would expect your height offset to mostly correct for that
But, notably, when going up a slope, you'll be attempting to move into the floor
since you discarded the Y component of your movement vector
Oh wait I've been severely misunderstanding
How would you suggest I go around this? I just tried adding the projectDirection's Y onto the moveDirection's Y and I think that made it better but not quite perfect
Wait I think I know I'll try quickly
How can move a gameobject that have a rigibody kinemactic?
What is everyones opinion on writing your own finite state machines vs using an asset to help manage them?
You can still manipulate the rigidbody's position
It just won't get affected by physics
I infact did not know
I'm kind of..halfway in between? I use Animancer for animations, and it comes with a very basic state machine system
Show me your current code
I would see for animation it would be really complicated. Mine is a bit simpler, I'm just thining about possible ways to avoid it becoming a rats nest down the road.
Although, to be fair, I'm also not using it much like a traditional FSM
I explicitly request state changes instead of having rules that I regularly check
I'm just interested in running code when entering/exiting states and asking if I'm allowed to transition between two states
you could use Rigidbody.MovePosition https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Rigidbody.MovePosition.html
It's practically identical to what was in the pastebin because I haven't found a way to approach what you're saying
@heady iris That's an interesting thing way to go about it.
Yeah, it barely even works as a state machine anymore, haha
It's just...states
I do have a few "transitions" -- I try to enter the idle state every frame, for example
But it's mostly explicit
Thanks
I'm sorry but I genuinely don't get what you're asking for I cant just add to it (unless I'm just completely misunderstanding what you're asking for again) because I'd need to adapt the target variable to be a spring and even then it wouldn't fix my issue because it's still not account for the offset that moving up / down the slope would create
Also just to clarify we're both on the same page when it comes to the movement variable right? (I'm only trying to use projectedDirection to account for the movement not for the actual movement velocity itself)
That does nothing for me because relativeDirection.y is 0 everytime anyways
oh, you're not using projectedDirection now, I see
That is not correct, and it will slow you down when going uphill (unless the physics engine happens to push you out of the surface in exactly the right way
The capsule never makes contact with the surface because it's floating off the floor
Projecting your intended movement vector onto the slope will prevent this entirely.
https://github.com/dotnet-state-machine/stateless I've used this before, its quite good. But from experience, state machines never seem to be worth it for me, I find they end up making the code too much of a problem to handle and it would have been easier to just do things manually without a bunch of state logic
I don't know how you would completely avoid a finite state machine in circumstances where one is applicable
Vector3 rawMovement = CameraManager.Instance.GetMoveDirection(moveDirection); // compute how the player *wants* to move
Vector3 movement = Vector3.ProjectOnPlane(rawMovement, surfaceNormal); // reject the part that aligns with the surface normal
movement = movement.normalized * rawMovement.magnitude; // restore the original magnitude
movement *= moveSpeed;
// calculate the "target" value here
movement.y += target;
playerBody.linearVelocity = movement;
This is what I would do.
this library does look interesting htough
It works but projecting the movement onto the normal causes the slow movement and horizontal sensitivity and causes weird movement in general
Which is why I wanted to try account for the offset in this scenario
That's why this is included:
movement = movement.normalized * rawMovement.magnitude;
It restores the original magnitude of the movement vector.
I've just done that and it still feels off
Nevermind I'm tripping it actually is accurate
My only issue with it the weird horizontal movement feel still
I mean the overengineered idea of having the FSM handle very simple logic that could handled with a simple if condition
Say you had a player that can jump, but you cant jump when youre in water. You could have a state for OnGround that can move to InWater or IsJumping, but then you cant go from InWater to IsJumping. It's perfectly reasonable to do that, and I wouldnt say its wrong to do so.
At the same time, you could just have an if statement that only allows jumping when not in water without the need for an entire FSM implementation
the tradeoff is that it wont be as robust as a genuine FSM
lol I can't just write hmmm
I'll have to think on that, maybe I will go with something basic.
underengineering a solution vs overengineering
I hate writing something and getting like 80% through it, make a mess and then have to refactor it, but that sometimes is how things go
and I'm not sure if using chat-gpt is helping me or hindering me lol
yes, sorry again for not responding this long but i was doing something else again
That's fine, can you show your current !code and are you sure you are not modifying the velocity of the rigidbody directly whilst in the air? The addforce function should not just stop you in the air like you are modifying the RBs velocity directly
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.
k, wait a sec
i sent it to you on priv
please send it here so others can comment
https://paste.mod.gg/vxqqlrdtthxn/0
you can laugh
A tool for sharing your source code with the world!
this line would probably do it as you are doing a direct velocity change on the rigidbody
_rb.AddForce(AirTtoGrav.Evaluate(Airtime) * Vector3.down, ForceMode.VelocityChange);
you could probably change it to ForceMode.acceleration
it just makes the player super floaty and doesnt fix my issue
i just want to do something like in quake/TF2/portal where no matter if you hold the movement keys, when you gain enough velocity, it just makes you fly
I have never seen that done in the source engine, Are you talking about strafing? Does removing the AirTimeHandler fix the issue?
removing it just removes the dynamic gravity but i can try
well yes but we need to debug to find what is causing the issue, narrow it down to a function or line
i dont think that its a issue with something in my code but rather that there is something missing
i just want to give the player a little push of force when no input is given
a short representation on how i want this to be
well there is an issue with your code as you said when you are jumping if you stop doing input your player just stops in place, which is an undesired effect. So you need to debug to find what is causing that. You can cheat it but it may cause more issues later down the road.
Actually, I just tried your code out and your issue is not happening for me, I just changed the isgrounded code, the slope angle code and the cantjump function to get rid of the errors.
And got rid of some variables
yeah, i didnt finish the cantjump function when i sent it
what did you exactly change?(did you entirely delete it? lol)
I'll send the code, keep in mind it was a very quick edit
and please send the video of how this looks for you(send it on mediafire or google drive or anything + im not on my pc now)
seems to be working fine for me
I would have to test a bit more with the animation curves
sweet Idea with the animation curves though, I might have to use that ( as I have my own source engine/ quake 2 movement with strafing)
animation curves are great for whenever you need to remap a value
Why the bullet is disappear? The bullet have a rigibody kinemactic
The code :
public class bullet_space_ship : MonoBehaviour
{
public float speed;
Rigidbody2D rb2D;
void Start()
{
rb2D = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void FixedUpdate()
{
rb2D.MovePosition(transform.position + Vector3.right * Time.deltaTime * speed);
// transform.Translate(Vector2.right * speed * Time.deltaTime);
}
}
i imagine that there is some other code destroying it
does it disappear from your hierarchy too?
No, only not is rendering
are you using drag?
show the inspector of the object before and after it disappears
Rb drag is zero, sorry π
Wait, i discovery thing
and i have 3
without drag i see that it works just fine
(3 drag, 30 speed, 15 jump force, .8 air multiplier, anim curve from 0,0 to 1000,600)
so do i need to lower the speed and set drag to 0 or is there a better way to solve this?
you could probably set drag to 0 or 1 and lower speed to your liking, this is what happens what I set mine to 3 drag
you can see when I let go of input
and when I hold it
yes, this is what is happening to me
I would set drag to 0 or 1 (depending on if you need it or not) and lower speed a bit to compensate
but anyway, how does drag work? how can i calculate how much speed it drains by moving a rigidbody against a collider
Forget it, i resolve it
I would have to look into it more but as of now I do not know
Does anyone know why my SphereCast (the blue one) doesn't respond to the collider whenever my player is also touching it? I have it print "High" whenever it detects a collider on the ledge layer.
https://gyazo.com/1945aa7a8e7c8a7f2233daf4f7acab34
Spherecasts don't hit anything they start inside of
Consider combining it with an OverlapSphere call
well that's annoying, I can just change the collider to not extend forward and just be flush with the object.
Thanks!
You could also start the cast a bit further back
That's also a good idea
Cross-posting here because Iβm really not sure where it belongs
Hey guys. Before I go ahead with an idea that im having. I just want to know if its possible. Im looking at doing a doom clone with multiplayer. My question is how would I tackle the enemy sprite look at and sprite change between different players. Would I just locally render them? Would that be the best?
i would recommend asking in #archived-networking
is there a way to have individual objects to have their own time scales, or change their physics to emulate slowed down time?
sure, each object would have a script that tracks its local time scale . . .
what's with all the ellipses you're using lmao
as long as you don't use global timescale and track them locally
i may be stupid, cause i cant find anything online about local timescale
since time immemorial . . .
you have to create a custom script for it . . .
well thats something custom you track
just really seems like you hate being here lol
it's really offputting
oh . . . that. it has more than one meaning. people only know of, or think of, the negative one . . .
because only the negative one makes sense in this context
i never see it that way. more of a continuation of a thought
somebody gets it . . .
they aren't adding anything after it though
aren't i? 
like there's not really any continuation when you just leave it as the final message
not every thought needs to be written lol
and the unwritten thought just seems negative in that case
they could be pondering the issue further?
but it's not my final message, or else i'd never come back here, lol . . .
that doesn't make sense a lot of the time
the pondering/unwritten thought is the ellipses thmeselves . . .
maybe this is old people stuff π€·
perhaps. I did more often on Aol Aim and IIRC
never seen anyone so bothered by it 
https://www.youtube.com/watch?v=cgszcKU18ZY
maybe thisll help explain why it feels hostile to me
gen z making a big deal out of nothin
no it really does feel hostile lol
the extra ellipses without any thought after it seems disapproving
like you're hesitant to even say anything
language has soften up
as i've stated, it has more than one meaning. even the video demonstrates it's intended use (which doesn't point to a negative), though i'd do some self reflecting if it feels hostile in nature to you . . .
...yes, the video shows that the non-negative, intended use now violates the maxim of quantity, so it now feels unnatural.
these young'uns ruin everything, i tell ya . . . π
well, this just devolved into a generational quarrel.... i tried to show why it's hostile to me, but of course, your way is correct and im just willfully misinterpreting it...
languages evolve, and if you refuse to adapt with it, kinda reveals some stubbornness in your character...
you're fine. we are by no means serious. just having a laugh. this isn't anything i'd get upset about. i don't understand half the stuff people say today anyway. there's always a new word, meaning, or form of something every few months. it makes me i'm tired . . . π«
did you ever work this out?
is there a way to make VS22 use System.Collection.Generic by default when adding List variables, instead of using NUnit.Framework
minor thing but so annoying
nop lol
hmmm, i've never seen that happen before . . .
started happening after upgrading to unity6
from what ive researched it only applies to anything that is not related to rigidbody physics
which i kinda wanted to apply to physics
sorry, i wouldn't know about this one. i don't use VS and have not updated to Unity 6 . . .