#💻┃code-beginner

1 messages · Page 449 of 1

loud owl
rocky canyon
#

it can be savage in here somedays

subtle hound
#

who do i need to be scard of 😰

#

theres some devils lurking here? hahaha

summer stump
#

Mostly new users

loud owl
#

My keyboard and screen is abotu to be broken

#

its 5 in the morning

#

im still trying to learn ai

#

without knowing unity

rocky canyon
#

oof, not a good combo

loud owl
#

yea but atleast i made a flappy bird without using ai

rocky canyon
#
  • Step 1
loud owl
#

Its time for me to sleep ty for help @rocky canyon i'll read the article when i woke up

queen adder
#
  if(camPos.y < 0.0) Debug.Log("I am below the camera's view.");
  if(1.0 < camPos.y) Debug.Log("I am above the camera's view.");``` so the debug.log and is firing when the sqaure is already half way off the screen and I think this is due to the transform.position the position must be in the middle of the square for the log to be triggering half way any idea on how to fix ?
teal viper
queen adder
mint remnant
#

😦 tried to switch over to using a ObjectPool and after setting it all up first thing off the bat I get a stackoverflow exception

teal viper
queen adder
#

got it

queen adder
# teal viper Probably a recursion somewhere.

this worked SpriteRenderer renderer; renderer = GetComponent<SpriteRenderer>(); Vector3 topRight = renderer.transform.TransformPoint(renderer.sprite.bounds.max); float verticalInput = Input.GetAxis("Vertical"); transform.Translate(Vector3.up * verticalInput * _speed * Time.deltaTime); Vector2 camPos = cam.WorldToViewportPoint(topRight); if(camPos.y < 0.0) Debug.Log("I am below the camera's view."); if(1.0 < camPos.y) Debug.Log("I am above the camera's view.");

#

Ill just change it for the bottom one too

mint remnant
teal viper
#

Nor do I know the details of your pool implementation.

mint remnant
#

ok was about to paste the code, but I think I see the recursion now

devout flower
#

Is pooling one of those things that almost always boosts performance, just sometimes a negligible amount

teal viper
mint remnant
#

I'm trying it because in my case spawning up a new object was a heavy hit on memory each instantiation, a minecraft like chunk of blocks, so much data had to be new'd up for each

#

My basic ObjectPool setup

        chunkPool = new ObjectPool<GameObject>(
            () => { return Instantiate(chunkPrefab); }, // create
            (GameObject) => { GameObject.SetActive(true); }, // get
            (GameObject) => { GameObject.SetActive(false); }, // release
            (GameObject) => { Destroy(GameObject); }, // destroy
            false, // collection check
            10, // capacity
            50); // max capacity```
though I get no more errors now, it's not working right, so more reserach 🙂
devout flower
teal viper
# devout flower Yeah, basically

Well, if it's configured correctly, then there aren't cases like that.
If not configured correctly, your pool might be eating more memory than necessary.
Other than that, there are cases where the benefit is negligible.

devout flower
#

Got it 👍

summer stump
# devout flower Got it 👍

You are trading cpu time for memory allocation when you pool. Memory is almost always at less of a premium. Taking less time on the cpu is almost always good.

If that is not the case, there are probably other significant issues to be addressed

devout flower
#

Wait, do memory allocations get cleared during runtime at some point

#

Can someone direct me to an article about this stuff for unity

summer stump
summer stump
devout flower
#

Ah ok, garbage collector

toxic yacht
#

that or how it's decided to release objects back to the pool

mint remnant
#

this is going to be trickier than I thought, going to want to skip some steps in the startup code for a chunk, but some definately will need to occur since the data will be different per chunk. Mainly I wanted to stop the horrendos new calls each time

#

I guess I need to look into what SetActive(true) actually invokes, I blindly copied it from a video

toxic yacht
#

SetActive is the same as clicking the enable/disable toggle on a game object in the editor. It invokes OnDisable() and OnEnable(), and when a game object is disabled, none of its components or that object's children will run their update loops.

mint remnant
#

right now all my new up code and populate chunk is in Start(), guessing what I need to do is split that up and put the memory newing into a seperate method, and check if already newed up if so skip

worn stirrup
#

whats the issue?

mint remnant
#

missing a semicolon per the error and screenshot

#

and what is that line with public Rigidbody = rb; between hte class and it's brace...

worn stirrup
mint remnant
#

well you copied it wrong

teal viper
#

Might want to learn about the basic C# syntax so that you don't miss small things like that.

mint remnant
#

don't know why people want to learn 2 major things at once, C# and Unity both deserve their own time

toxic yacht
#

Usually I stick a Reset() method the class I'm pooling, and then call it in the Get wrapper for the pool:

public class ChunkManager
{
    private ObjectPool<Chunk> pool;
    
    public Chunk GetChunk(args)
    {
         var chunk = pool.Get();
         chunk.Reset(args);
         return chunk;
    }
}
worn stirrup
deep yew
#

I'm trying to spawn an object "missile" behind something which is put in an array.
How do you do that?

languid spire
eternal falconBOT
rich adder
#

also that instantiate makes no sense

languid spire
#

none of the code makes any sense

deep yew
deep yew
rich adder
languid spire
#

read the bot message if you expect help

rich adder
#

clearly not

#
  1. why are you using a specific number for vector3 and also why is not a variable, also its not written correctly hence the error
  2. why are you not using the clone/copy returned from instantiate to put it in array if that was the end goal
deep yew
#
  1. I tried to grab the position of the object that I wish to put it behind it but I've decided to do it manually.
  2. Huh?
rich adder
#

also you're passing a position as Object, the more i look at this the worse it gets tbh..

rich adder
#

anyway read the docs i sent how to properly write Instantiate

#

also don't post code as screenshots

deep yew
#

Alright, I'll re-read them

rich adder
#

btw the coroutine is also doing nothing right now and its not properly called

strong harness
#

Hey, I have clamped input values (middle mouse button for pan), but when reading and logging values, I see larger values!
ReadValue<Vector2>

eternal falconBOT
twilit iris
#

How do I ungroup object in unity? I tried making parralax effect but it seems like all my object still moving together even though the code tell them to move on different speed

strong harness
# burnt vapor Can't help without !code
 private void CheckMovement()
        {
            var value = _movementInputAction.ReadValue<Vector2>(); //here value is not clamped while it should be. I have added clamp in post processing section (new input system)
            foreach (var cam in _cameras)
            {
                var panSpeed = Mathf.Lerp(_panSpeedRange.Min, _panSpeedRange.Max, MathUtility.Remap01(_zoomRange, cam.GetZoom()));

                cam.transform.position += new Vector3(value.x, value.y, 0) * Time.unscaledDeltaTime * panSpeed;
            }
        }

It is called in Update

fickle plume
#

Don't animate parent object. Make all of them under another parent

#

@twilit iris ^^

strong harness
twilit iris
#
public class ParalaxScript : MonoBehaviour
{

    private float length, startpos;
    public GameObject cam;
    public float parralax;
    void Start()
    {
        startpos = transform.position.x;
        length = GetComponent<SpriteRenderer>().bounds.size.x;
    }

    void FixedUpdate()
    {
oat dist = (cam.transform.position.x * parralax);

        transform.position = new Vector3 (startpos + parralax, transform.position.y, transform.position.z);
}
}

     ```
#

its not even moving... im so confused

twilit iris
fickle plume
twilit iris
#

the children of it I just ctrl c and V to extend it

fickle plume
#

You'll get more control with single script. Put all panels into a single array and move them together. If one reaches outer bounds swap it to new position.

#

Note you can also have just one tiled large sprite and just animate material offset to move it back and forth

stone python
#

Recommend me a tutorial to learn unity?

fickle plume
eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

stone python
fickle plume
#

If you want to learn properly without wasting your time you should follow Pathways courses on that page.

ruby flower
#

I wanna make steam inventory items but i dont have a project yet and dont want to pay 100$ for it how can i test without buying yet

fickle plume
ruby flower
#

yeah but how can i know if it works

#

or do you mean the steam code

fickle plume
ruby flower
#

okay thanks 😄

silver girder
#

!code

eternal falconBOT
queen adder
#

yo guys any tutorials and documentations on how to code 3rd person camera without cinnemachine

teal viper
queen adder
#

i tried

#

only cinnemachine tutorials

teal viper
#

Are you sure you looked at all beyond the first search result?

#

I've just tried googling and there were several(as soon as the second search result) results not involving cinemachine.

#

That being said, I'd still recommend using cinemachine.

queen adder
#

Btw

#

i have so many public variables

#

but it only shows 2

#

which arent even ther

#

in my scrip

teal viper
# queen adder

It doesn't even look like it's the same script(all of the fields are different).
Do you have compile errors in the console?

opal zealot
#

Mainly plan to add a double jump, dash and run slates for the code.

queen adder
opal zealot
#

Ok

queen adder
#

see the errors

#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMain : MonoBehaviour
{
    public Transform player_core_transform;
}```
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerOBJ : MonoBehaviour
{
    public Transform playerCoreTransform; // Player's core transform
    public Vector3 positionOffset = new Vector3(0, 2, -5); // Camera position offset
    public float orbitRadius = 5.0f; // Radius of orbit
    public float rotationSpeed = 5.0f; // Speed of orbit rotation
    public float maxZRotation = 20.0f; // Maximum Z-axis rotation
    public float minZRotation = -20.0f; // Minimum Z-axis rotation

    private float currentRotationX = 0f; // Current X-axis rotation
    private float currentRotationZ = 0f; // Current Z-axis rotation

    void Start()
    {
        if (playerCoreTransform == null)
        {
            var player = FindObjectOfType<PlayerMain>();
            if (player != null)
            {
                playerCoreTransform = player.player_core_transform; // Ensure this matches your actual PlayerMain definition
            }
            else
            {
                Debug.LogError("PlayerMain script not found in the scene!");
            }
        }
    }

    void Update()
    {
        if (playerCoreTransform == null) return;

        // Get mouse inputs
        float mouseX = Input.GetAxis("Mouse X") * rotationSpeed;
        float mouseY = Input.GetAxis("Mouse Y") * rotationSpeed;

        // Rotate around the player based on mouse input
        currentRotationX += mouseX;
        currentRotationZ = Mathf.Clamp(currentRotationZ - mouseY, minZRotation, maxZRotation);

        // Calculate the new position and rotation
        Quaternion rotation = Quaternion.Euler(currentRotationZ, currentRotationX, 0);
        Vector3 offset = rotation * new Vector3(0, 0, -orbitRadius) + positionOffset;
        transform.position = playerCoreTransform.position + offset;

        // Look at the player
        transform.LookAt(playerCoreTransform.position + positionOffset);
    }
}```
#

oh wait

#

i fixed the issue

warm raptor
#

why I have that many issue and why does it give me errors when I put the ";" correctly?

Assets\_Script\Multiplayer\Client.cs(202,106): error CS1002: ; expected
worthy tundra
#

i have a problem.

blue is the player, red is the AI, orange is the AI's line of fire, green is the direction the AI should go.

whenever the player gets on a place that is higher than the place the AI stands on, the AI's line of fire can be blocked by whatever the player is standing on and thus can hit them.

i want it to find the position it should move to in order to be able to target the player, but i dont know how to do that

queen adder
#

I cant understand any docs, i tried, eveyr tutorial, on cinnemachine and stuff, i know the basics, but this math, quaternion and stuff is soo confusing, i can make basic games and 1st person camera, but 3rd person is out of my leuge cuz maths

woven crater
#

why inspector appear blank?

languid spire
#

I'm guessing IAttack is an interface and interfaces are not serializable

woven crater
#

well i thought serialize reference help that

teal viper
languid spire
teal viper
teal viper
# woven crater why inspector appear blank?

Probably because nothing is assigned. You need an actual instance of an actual type that implements the interface assigned(via code, since there's no way to assign it via the inspector by default)..

woven crater
#

awh

warm raptor
woven crater
woven crater
fathom timber
# worthy tundra i have a problem. blue is the player, red is the AI, orange is the AI's line of...

Hey, this is an interesting problem you are presenting. Unfortunately, there isn't an easy solution to this using Unity's navigation system.

I think your best bet is to have pre-placed visibility markers for your AI so they can have points where you know they can see the platform. The process would be:

  • Get the closest visibility marker to the npc.
  • Raycast the marker to the player.
  • If hit, navigate to that marker position on the navmesh. If not hit, get the next closest visibility marker and repeat.

This will require placing visibility markers which will add to your level design time. However, a dynamic solution without markers would be a lot more complicated. I had an idea for that and I can go over it if you want, but I think the marker solution is a lot better.

Hopefully that makes sense, let me know if you have questions.

worthy tundra
fathom timber
#

Okay, fair enough. lol

languid spire
worthy tundra
languid spire
#

!code

eternal falconBOT
opal zealot
#

Here's my movement code as of now: https://hastebin.com/share/wibitigice.csharp
Mainly focusing on these two:

void OnJump(InputValue value)```
For OnMovement I plan to add a minSpeed + maxSpeed, a Dash and a RunSpeed.
For OnJump, I plan to give it gravity, a grounded function and a DoubleJump.
How do I add in the ``GravitySettings`` and ``GroundSettings`` to   ``void OnJump(InputValue value)``?
languid spire
#

you have 2 nested classes so the first thing you need to do is create instances of them

#

because you dont have a varaible called body

ionic zephyr
#

Can I make a Canvas instantiate itself according to the players position?

opal zealot
#

Oh

#

What's with this?

languid spire
#

Exactly what it says

opal zealot
#

Should I worry?

languid spire
#

yes

opal zealot
#

Oh

#

Uh, how do I handle that?

languid spire
#

change your path names. paths should only contain A-Z and 0-9

opal zealot
#

Oh

#

Done.

opal zealot
# languid spire because you dont have a varaible called body

One example would be this:

        {
            Vector3 spherePosition = transform.position;
            spherePosition.y = transform.position.y + GroundSettings.SphereCastRadius - GroundSettings.SphereCastDistance;
            bool isGrounded = Physics.CheckSphere(spherePosition, GroundSettings.SphereCastRadius, GroundSettings.GroundLayers, QueryTriggerInteraction.Ignore);

            return isGrounded;
        }``` As the variable called body for isGrounded
languid spire
languid spire
tender wharf
#

so gamers, whats the best way to do racing ai? making a mario kart clone and just thinking about all of the drifting and turns makes me think of using a bunch of colliders to tell the ai what to do, but that is really cumbersome especially if i have a lot of maps

eager spindle
#

it would be more convenient if you built your track with a spline. have your cars follow the spline with an offset

#

to get very technical, mario kart rigs their races a lot such that

  • players who are first at the start of the race fall behind a lot
  • players in the middle of the race are given equal opportunity to catch up
  • last places tend to receive better boosts and racing AI becomes much more difficult
#

but I don't think you're thinking of that here. As long as you get the car to follow the spline it should be fine

tender wharf
#

i'm just thinking about having a basic racing ai that could potentially use the drift functionally so that i pass the class

#

Unity is really fun and easy but its so damn time consuming

tender wharf
#

especially when it comes to finding assets ;_;

#

but thanks for the valuable info gamer, I'll look into splines

eager spindle
#

nintendo rigs all their party games. mario party especially, theres a set of narratives that play out every game. including first place players getting screwed over at the last minute, last place players suddenly making comebacks

these are small things that make mario party and mario kart much more memorable than something that's just randomly generated, yet consumers dont know about

eternal falconBOT
#

:teacher: Unity Learn ↗

Over 750 hours of free live and on-demand learning content for all levels of experience!

raw robin
#

Hi all, Im running into a bit of an annoying logical issue hoping if someone can help:

I have a player with grid based movement. There is two item, Item A and Item B.

When player step on an Item, it picks it up, follows the player.

And when the player with an Item, steps onto Item B, it switches to holding onto item B.

Now I don't want the item to switch indefinitely (since both Item A and Item B are on the same tile as the player, and the colliders/triggers are activating in Update)

My solution is, once I dropped the Item, it will only be "pickup-able / turn on collider" after the player has moved 1 tile

The issue is, if I want to make the player to be able to "throw" the item in an direction, how should I handle the colider? As I want the item to stop if it hits any obstacle. I "need to" turn off the collider when I first throw the object because I don't want it to instantly pick it back up.

Question: Is the way Im handling the collision good? Have you seen a better way? Thanks

sleek gazelle
raw robin
#

hmm interesting, make sense, technically I can have two colliders and set them on different layers but on the same object

dense plume
#

Are these triggers or colliders?

#

If they're actual colliders, Physics.IgnoreCollision is what you want

#

Turn off the collision between the player and the item while it is being held, re-enable the collision after it is thrown. Make sense?

tender wharf
eager spindle
#

that works

#

though the car wont exactly follow the road smoothly

#

make sure the cars are offset from each other so they dont go to the exact same spot

#

when it comes to balancing also dont make every car take the tightest corner otherwise your players cant overtake them

primal trench
#

is there a way to mkae a variable show in the inspector but read-only?

rocky canyon
tawny bone
#

trying to make attack animations work for my school project, and the code didn't work but now I have this perpetual error and I have no idea what it means

rocky canyon
#

its a unity bug, clear it, ignore it, or restart the engine

tawny bone
ionic zephyr
#

Can I spawn a canvas according to the players position even if it is UI related?

#

for example I want to show the inventory next to the player

frosty hound
#

If it's a world space canvas, it has a world position. So yes.

#

If it's screenspace, then you can't move the canvas. You can however move the elements (for example, the inventory panel) and position it with code to be where you want relative to the player.

ionic zephyr
#

Ok, so I should make it a world space canvas then

#

thanks!

sweet sierra
#

ArgumentException: The Object you want to instantiate is null.
UnityEngine.Object.Instantiate[T] (T original) (at <f1e29a71158e46cdb750140a667aea01>:0)
SpawnCharacter.Start () (at Assets/Scripts/Character Scripts/SpawnCharacter.cs:13)

Getting this error when trying to spawn the character from CharacterManager even though I do have a default character prefab at Index(0) of the char manager

#

Am I doing something wrong here ?

keen dew
#

It's trying to instantiate whatever is in the Prefab field. Not sure why indexes would have anything to do with it?

sweet sierra
#

So, it should instantiate cat, but it's not

#

Heck... even the name of the current selected character is good but it's not spawning the prefab

rich adder
sweet sierra
rich adder
#

yes but where is it

#

show the field

sweet sierra
#

I have made it a property

rich adder
#

if its a property how did you add the Prefab to it

sweet sierra
#

This function does the job

#

It's on the same gameObject

#

By default, it loads character at index 0

keen dew
#

It's clearly trying to instantiate before it sets the property value since it prints the error before the name

rich adder
#

You must be running the previous method before this function runs

sweet sierra
#

But I have RequiredComponentEnabled 😬. Lemme try placing UpdateCharacter code in Awake(); and instantiation in Start(); of the other script

sweet sierra
rich adder
#

RequiredComponent just simply slaps the Component onto the object if its missing

sweet sierra
#

Now to fix the position and rotation of the character 😂. But at least it's working.

rich adder
#

it has nothing to do with order of methods

sweet sierra
#

So this is perfect that it waits until char manager is awake, then does this

rich adder
sweet sierra
#

I've read that but yk... kinda dum dum of me to assume that both of them should be in Start

rocky canyon
#

just a bit

rich adder
#

there is no guarantee which Start will run first unless you mess with Order of Execution

rocky canyon
#

Awake <-- Set up self
Start <-- Grab stuff from others

rich adder
#

I think it goes by the ID but not too positive

sweet sierra
sweet sierra
rich adder
rocky canyon
#

^ in here u can manually set orders

#

lower numbers run first

rich adder
#

yes, i use this as a true last resort to be honest

rocky canyon
#

same..

rich adder
#

I try not to use it, and work on a better design first

#

lots of Init() methods 😛

#

and events ofc

rocky canyon
#

this Realistic Vehicle P... whatever..

#

seems he wants his stuff to run ASAP (move over unity)

#

lol

sweet sierra
#

almost done with my game. only character selection giving me KIND of a hard time. It's a Basketball game for an internship lol

rich adder
#

wow a whole game for an intership, you're quite committed 😛

#

better be paid intership lol

sweet sierra
summer stump
rocky canyon
#

ya, your normally doing (1) thing..

#

art, audio, code, etc

sweet sierra
rich adder
#

ahh okay that makes sense

#

Jam for your Job

rocky canyon
#

finish a gamejam -> win an internship..

#

that the eziest test ever

rich adder
#

Jams4Jobs

sweet sierra
# rocky canyon art, audio, code, etc

We're 4 group members. 2 artists, 2 coders.

I've developed most of the physics, game logic, currency system, etc.
Another programmer does the UI and linking it to the code-behind.

But right now, setting the animations is a really big deal 💀

rocky canyon
#

Time to hack the NavMeshAgent and create a Rigidbody Agent 😈 wish me luck

sweet sierra
#

Even harder is gonna be making the character face the right way because the prefabs that the artist sent come with preset positions.

rich adder
#

animations are a pain

sweet sierra
#

Any idea on how I can change the predefined position in a prefab without tearing it apart. It has metarig, etc. in it

rocky canyon
#

if u mean the pose not really.

#

if u mean the orientation (can use an empty gameobject)

sweet sierra
rich adder
#

are they not T-Pose?

sweet sierra
rocky canyon
#

ya, just tuck the rig as a child..

sweet sierra
#

The pose is not an issue, I baked the poses so animations are working alright now.

solemn fractal
#

Hi friends.. Just starting with unity again after some months.. still getting grasp of things again.. my old game when I open the code i see colors on things.. but in the new game when I write the code everything looks same color.. how to fix that?

rocky canyon
#

!ide

eternal falconBOT
sweet sierra
rich adder
#

seems they are all facing Z / Forward which is quite normal as default

rocky canyon
#

simplest atleast

sweet sierra
#

Hmm.. so get a reference to the spawned child then rotate in script is best I should do?

rich adder
#

no no reference needed

rocky canyon
#

no..

#

just rotate the child (object) so its facing the parents Z direction

#

well the left direction

rich adder
#

right click the object, Create Empty parent rotate to the left.
Now rotate the child as desired to match parent

rocky canyon
#

w/e orientation u want lol

sweet sierra
#

Yes but the character spawns at runtime. And it's different for each character ig.

rich adder
#

you have to make a prefab, dont spawn in model directly

#

if they all have the same orientation you can keep the parent the same and just swap out the child accordingly

sweet sierra
#

omg yes. I still have a lot to learn 🤦. But yes I got it now

rocky canyon
#

you'd spawn the parent the root obj

#

the graphics will spawn b/c its a child

sweet sierra
#

Model to prefab, then fix orientation, then assign prefab to database. Will do the job

#

Thanks a lot y'all! Really appreciate it as a beginner 🥹🙌

late burrow
#

does interface holds value in itself

rich adder
#

what does that mean?

late burrow
#

can i write setter that sets itself and holds the value

rich adder
#

if you mean can it hold any values , no because they are simply just "contracts"

solemn fractal
#

hey guys..I just clicked on the scripts folder, create new, create C# script, gave the name and tried to drag to my 2d circle object and get that error.. the classname is the same as the file name.. what could it be the prob?

#

There are no compile error and the file name is the same as the class

rich adder
#

they just define contract for the implementing class/struct (methods, props, events)

#

values are provided by the classes or structs that implement the interface

rocky canyon
#

show us PlayerBullet.cs

solemn fractal
rich adder
rocky canyon
#

nope, no errors there

rich adder
#

I get that too sometimes when I create a new script on a gameobjec/prefab

#

unity just fucking up in this case

rocky canyon
solemn fractal
#

Ok thank you !!

rich adder
rocky canyon
solemn fractal
rocky canyon
#

is it selected as the external code editor in the settings?

rich adder
#

also yeah check if its External Tools

#

might need to Regen project files a couple of times

solemn fractal
#

Will check that, thank you!!

solemn fractal
rocky canyon
#

via hte package manager

solemn fractal
#

yeah been 6 months without using unity.. might be it

rich adder
#

yeah do you have Unity and DevKit extensions ?

rocky canyon
solemn fractal
#

I should have.. if I open the scripts from my old game I get no error just in this new one I created now

rocky canyon
#

its 2.0.22 now.. and they dont use the Code Editor one anymore

rich adder
#

also make sure to remove the Visual Studio Code Editor package just to avoid any weird hooking problem

rocky canyon
#

its deprecated

solemn fractal
#

I see, ok thank you

rocky canyon
#

one day, they'll make it all plug-n-play 😅

sweet sierra
#

Got the character to spawn perfectly in position. The only thing remaining is the character animation setup. What's the best way for this though?

because now my character is spawning at runtime so I don't think I can just assign like that, or can I?

rich adder
rich adder
#

you probably dont want root motion on do you

rich adder
solemn fractal
sweet sierra
# rich adder wdym best way ?

Nevermind. Lemme simply the question. if I assign the controller directly to the prefab, it won't arise issues for me right?

sweet sierra
rich adder
rocky canyon
sweet sierra
rocky canyon
#

mmhmm shoould work as is

rich adder
#

either way it would actually

sweet sierra
#

Can I ask just 1 more question for now? I might be sounding annoying but... this is the last step to completion lol

rich adder
sweet sierra
#

Alright so... I need to access the character but... the character is...

#

this far

#

So, I should assign the "Character" now? Right?

#

And then access the child through it

solemn fractal
sweet sierra
#

Ignore the question at this point 😭 answered it myself

rich adder
#

thats why the Type Mistmatch usually

sweet sierra
#

Obviously. In this case, I just wanted to access the animator

#

So, I got a reference to the "Character" (spawner), then used GetComponentInChildren<Animator>(); and got it to work

rocky canyon
#

make sure u cache those types of variables and re-use the cached versions

#

dont know ur code.. but jsut dont call GetComponent every frame for example

#

via Awake() or Start() but im sure u know that

sweet sierra
#

Me?

rocky canyon
#

yesh u

sweet sierra
#

Yes I do that in Start() or Awake() 😂

rocky canyon
#

some ppl go crazy w/ the getcomponents

#

putting them in update and stuff 🫣

sweet sierra
rocky canyon
#

ignorance

rich adder
#

You can also access it as a property from Character(if it has a script with animator referenced) and skip the get component completely 💪

sweet sierra
#

That's like:

"What's your name?"

"XYZ"

"Okay. What's your name?"

#

🤦💀

rocky canyon
#

lmfao!

rocky canyon
rich adder
#

to be fair I did that too in the beginning lmfao

slender nymph
# rocky canyon putting them in update and stuff 🫣

fun fact, but while caching the result of GetComponent is definitely advised, the actual GetComponent call is very fast so it isn't really worth worrying about all that much unless someone is really going overboard

rocky canyon
#

ohh cool! lol

#

🤫 i'll keep it a secret

slender nymph
rich adder
#

😮
I didn't know we had this
using Unity.PerformanceTesting;

#

nice results UnityChanThumbsUp

slender nymph
rich adder
#

new toys! sweet

rocky canyon
#

the more i learn unity the more i feel gaslit.. alot of the things i heard "NEVER DO THAT!" are more like.. "its okay if you do that a little bit"

#

it all started with, Camera.main

slender nymph
#

I mean, most things are okay in moderation. Like a single Find call in Awake? that's technically perfectly fine even though it's going to be slower than almost any other way to get a reference to another object. It's still better to teach people to do it the right way though

slender nymph
sweet sierra
#

Honestly, I spent 1 and a half month trying to learn unity back in Decemeber 2023. And even for a month in July 2023. And I hated it. I thought it was sooooo complex.

But now, in a month's time, I'm learning and enjoying it, never thought I would 🌝. Internship coming in handy ig

rocky canyon
#

ya, im not complaining by no-means..

#

i guess its better to know the most proper way

#

and ignore the techanically okay types

rocky canyon
sweet sierra
#

But again, I knew 0 coding in July 2023. And beginner coding in December 2023.

#

So I guess it plays a huge role too. Building blocks and then connecting them through logic.

#

Currently, I'm an intermediate or more C++ developer (2nd semester of Bachelor's just ended) but yeah... I wanna be a few steps ahead of my colleagues 😉

rocky canyon
#

humble 💪 flex

rocky canyon
#

would this be the cause for this API change?

#

only namespace im using is AI (Unity6) project

slender nymph
#

yeah, probably

rocky canyon
#

linearVelocity ftw

#

yup, that was it ☑️ , was gonna go old school w/ the rigidbody stuff

slender nymph
#

could always use some preprocessor directives if you want to maintain compatibility with older versions. or you could disable the warning for that line 🤷‍♂️
i'm fairly sure that velocity still works, it just internally uses linearVelocity

sweet sierra
#

Aren't VS and Rider the most preferred and optimized for Unity?

rocky canyon
sweet sierra
#

That's a relief to know. Because I actually researched on this (didn't wanna leave VSCode) and learned that it is possible to code Unity with extensions and stuff.

#

So I simply went for VS after that

rocky canyon
sweet sierra
#

That's nice to know 🫡

#

Question : I have an animation flow like this:

Idle state -> Hold state

When ball is thrown, repeat

#

But obviously using time to do this is unreliable. And Animation Events are being soooo tricky for the prefab. What do I do to get the same result as I am getting right now?

wintry quarry
#

not sure what you mean by animation events being tricky for a prefab.

surreal scroll
#

if i get a script component from a prefab that contains a bool can i use it in another script?

wintry quarry
surreal scroll
#

in the second script i used GetComponent but i can't seem to use the bool

#

from the first script

wintry quarry
#

i can't seem to use the bool
This is very vague

#

Show your code and any full error messages you're getting.

surreal scroll
#

i'm not getting an error but i'm having trouble with the reference

wintry quarry
#

If you want help you're going to have to show detaiuls of what you're trying and what's going wrong

#

if you're not getting errors you'll have to explain what you mean by "trouble"

surreal scroll
#

can i just copu and paste

wintry quarry
#

!code

eternal falconBOT
rich adder
#

read the bot message
its backtics you can copy it
(though ideally entire class would be best in a link)

surreal scroll
#
using System.Collections.Generic;
using UnityEngine;

public class ScoreScript : MonoBehaviour
{
    public LogicScript logic;
    public PlayerScript player;
    // Start is called before the first frame update
    void Start()
    {
        logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<LogicScript>();
        player = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerScript>();
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        logic.AddScore();
    }
}```
wintry quarry
sweet sierra
# wintry quarry Animation events or StateMachineBehaviours are the way to go

Yes I added an event but you could guide me on this please?

So basically, the event controller is on my character.

But I need different scripts (one on ball and one on balls spawner) to call the animations. And event demands a function from the scripts attached to the same gameObject. So, how exactly can I achieve this?

surreal scroll
#

thank you very much i'm sorry

wintry quarry
#

Have that function call a function elsewhere, however you need.

surreal scroll
wintry quarry
surreal scroll
#

i can't use the bool in ScoreScript

wintry quarry
#

Why not

#

what happens when you try

surreal scroll
#

i don't know

wintry quarry
#

what did you try

#

YOu don't know what happens?

#

Something is happening that made you come here

#
  1. You tried something
  2. Something bad happened
  3. You came here
surreal scroll
#

nothing is happening that's the problem

wintry quarry
#

Tell us about 1 and 2

surreal scroll
#

i'm very new to programming

sweet sierra
rich adder
#

start with that

surreal scroll
#

i don't have any errors

wintry quarry
rich adder
#

check the code/ function is even running

#

put Debug.Log inside methods, start debugging

surreal scroll
#

o tried to put if (PlayerScript.IsAlive == true) AddScore();

wintry quarry
#

this is the 1.

#

the thing you tried

surreal scroll
#

yes

wintry quarry
#

So this is wrong because you used the class name instead of your actual reference variable

#

you need to use your reference variable

#
if (player.IsAlive) AddScore();```
rich adder
surreal scroll
#

i was being hasty my bad

#

if (PlayerScript.IsAlive == true) { logic.AddScore(); }

#

that's what i meant to send

#

i'm very

#

sorry

wintry quarry
surreal scroll
#

OH THANK YOU SO MUCH

wintry quarry
#

And what you have would still give you errors

#

so when you said you had no errors... that wasn't helpful

surreal scroll
#

i'm stupid

rich adder
#

yeah you probably weren't looking at correct spot

surreal scroll
#

i forgot i removed the code when it didn't work

rich adder
#

or your IDE is not underlining you have a bigger issue (don't code without configured IDE)

surreal scroll
#

sorry

#

thank you very much tho

#

i have one more question

rich adder
surreal scroll
#

i don't understand

#

do you mean the red line

rich adder
#

the underline red ?

#

yes

surreal scroll
#

yes it was there

rich adder
#

oh ok well, you saying no errors was misleading lol

#

moving on.. whats your new question?

surreal scroll
#

i forgot i removed the faulty code

#

i added a tag to a prefab that makes it so when you touch it you die but the copies of the prefab don't have it

rich adder
#

make sure you applied the new changes to all the prefabs

surreal scroll
#

ok i'll check thank you

rich adder
#

if you drag a prefab inside the hirerchy it becomes an Instance, anything changed there wont affect other prefabs unless you apply the "overrides"

surreal scroll
#

thank you so much it works

#

now my game is complete 😎

#

after i dragged the new prefab into the spawner it always stops after spawning two prefabs

#

even tho i set the function to spawn a new prefab into void update

#

maybe this has to do with the fact they all have the same tag?

rich adder
surreal scroll
#
using System.Collections.Generic;
using UnityEditor.Experimental.GraphView;
using UnityEngine;

public class TowerSpawningScript : MonoBehaviour
   
{
    public GameObject tower;
    private float time = 0;
    public int delay = 3;
    public float DistanceOffset = 10;
    // Start is called before the first frame update
    void Start()
    {
        SpawnPipe();
    }

    // Update is called once per frame
    void Update()
    {
        if (time < delay)
        {
            time += Time.deltaTime;
        }
        else {
            time = 0;
            SpawnPipe();
             }
        
        
    }
    void SpawnPipe()
    {
        float LeftMost = transform.position.x - DistanceOffset;
        float Rightmost = transform.position.x + DistanceOffset;

        Instantiate(tower, new Vector3(Random.Range(LeftMost,Rightmost),transform.position.y,0),transform.rotation);

    }
}```
#

i don't have any errors i double checked and i didn't change any code after it was working

#

no code that has to do with the spawning at least

wintry quarry
primal trench
#

this is a extremely dumb question but
private void blahblahblah : blah
^^
what's that bit called? if forgot:(

wintry quarry
#

My guess is you are not using a prefab, but rather an object in the scene, and once it gets destroyed your Instantiate code no longer works. When this happens an error will go in the console

rocky canyon
#

& are you spawning a prefab.. or a copy of something in the scene?

wintry quarry
rocky canyon
#

once it gets destroyed (off the side of hte screen) or w/e it doesn't have a reference to anything ot copy anymore

rich adder
#

have a feeling they dragged in the prefab from the hierarchy

wintry quarry
surreal scroll
#

yes

primal trench
wintry quarry
#

The part after a function name doesn't use :

primal trench
#

like
function : monobehavior

rich adder
wintry quarry
#

no

wintry quarry
primal trench
#

class sorry

wintry quarry
#

you're confusing functions with classes

primal trench
#

class : monobehavior
what's the second part called

raw token
# primal trench class sorry

It's a just a type - a class which blahblahblah is extending, or an interface which blahblahblah is implementing

wintry quarry
#

You can also put interfaces you implement there

rocky canyon
rich adder
rocky canyon
#

these are not

surreal scroll
#

where do you find the project folder i mean

rocky canyon
#

Windows > General

#

how did u make a prefab w/o knowing where the project window is?

surreal scroll
#

i dragged an asset to the hierarchy then i added some children

#

and then i dragged it back into the assets i think

#

and it created a prefab

rocky canyon
#

where do u think ur dragging assets from?

surreal scroll
#

idk

#

the bottom

rich adder
#

"the bottom"

surreal scroll
#

oh i understand

rich adder
#

those tabs have labels

rocky canyon
#

oh u mean the PROJECT folder

surreal scroll
#

my bad

rocky canyon
#

no worries..

#

just trying to drive it into ur memory 😄

rich adder
surreal scroll
#

why is there a problem if i drag it in from the hierarchy but not if it's from the project folder

rocky canyon
#

b/c thats not techanically a prefab..

#

its a Instance of the prefab..

rich adder
rocky canyon
#

^ its a copy

rich adder
#

a copy

rocky canyon
#

ur copying a copy

surreal scroll
#

ok thanks

#

it still doesn't work

rocky canyon
#

but what was happening was.. the copy of the pipes u slotted into the slot.. got destroyed..

#

and then the script couldnt spawn it anymore

#

prefabs from within the project folder dont get destroyed.. (jsut their copies do)

rich adder
surreal scroll
#

it doesn't stop spawning but the tag isn't getting copied

rocky canyon
#

b/c u changed the tag on the COPY

#

not the actual prefab

#

same problem

surreal scroll
#

OHH

rocky canyon
#

double click the real prefab

#

and change that

rich adder
#

thats why i told you to apply the tag in the Overrides

surreal scroll
#

maybe i should think more

rich adder
#

or just click the link I sent..

#

actually learn how Unity engine itself works

surreal scroll
#

ok

#

thank you guys very much for the help

rocky canyon
#

crash course

#

Tank -> drag in scene -> now its an instance (if i modify THAT instance) it doesn't matter..
BUT if i APPLY the overloads (now the prefab matches the version i changed)

#

you can also just double click the prefab.. and it opens in (prefab view)

surreal scroll
#

i changed the prefab itself this time by clicking it in the project folder and the selecting the tag

rocky canyon
#

that will change all versions (even the ones u already have in the scene)

surreal scroll
#

i'll keep all this in mind next time

frosty wren
#

Any recommendations on an easy to use asset to build out game settings? I need something to read and change settings such a resolution, turning shadows on/off, texture resolution etc. I can do the UI for it, and even saving/loading from a file.

raw token
#

If you're willing to do the UI and I/O, you're already tackling the majority of the work :P

primal trench
#

should i upgrade c# from 9 to 12? i tried to do some array stuff but it said it isn't avaibled in 9

slender nymph
#

doing so would require you messing with roslyn and it isn't generally advised because it isn't something that is actually supported by unity

#

i'm guessing you tried to use the new collection expression syntax, but you should just use the older collection initializer syntax

primal trench
slender nymph
#

yes that is the new collection expression syntax

primal trench
#

what's the old?

frosty wren
frosty wren
slender nymph
#

each of those options usually only takes one or two lines of code to change

eternal needle
frosty wren
#

Thanks, will give it a try. Just thought there would be some well polished tools out there for something every game probably needs

slender nymph
#

there are plenty of assets on the asset store that have settings menus built in, you could search for those. but if you want to build the UI yourself, then it's literally just a matter of reading the documentation to find out what line of code you need to run for each setting change

somber osprey
#

Hi, I'm working on a turn-based strategy game and I am working on a system where the player can bring a battle into focus (they will click on a button and the battle will open in a less interrupted window). For now what I've been doing was that I just disabled all the other tiles that weren't a part of the battle and spawned a fog of war. This was pretty performance heavy (a 1-2 second load in debug). I want to transition to a system where I would load a scene and the battle would only happen in that specific scene (and data would be shared through scriptable objects) and then when the player closes the battle, the original scene would be loaded back in. Imagine a 4X game like civ, scene loading is pretty heavy unless the scene would remain in memory, is this possible?

rocky canyon
#

additive scene loading sounds like something that might help

#

keep the main scene loaded in memory.. and add/remove the battle scene as needed

toxic frigate
#

hello all, how come these values arent assigned? the second screenshot was taken in game

slender nymph
#
  1. !code 👇
  2. have you confirmed that code is actually running?
  3. if yes, are you certain you are looking at the correct object and that you have no exceptions in the console?
eternal falconBOT
toxic frigate
#
void Start()
    {
        FindClosestShip();
        radarScanner = GetComponent<RadarScanner>();
        shipMovementController = GetComponent<ShipMovementController>();
        if (shipMovementController == null)
        {
            airship = GetComponent<airship>();
        }
        teamController = GetComponent<TeamController>();
        masterGunController = GetComponent<MasterGunController>();
        ChooseDestination();

        shipMovementController.isEnabled = true;
        shipMovementController.hasMoveOrder = true;
    }
somber osprey
toxic frigate
#

ah okay

rocky canyon
#

just copy them str8 from the embed

frank flare
#

How do I fix these errors?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GrabItems : MonoBehaviour
{
    GameObject Cam = gameObject;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    void FixedUpdate()
    {
        var ray = Cam.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out var hit)) {
            var objectPos = hit.collider.transform.position;
            Debug.Log(ray);
            Debug.Log(objectPos);
        }
    }
}
rocky canyon
#

var ray = Cam.main.ScreenPointToRay(Input.mousePosition); this can become
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);

#

Camera.main just grabs the Camera thats tagged as MainCamera

rich adder
slender nymph
eternal falconBOT
toxic frigate
slender nymph
#

then have you confirmed you are actually looking at the correct object

rocky canyon
#
public class GrabItems : MonoBehaviour
{
    void FixedUpdate()
    {
        var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out var hit)) {
            var objectPos = hit.collider.transform.position;
            Debug.Log(ray);
            Debug.Log(objectPos);
        }
    }
}``` @frank flare but get ur IDE configured as well
frank flare
toxic frigate
#
void Start()
    {
        Debug.Log("ai controls started");
        FindClosestShip();
        radarScanner = GetComponent<RadarScanner>();
        shipMovementController = GetComponent<ShipMovementController>();
        if (shipMovementController == null)
        {
            airship = GetComponent<airship>();
        }
        teamController = GetComponent<TeamController>();
        masterGunController = GetComponent<MasterGunController>();
        ChooseDestination();

        shipMovementController.isEnabled = true;
        shipMovementController.hasMoveOrder = true;
    }
slender nymph
slender nymph
toxic frigate
#

i looked through these errors already

slender nymph
#

if you have absolutely confirmed that none of the many errors you are receiving are in the callstack for this code, then you are likely just looking at the wrong object

#

but also, fix your errors.

toxic frigate
#

im fairly certain im looking at the right object

slender nymph
#

"fairly certain" is not "100% certain because you've verified"

toxic frigate
#

ive shift selected all of the objects which have that script and it still looks like this

slender nymph
#

change the log from Start to this: Debug.Log($"{GetType().Name}.Start has been called on {name} ({GetInstanceID()})", this); and show what it prints, then also click the log to see what it highlights and show the inspector for that object

toxic frigate
#

roger

slender nymph
#

there is clearly something you aren't showing then. share the entire class using a bin site

rocky canyon
#

ty

slender nymph
toxic frigate
#

certain, but let me double check again

slender nymph
#

while you check, move that log to the end of the Start method too instead of the beginning

toxic frigate
#

nothing is modifying those fields, i had just changed those to public anyways since i wanted to see if the values were assigned or not

slender nymph
#

you can serialize a field using the [SerializeField] attribute if you want a non-public field to appear in the inspector

#

but now that you've moved the log to the end of the Start method, is it still printing?

slender nymph
toxic frigate
#

oof

slender nymph
#

so instead of ignoring your errors you should actually fix them

frank flare
#

why is visual studio code visual studio code setup tutorial telling about visual studio plugin while there's visual studio code plugin in front of it?

#

every day is problems with computer...

slender nymph
rich adder
slender nymph
#

you can also read the convenient text right below the image which you've conveniently cropped from the screenshot

frank flare
#

I clicked unlock button this should work right?

#

ok

rich adder
#

so you dont accidentally select the wrong VSC version in External Tools

frank flare
#

why is visual studio editor getting un unlocked when I'm closing the menu?

finite pelican
#

Hey guys I am not sure if this is the right place to ask but I want to make a AR game using Unity and Vuforia, every tutorial or documents that I read state that I need to check Vuforia in the XR settings. But I don't have that option at all but I have the Vuforia Engine in the Hierarchy.

rich adder
rich adder
#

how can we help

warm raptor
#

Hi! I've just made a grenade throwing animation and I wanted to know, how can I make the grenade instantiate as a child of the hand bone and then make it stop being a child and get speed?

rich adder
frank flare
rich adder
frank flare
#

unremovable

rich adder
# frank flare unremovable

its part of engineering package thats why . You can remove that first then Install Visual Studio Editor if it removes it

warm raptor
frank flare
rich adder
frank flare
#

was there anything important in engineering thing?

rich adder
frank flare
#

so if I don't know it I shouldn't use it

#

ok

rich adder
#

its just something that unity preinstalls

#

you dont need everything in it as essential

#

just Visual Studio Editor package will do

frank flare
#

why does referencing gameObject not work?

ripe shard
rich adder
slender nymph
frank flare
rich adder
#

gameObject is already short enough to get from the Component you're on , assigning a variable to it is double the work

frank flare
#

why is main doing issues?

rich adder
#

you probably are looking for the Camera component not Gameobject

frank flare
#

they're different?

rich adder
#

very different

#

Camera is a component, GameObject contains components basically

#

you can do Camera.main since its static

#

or if you're super micro optimizing or have no Camera with a Main Camera label, you can just do
[SerializeField] private Camera cam

#

then link that and use cam.ScreenToWhatever

#

not necessary though as Camera.main already has its own opimizations (so i've heard)

frank flare
#

idk what serializefield does

rich adder
#

just makes a private field serialized in the inspector

#

like when you do public it shows up in the inpsector

#

you can also do
private Camera cam
Awake()
cam = Camera.main
all unnecessary, just showing you there is options

frank flare
tiny plaza
#

I can't find the number that changes the animation speed

rich adder
#

declaring != assigning

rich adder
frank flare
#

I guess I don't need to know it for now

rich adder
#

nah. ur fine with Camera.main

#

just make sure you have a camera with "Main Camera" tag for it to work

inner quartz
#

What am I doing wrong?..

rich adder
slender nymph
rich adder
frank flare
inner quartz
slender nymph
#

wdym "download"? this doesn't "download" anything, in fact it doesn't do anything at all, which is the point of the error

#

this is like if you just wrote a line that was 3; that line doesn't do anything. it's just the number 3 on its own

rich adder
#

go up to someone and just say "Apples"
it makes no sense lol
"what about apples? what do you want to do with apples"

inner quartz
slender nymph
#

then describe what exactly you are trying to achieve

#

i cannot read your mind, so i have no way of knowing what you are actually trying to do with this statement

inner quartz
slender nymph
#

there is no function being invoked here

rich adder
#

how should we know that lol

#

you're the one who copied this from *somewhere *

inner quartz
rich adder
#

maybe start by showing us that

inner quartz
#

I need to load the next audio track so that it does not load for a few more seconds after the end of the previous audio track

rich adder
#

what does "download the next audio track" have to do with this

slender nymph
inner quartz
slender nymph
#

hint: the answer is absolutely nothing. just like accessing a variable without using it in any way or assigning it to anything does literally nothing at all

rich adder
#

does not load for a few more seconds after the end of the previous audio track

#

so like a timer before next track ?

inner quartz
rich adder
#

Im confused

slender nymph
# inner quartz

this doesn't make anything clearer. what are you actually trying to do with the variable you have accessed on that line with the error

sleek gazelle
#
chassisRenderer.materials[0].color = new Color(1,(data.primaryColor%16777216)/(65536*255),(data.primaryColor%65536)/(256*255),(data.primaryColor%256)/(255));
Debug.Log((data.primaryColor%16777216)/(65536*255));
Debug.Log((data.primaryColor%65536)/(256*255));
Debug.Log((data.primaryColor%256)/(255));

I have this piece of code, the debugs are 1,0,0 so the material should be red, but for some reasons it appear yellow, can someone help me?

slender nymph
#

you are doing integer division

sleek gazelle
#

mb, it's RGBA not ARGB

inner quartz
slender nymph
#

wtf do you mean by "download" in this context? because that is surely not the correct term

inner quartz
#

any sound must be loaded before it can be played

slender nymph
#

at this point i give up attempting to help you. you are not making your actual intentions clear and i don't feel like asking repeating questions for the next half hour

frank flare
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GrabItems : MonoBehaviour
{
    Camera cam;

    void Awake()
    {
        cam = Camera.main;
    }

    void FixedUpdate()
    {
        var ray = cam.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(ray, out var hit)) {
            var Object = hit.collider.transform;
            Debug.Log(ray);
            Debug.Log(Object);
        }
    }
}

how can I make

var ray = cam.ScreenPointToRay(Input.mousePosition);

always be center of the screen?

slender nymph
#

at that point you don't need to be using ScreenPointToRay at all, just raycast from the camera's position in its forward direction

frank flare
#

like it has Input.mousePosition

slender nymph
#

look at the documentation for Physics.Raycast

rich adder
slender nymph
#

then in the origin and direction you put the camera's position and forward

rich adder
#

^ camera.transform.forward

rich adder
inner quartz
frank flare
rich adder
inner quartz
uncut leaf
#

y is the coner tile not auto tiling correctly when i have it setup in the auto tiler

late burrow
#

if there specific kind of loop that takes lots of code and i want to use it many times is there some kind of function to shortcut it

worthy merlin
#

I feel like this is an obvious yes, but I don't want to go insane. It shouldn't matter where I put my start and end rooms on a maze generated with a Recursive back tracker right? There should always be one path connecting both?

rich adder
#

maybe think it over a bit , and try to come up something a bit more easy to explain to someone else what you want

#

if you cannot explain it, you wont be able to solve it

inner quartz
#

in my other game, I just can't load the AudioClip I need because I'm constantly changing them..

rich adder
#

I have not experimented with audio that deep but looks promising

rich adder
inner quartz
rich adder
#

I'm not sure then :\ sory

inner quartz
#

no

#

this

late burrow
inner quartz
late burrow
#

i want bind loop into function/interface/whatever thats already preparing it to use

rich adder
slender nymph
rich adder
late burrow
slender nymph
#

what the fuck do you mean by "20 lines of preparation"

rich adder
#

loops are like 3 lines what does that mean lmao

raw token
#
for (int i = 0; i < total; i++) {

one line prep!

late burrow
#

not when i put loop inside loop inside loop

#

and toss variables around

#

i want to shortcut it

slender nymph
rich adder
#

can you give like a real life scenario or like your current scenario so I know wtf you're talking about

late burrow
#

though when i think of that i probably could do custom class where i already did that loop beforehand toss all variables there and then foreach it in every function i need

slender nymph
#

or just write a method that does what you need and call the method while passing whatever data you need into it. but until you provide a real example of what you are trying to solve all anyone could possibly provide is speculation at best

late burrow
#

ok so for example

#

car has multiple of parts which each can hold multiple modules

#

and i want to add same variable to all of the modules at once

#

while skipping the looping part

frosty hound
#

Use an event

warm raptor
#

why, depending on where I'm looking, the grenade never goes off in the same way ?

public void ThrowGrenade()
    {
        GrenadeInstance.transform.SetParent(null);
        Rigidbody rb = GrenadeInstance.GetComponent<Rigidbody>();
        if (rb != null)
        {
            rb.isKinematic = false;

            Vector3 localForward = RightHand.forward;
            Vector3 localRight = RightHand.right;

            Quaternion throwRotation = Quaternion.Euler(throwAngles);
            Vector3 throwDirection = throwRotation * localForward;
            rb.AddForce(throwDirection * ThrowPower, ForceMode.VelocityChange);
        }
        
    }
#

also if I remove throwRotation the grenade it's not going straight but at least it always go in the same direction

rich adder
#

could also be the wrong directon/rotation.
Debug them Gizmos class will be your best friend

warm raptor
rich adder
#

so assume you're calculating direction/rotations wrong

long jacinth
#

how do i change his hands pivot location

warm raptor
rich adder
#

the sprite editor lets you edit the pivots, otherwise use a sperate gameobject parent

eternal needle
long jacinth
eternal needle
# warm raptor why ?

because you want it to throw based on the direction the player is looking + some offset. syncing it up to throw with the hands local directions is just gonna be more of a pain, although i dont see anything super wrong with the current code. Maybe throwAngles is wrong or this code is playing at different points in the animation causing it to read different values

#

try to visualize even with Debug.DrawRay to see what these directions are

warm raptor
rich adder
warm raptor
#

I just have a last question, how can I add a collider to my grenade without it interfering with my player's colliders? do i have do disable the collider of the grenade as long as the player holds it ?

long jacinth
#

im making a 2.5d game in unity any tips?

warm raptor
long jacinth
long jacinth
rich adder
#

did you switch it from Center to Pivot, what does it look like now

warm raptor
rich adder
#

just to see where the pivot actually was

long jacinth
rich adder
#

wat

long jacinth
#

where do i view pivot

rich adder
#

Screenshot the Scene

long jacinth
rich adder
#

you cutoff most of the editor

#

dont crop

long jacinth
rich adder
#

see how it says "Center"

eternal needle
rich adder
#

click it, and switch it to Pivot

long jacinth
#

oh i see now

#

it now works i think

rich adder
#

if its still wrong, after that use the Sprite Editor to edit the pivot

long jacinth
long jacinth
silk fossil
#

I am making an enimy trying to just follow me, but it just falls straight through the ground

warm raptor
rich adder
#

we only know the problem for now, not the cause

silk fossil
#

ok

long jacinth
warm raptor
long jacinth
#

its a pixel game so im kindof good with blockbench

rich adder
warm raptor
rich adder
#

if anything finding similar 2D assets is harder than cohesive 3D

warm raptor
rich adder
#

depends on the game you can also use depth

raw token
#

I always equate it with "Isometric," which may or may not be accurate. But isometric games often incorporate height

Edit: further research says this is not accurate 😁

pulsar forum
#

Like... the camera is not axis aligned to your 2D viewindow?

rich adder
#

mostly its having sprites in a 3D world

#

billboarding and such

#

but yeah if it moves like 2D (eg side scroller ) helps sell the "feel"

long jacinth
pulsar forum
#

Like paper mario?

rich adder
#

yes

#

or zelda remake

#

actually thats all 3D models iirc

#

its just that view thats 2Dish so doesn't count ig
but yeah paper mario is the best example of 2.5d

warm raptor
fringe plover
#

My friend says that this is right way of making values..
And its right to place [SerealizeField] in public values.. is it so or he's just dumb?

rich adder
#

Hence the 3 dots on it suggestions from VS

#

if these are not accessed else where make them [SerializeField] private

#

thats what its fore

fringe plover
#

ok

#

thanks

rocky canyon
long jacinth
rich adder
#

language barrier?

rocky canyon
#

more like zero modelling experience.. no need to even open a 3d program to do sprites in 3d / 2.5d billboarding

rocky canyon
rocky canyon
#

tree's in the background for example

rich adder
long jacinth
long jacinth
rocky canyon
#

hell ya, trying for that cease and desist achievement ⭐

long jacinth
#

actually all of baldis enviroment is strange

rich adder
#

You have unlocked LAWSUIT

rocky canyon
#

just kidden, as long as u dont redestribute it outside ur friend circle u should be ok

rich adder
#

currently owned by Paramount Global

#

you dont wanna fux with that

rich adder
#

movie companies are ruthless

rocky canyon
long jacinth
#

i will call him gaafar and change a bit of his looks and he is an arab cat with an atayef addiction

rich adder
rocky canyon
long jacinth
rich adder
#

as long as you're not selling it should be ok (not legal advice)

long jacinth
#

thanks for the advice guys

rocky canyon
rocky canyon
jagged vapor
#

i have a cylinder and cube one on top of another. Both are instanciated prefabs. if i click on the cilinder it says its pos is 4,0,4. If i click on the cube it says its -540,0,4. yet both have the same size? How is this possible?

rocky canyon
#

are they children of anything?

jagged vapor
#

but they are one on top of another

raw token
jagged vapor
primal trench
#

hey! i have a canvas which is a prefab which is a worldspace canvas, but the buttons don't work and none of the keys i press trigger the coresponding stuf, any idea why?

rich adder
#

everything else is just throwing darts at a board

raw token
#

Do you have an EventSystem in your scene? 🎯

primal trench
primal trench
rich adder
#

so you are trying to interact with world canvas how exactly? fpv or wat

primal trench
primal trench
#

that checks if "W" is down

#

and if it is

#

change a variable

#

but w isn't triggering

rich adder
#

how did you check the code is running ?

primal trench
#

it works when not a worldspace, only breaks when it is worldspace

rich adder
#

are you using a FPV controller ?

primal trench
rich adder
#

first person view

#

also what does "w" have to do with world canvas

primal trench
#

like clicking "w"

primal trench
rich adder
#

thats probably why

#

your cursor is locked and not visible most likely

#

world canvas doesn't like that

primal trench
rich adder
#

replace the one on the Event System

primal trench
#

sorry

rich adder
# primal trench wdym?

do you have an event system object in your setup? if so can you screenshot the gameobject

primal trench
rich adder
#

thats the old input module or new?

#

normally is called "StandaloneInputModule" iirc

primal trench
#

new

rich adder
#

use that method instead then

#

hopefully that works, I havent tried new input system yet with this

raw token
#

Where does GetComponent()'s overhead come from?

Is it just managed/unmanaged interop shtuff? Outside of that, all I can conceive the components collection to be is just something like a type-keyed dictionary, and lookups there should be cheap, no? 🤔

teal viper
#

Also GetComponent is not that slow.

rich adder
#

yes TIL GetComponent is quite fast

mint remnant
#

was watching a performance test video and several things people think are better turned out to be slower, example FindBy Tag() was fast

raw token
balmy steeple
#
public class PartBase : MonoBehaviour
{
    public float maxHealth = 100;
    public bool interactable = false;
    private Vector3 originalPosition;
    private Rigidbody originalConnectedRb;
    private FixedJoint joint;
    private bool wasActivatedBefore;
    private Rigidbody rb;
    protected float health;
    protected bool isActive = false;
    
    void Start()
    {
        rb = GetComponent<Rigidbody>();
        TryGetComponent<FixedJoint>(out joint);
        Reset();
    }

    public void Activate(){
        isActive = true;
        rb.isKinematic = false;
        originalPosition = transform.localPosition;
        if (joint) originalConnectedRb = joint.connectedBody;
        wasActivatedBefore = true;
    }

    public void Reset(){
        isActive = false;
        rb.isKinematic = true;
        if (wasActivatedBefore){
            transform.localPosition = originalPosition;
            if (joint) joint.connectedBody = originalConnectedRb;
            health = maxHealth;
        }
    }

    public void DealDamage(float damage){
        health -= damage;
    }
}```
there is a rigidbody yet it says the `rb.isKinematic = true` line throws a null exception
raw token
balmy steeple
#

yes

#

a thing calls a thing that calls reset

#

oh no

#

they all call each other in start

#

is that it?

raw token
# balmy steeple is that it?

Quite possibly.

A common practice to have a script initialize itself in Awake() (cache references to it's own components and such), and anything requiring interaction with other objects/scripts happens in Start()

balmy steeple
#

it is pikachuface

balmy steeple
tardy needle
#

For object pooling is it better to store objects in a list or an queue?

mint remnant
rocky canyon
#

(keeping a list of the last few seconds to average them into a rolling value)

#

but, i've also had that question.. would a list be better?

#

i dont think i can test w/ the accuracy to know which ones better

mint remnant
#

Also are you talking about the actual pool? And if so, are you rolling your own or using Unity's. If Unity's you don't care how the objects are stored in the pool. If rolling your own that's a tough one. But once you get them out of the pool what you store them in is going to depend more on how they will be used from there.