#๐Ÿ’ปโ”ƒcode-beginner

1 messages ยท Page 443 of 1

ashen trail
#

@eager spindle thank you, I am following these C# courses on unity that told me I should make my own game so I'm trying to make a space wars clown. https://learn.unity.com/tutorial/lab-2-new-project-with-primitives?uv=2022.3&courseId=5cf96c41edbc2a2ca6e8810f&projectId=5cdcc312edbc2a24a41671e6

Unity Learn

Overview: You will create and set up the project that will soon transform into your very own Personal Project. For now, you will use โ€œprimitiveโ€ shapes (such as spheres, cubes, and planes) as placeholders for your objects so that you can add functionality as efficiently as possible without getting bogged down by graphics. To make it clear whic...

rich adder
#

why not just make reference in the inspector and drag n drop if they're on the same object

eager spindle
#

I dont think you can find it by name.
make a publlic reference to this.

round mirage
#

i want make an inventory

eager spindle
hybrid gust
#

I'll say this is kind of what I did. I think Unity is a great tool for learning C# - Granted I think its important to keep in mind that you won't be making FINISHED GAMES for a while.

#

But its much better than learning via the console

eager spindle
#

my first game was nowhere near finished yea, and my second, and my thirrd.

#

not for another year

eager spindle
#

Its a big part of how I teach people programming for game dev now

rich adder
eager spindle
#

you can just InitWindow(800, 600, "Title"); to get the window you want. then you can DrawCube, DrawText or do whatever you want. very fun stuff

#

it also gives you access to matrix transformation stuff if you want to look into that

#

Raylib builds on rlgl, an abstraction of opengl

#

has bindings for lots of languages too

queen adder
#

Can prefabs not access other components through the inspector?

eager spindle
#

โŒ prefabs are not part of the scene yet

#

why are you executing stuff as a prefab?

strong wren
eager spindle
eager spindle
#

what is unity huh how

#

I see it get referenced a lot here now

rich adder
#

one of the mods made it

eager spindle
#

ooh

eager spindle
#

is there any way to contribute to this? I wanna add something to it

rich adder
#

I believe so

eager spindle
#

ooh theres a github

rich adder
#

github, yea

queen adder
rich adder
eager spindle
queen adder
#

Okay thanks

queen adder
queen adder
#

yes 2d

rich adder
#

firePoint.right = (mouseWorldPos - firePoint.position).normalized

#

or firePoint.up if you got green arrow as your forward

queen adder
#

ill try it out thanks

steel kite
#
private void OnMove(InputValue inputValue)
    {
        _movementInput = inputValue.Get<Vector2>();

        if (_movementInput.x < 0 && !_spriteRenderer.flipX) {
            _spriteRenderer.flipX = true;
            animator.SetBool("turnRight", false);
            animator.SetBool("turnLeft", true);
        } else if (_movementInput.x > 0  && _spriteRenderer.flipX) {
            _spriteRenderer.flipX = false;
            animator.SetBool("turnRight", true);
            animator.SetBool("turnLeft", false);
        }else {
            animator.SetBool("turnRight", false);
            animator.SetBool("turnLeft", false);
        }
    }

I have a blend tree for idle and walk, and I use the spriterenderer.flipX function to flip my character left or right. So far everything is working perfectly. but when I try to run the turn animation before flipX, the character keeps trying to turn and stays in the opposite direction.

rich adder
#

also did you have a look at animator controller during playmode to see where whats happening there

near wadi
#

There is a known Unity bug in Light mode that causes an error because the filename has a space in it. Is there a simple way to alter this code, so it does not fail when it hits a space?

        static IEnumerable<string> GetIconsFilePath()
        {
            // Captures file path from "Editor Default Resources/Icons/<theme>", with optional scale suffix (e.g. @2x).
            var regex = new Regex(@"(?<baseName>\w*/\w*)(?<scaleSuffix>@\dx)?.png");

            var basePath = BuildBasePath(IconType.UniqueToSkin);
            var files = Directory.GetFiles(basePath, "*.png", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                // Standardize on forward slashes as directory separators.
                var path = file.Replace(Path.DirectorySeparatorChar, '/');

                var match = regex.Match(path);

                // Skip all files ending with a size number. Example: "@2x.png"
                if (match.Groups["scaleSuffix"].Success)
                    continue;

                var baseName = match.Groups["baseName"];
                Debug.Assert(baseName.Success, $"Found icon file with unexpected path: {file}.");
                yield return baseName.Value;
            }
        }
short hazel
near wadi
steel kite
rich adder
#

Im take a wild guess that you got multiple bools active at once

rich adder
steel kite
rich adder
steel kite
quick fractal
#

Why won't my list show up properly? I've copied it exactly from the Wiki and other scripts that work just fine

quick fractal
#

Nothin

rich adder
#

is Renderer a custom class or are you using the unity one

quick fractal
#

Unity one

rich adder
#

Try right click on the script in Project folder and do Reimport

#

on ArmourModule

quick fractal
#

Still won't show anything

polar acorn
summer stump
#

Show the whole thing, including the icons on the top right

quick fractal
summer stump
#

Also... gotta ask, but it is saved right?

quick fractal
#

It's weird right

summer stump
#

Yeah, nothing is jumping out at me.

Try clicking ctrl+r in unity. Perhaps you have domain reload disabled?

quick fractal
#

I had about half a second of loading and nothing happened

summer stump
#

Dang

quick fractal
#

Using an array works

#

I kind of don't want to use an array though lol

rich adder
#

List should have no issues

#

looks like custom inspector though

quick fractal
#

TriInspector

#

I have no control over whether it's being used or not

glad rune
#

why cant i tag pipe cs Instantiate(Pipe, new Vector3(transform.position.x, Random.Range(LowestPoint, HighestPoint), 0), transform.rotation); Pipe.gameObject.tag = "Pipe";

rich adder
#

might be messing with the List ?

#

idk why it would

rich adder
glad rune
polar acorn
wintry quarry
#

System.Collections.Generic

glad rune
quick fractal
wintry quarry
quick fractal
polar acorn
#

And where did you put it

glad rune
#

Pipe

rich adder
#

also just noticed you directly modifying the prefab in code not the instance :\

glad rune
#

in a func

polar acorn
# quick fractal

I'm gonna put the blame on the custom inspector then. This should work with the default value

polar acorn
eternal falconBOT
polar acorn
#

As presented, you physically could not be getting that error on that line

#

Because you use Pipe the line right before it

wintry quarry
glad rune
#
public float heightOffset = 15;
public float spawnRate = 100;
private float Timer = 0;
void spawnAPipe()
{
    float LowestPoint = transform.position.y - heightOffset;
    float HighestPoint = transform.position.y + heightOffset;
    Instantiate(Pipe, new Vector3(transform.position.x, Random.Range(LowestPoint, HighestPoint), 0), transform.rotation);
}```
quick fractal
#

Yup, others work

rich adder
#

this way you can easily clear them when you need

glad rune
#

fairt

wintry quarry
quick fractal
summer stump
glad rune
#

theres just an update func that calls the spawnpipe but the spawning part works its the tag thats the problem

summer stump
#

Use a paste site

#

Include even the usings at the top

rich adder
#

make the Tag and then change the prefab's tag in inspector

wintry quarry
quick fractal
#

I'm doubtful the custom editor is causing problems, I'm not all that familiar with it but if it's working on every other component then it's going to be my fault

#

All other components just have stuff like this, nothing extra

#

The [NonSerialized] isn't there for most

wintry quarry
quick fractal
#

I, do not think I can make a commit out of this, it's not my project

#

And removing the inspector would totally fuck the entire project

#

everything uses it

wintry quarry
#

duplicate it then? Why are you working on a "not your" project

quick fractal
#

SDK

wintry quarry
#

see what happens with your list

hybrid gust
# eager spindle oh look into raylib

So, I'm trying to have my player character thrust a sword forward at a target using animation rigging, the actual thrusting motion is an animation I did in blender and imported. The sword is parented to the hand only, it doesn't have any bones.
So I have two questions:

  1. The hand's rotation doesn't seem to visually deviate from the original pre-made animation but the sword, which is a child of the hand, DOES point to the source object via the constraint. - So what would I need to do to get the hand (and even better the arm) to also follow the constraint like the sword does.
  2. Although the sword very obviously is responding to the constrain component, it doesn't actually "stab." Towards the end of the animation, it kinda curves around the target, almost like trying to push two magnets together that are facing the wrong way. - Is there a better of setting all this up?

please ping me I need to go afk for a sec

quick fractal
#

Got it working, the people who made the SDK gave me a pointer

wintry quarry
#

which was?

quick fractal
#

Had to add [Serializable] to the top of the class which, I've never done before

#

Things just worked

wintry quarry
quick fractal
#

That and apparently not having a static list helps

wintry quarry
#

that's only necessary for non MB usually

polar acorn
#

Statics are never serialized

wintry quarry
#

um yeah if it was static

quick fractal
#

I tried it with both static and not static

wintry quarry
#

that was your actual problem

polar acorn
#

It wasn't static in your screenshot

wintry quarry
#

(or if it was, it was cut off)

quick fractal
#

Ok I can't just.. Link stuff with a .

quick fractal
#

Seems I had to do both

summer stump
# quick fractal Seems I had to do both

That is an issue caused either by something else in the project or the custom editor. Because that is not required in base unity
MonoBehaviours are serialiable automatically

raw token
toxic pasture
#

if I were to create a new type of tile that inherits from the "TileBase" class, how would I use it within the tilemap?

hybrid gust
#

Also I didn't realize I sent that as a reply my b

rich adder
#

its similiar to ScriptableObjects

#

these are Scriptable tiles

glad rune
# rich adder didnt I also suggest you last time you can store the instance in a list ? Instan...

so i am trying to add the pipe but its the same issue do i have to add it to the list in the instantiate line. i know what i am adding is the prefab ``` cs void spawnAPipe()
{
float LowestPoint = transform.position.y - heightOffset;
float HighestPoint = transform.position.y + heightOffset;
Instantiate(Pipe, new Vector3(transform.position.x, Random.Range(LowestPoint, HighestPoint), 0), transform.rotation);
pipes.Add(Pipe);

} ```

rich adder
glad rune
#

yeah

rich adder
#

i told you Instantiate returns the copy instantiated.

#

capture the result in a variable

glad rune
#

so : var copy = instantiate(...)

#

and then add copy

#

fair

#

yaaay it works. thanks a lot to anyone that helped much appreciated

toxic pasture
#

also it still shows the script icon on it.

toxic pasture
#

ok I still have more work to do but it works

#

ty

pliant valley
#

Hey guys, I'm having some trouble with code that interacts with a GUI. It seems that the code is running before the GUI is finished loading into the program, and as a result some of the variables are referencing non-existent objects which causes errors during certain actions that involve interacting with the GUI. Is there a way to prevent a script from running until the entire GUI has finished loading?

rich adder
#

a good design ๐Ÿ˜…

wintry quarry
#

as well as showing us the actual errors you're getting

summer stump
ancient rampart
#

how would I go about setting the width and height of an rect transform to be that of the texture I'm giving the imageui component?

ancient rampart
#

hmmm guess I should've been more specific, I've got a waveform that I'm generating from an audio clip, but I need the rect it fills to be the same length as the generated waveform/audiolength

wintry quarry
#

audio length is an abstract concept

#

or rather, it's measured in time, or number of samples. Not in pixels

#

Therefore you'll have to decide how many pixels == one sample or whatever

ancient rampart
#

yeah ik, I'm trying to figure out a way to map the image to a timeline that'll be in seconds, not sure the best way to go about that

wintry quarry
#

if it's anything like audacity or any other waveform editor, you would basically have a "zoom level" at any given moment which has some value for "samples per pixel" that you change as you zoom in/out

ancient rampart
#

gotcha, I'd have to add in some logic for all the different sample rates for that, right?

#

since sample amounts would vary

wintry quarry
#

i mean realistically you'd probably write a shader that converts the sample data to visual/texture data on the fly

#

with the pixels per sample and position of the cursor within the sample as inputs

#

In the UI side it'd just be a RawImage of whatever size you want

ancient rampart
#

for context I'm trying to make a charter for a game (rhythm game stuff) the charts use microseconds for their unit of time and I'm gonna be trying to get some visualization in for the wav file that I can then use as reference when making the beat markers

#

I have some code that makes a waveform as a sprite for the ui image object, and that all is procedural

#

at the point where I need to figure out how to actually show the waveform properly with scaling and whatnot

wintry quarry
#

Yeah my recommendation would be a compute shader to draw the waveform in a texture

ancient rampart
#

rather than drawing to a texture without a shader?

wintry quarry
#

I would guess this is quite slow

#

the point of a shader would be to do this much faster so it doesn't bog your app down

#

is this for the editor though?

ancient rampart
#

yeah, this is all just an editor, not an actual game

#

it'd be parsing yaml data and converting from and to

frozen stream
#

y'know how in like the older midway racing arcade games, the physics were like your car was glued to the ground and had heavy gravity without the ablility to flip the car over no matter how big the jump was? how do I recreate that arcade-y feel with (I'm assuming) rigidbody forces

wintry quarry
#

Well those games almost certainly had custom physics

teal viper
wintry quarry
#

not an off-the-shelf physics engine

frozen stream
#

I figured it was custom non realistic physics I just meant that for the unity equivalent I'd have to use rigidbodies

wintry quarry
#

You only have to use Rigidbodies if you want to use PhysX

#

You can write your own custom physics in C#, just like they wrote their own custom physics

frozen stream
#

idk I have some existing code that uses forces but if you think something like the character controller would be better...

wintry quarry
#

CharacterController is part of the Physics Engine too

frozen stream
#

well

#

I don't think I'm smart enough to remake custom car physics lol

#

how would I use counter forces to force the car to un realistically stay level in the air?

#

without flipping over due to center of mass

teal viper
#

Maybe get the dot product between it's current and desired orientation, and (with some math) use it as a multiplier for a torque.

frozen stream
#

what is a dot product?

#

i never done anything with physics

teal viper
#

Dot product is not really a physics thing.

#

Although it's used in game physics mechanics often.

ripe shard
#

dot product is when you graduate form trigonometry to real math and suddenly hard stuff gets easy ๐Ÿ˜‰

frozen stream
#

one google search later it's the in between of two vectors?

#

or the middle i should say

ripe shard
#

its a projection of one vector onto another, the resulting value tells you how orthogonal they are to each other

#

0 = orthogonal, 1 = perfectly aligned, -1 opposite direction (when both vectors are normalized)

#

values in between can be interpreted as a cosine of the angle between the vectors

#

you could also imagine the dot product as the length of the shadow vector A casts on vector B

frozen stream
#

I need to learn more math for this lol, thank you for your help but I'm not smart enough to use it

#

I can't remember geometry class

north oar
#

how would i give a prefab some randomness when it spawns like one will spawn on the floor and one will spawn on the ceiling? or would i have to make 2 seperate prefabs

strong wren
cosmic dagger
ancient rampart
#

what's the best way to instantiate a prefab incrementally? looking to spawn a line of objects with a specific spacing upwards

raw token
ancient rampart
#

how would I go about that? been having some issues with using float inputs for the offset (gonna be using the user input as the offset amount, and it's a number with a decimal place)

#

gonna try to fit some examples I found to what I'm after in the meantime, or if you don't want to it's all good

honest trench
#

im having a problem where if the player crouches while idle, they stay in crouch even if they let go of control, and the only way to uncrouch is to walk and press control. Attached is a screenshot of my animator, and a pastebin with my movement state manager, my movementbasestate, and my idle and crouch state scripts. https://pastebin.com/78VHaC2z
please somebody help :)

#

and lmk if theres any thing else i can show to assist in diagnosing the problem

raw token
ancient rampart
#

thank you, I'll try to work this out

raw token
raw token
#

@karmic isle Your condition in that if statement looks a little funky...

if (Input.GetKeyDown(KeyCode.Space) == !isJumping)

This reads as "If whether or not the space key was pressed is equal to the opposite of whether or not the player is jumping"

What you should try to make it say is "If the space key was pressed and the player is not jumping"

karmic isle
#

i gotcha

#

what if i remove a "="

if i changed the == for && what that do anything? or maybe the answer is in the "inputkeydown"?

deft grail
raw token
# karmic isle what if i remove a "=" if i changed the == for && what that do anything? or ma...

= is the "assignment operator", used to set the variable on the left to the value on the right. You shouldn't ever really see it in an if statement's condition.

== is the "equality operator", which checks if the left and right are considered equal, and evaluates to the boolean value true or false respectively.

&& is the "boolean and operator", which will evaluate to true if the things on the left and the right both evaluate to true, and false otherwise.

Input.GetKeyDown(KeyCode.Space) is fine ๐Ÿ‘. From it's documentation page, we can see that when we call this method, it will return true if the key was just pressed this frame, and false otherwise

mint remnant
karmic isle
#

ah sick

#

good news, "&&" seemed to work instead or well atleast its recognized as "isjumping"

#

one step closer

karmic isle
mint remnant
#

good code is self documenting, just make your code read like you want it to happen, if user pressed jump and player is not jumping...do this

summer stump
copper orbit
#

i'd like to change the scale of an object when instantiated. Can I do this?

#

Transform bulletTransform = Instantiate(VfxSlash, pistolTransform.position, Quaternion.identity);

bulletTransform.transform.localScale = scale;

#

scale being a vector3

deft grail
mint remnant
#

you'll have to use the vector3 scale per axis remember, as you can't just multiply a vaector3 times another vector3

#

oh nvm, you're setting it, not multiplying it

queen adder
#

how to scan whole project for errors using vscode unity extension? F8 used to find all errors in the project using omnisharp

#

now it wont show unless I open the files

#

now I have to rely on clicking errors in the console, rather than just staying in vscode and pressing F8

wintry quarry
queen adder
#

transform.transform.transform.transform.transform.transform.gameObject.SetActive(meow)

dark needle
#

anybody>?

#

cant fijnd

queen adder
summer stump
# dark needle

Please don't crosspost
Nor ping people not already in a conversation with you

dark needle
#

i didnt know i just joined to fix this

queen adder
#

doesnt really hurt posting it where it should be

summer stump
dark needle
#

no i had a code issue]

queen adder
#

oh so it's the third, lol second is acceptable at most UnityChanOops

summer stump
half egret
topaz mortar
#

GameObject equipment = GameObject.FindGameObjectWithTag("Equipment");
Is this correct? Seems weird

deft grail
topaz mortar
#

So I have an Item and Inventory script, neither have references to the other
My Inventory holds a list of equipped items
I somehow need to access this from Item, so I can show the description of the currently equipped item (if there is one) when an item is hovered

eternal needle
#

Your inventory doesnt have a reference to items, yet it holds a list of them?
I would just have the inventory go through each item and assign itself to whatever is needed. Though I dont really see how this is needed. Your UI and inventory itself should be separate

topaz mortar
#

so Item would have a reference to Inventory, which is filled in the Inventory script? that kinda makes sense

#

seems like a waste of memory to add a reference on each item, but I guess it doesn't matter

#

I guess Inventory does have all the Item references

eternal needle
#

Well my last sentence was saying how you probably shouldnt need that at all. Because your UI is not (or should not be) the actual item itself

topaz mortar
#

if you're saying I should be doing something like MVC then that would just make things needlessly complicated, and it would just create the same issue in the view

raw token
#

Basic character movement

topaz mortar
#

my UI code is on the item itself atm

#

I could throw an event to inventory on hover, then have the inventory call the ShowDescription function on the item a second time if there's an equipped item
but kinda seems like a long detour

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

public class EnemyShooting : MonoBehaviour
{   public Transform Player;
    public float Distance;
    public bool ShootReady = false;
    public GameObject bullet;
    private Rigidbody rb;
    public float DistanceBetweenPlayers;
    public float Cooldown = 5;
    public float CountDown = 0;
    public float BulletSpeed;
    public float DistanceNumber; // distance enemy needs to see player and shoot

    // Start is called before the first frame update
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        DistanceBetweenPlayers = Vector3.Distance(transform.position, Player.position);
        LookAtPlayer();
        Shoot();
        CountDown += Time.deltaTime;
        if(CountDown >= Cooldown && DistanceBetweenPlayers <= DistanceNumber){
            ShootReady = true;
            CountDown = 0;
        }
        else{
            ShootReady = false;
        }

    }
    void LookAtPlayer(){
        if(DistanceBetweenPlayers <= DistanceNumber){
            transform.LookAt(Player);
    

        }
        else{
            ShootReady = false;
        }
    }
    void Shoot(){
        if(DistanceBetweenPlayers <= DistanceNumber && ShootReady){
            GameObject Bullet = Instantiate(bullet,Player.position,Player.rotation);
            rb.velocity = transform.forward * BulletSpeed *0.2f;
        }

    }

    

}``` how do i make it so the bullet shoots a lot slower?
#

look in the shoot method to see how i did it

topaz mortar
raw token
native hill
#

thank u, i shouldve reread my code i havent gotten on unity in a bit

raw token
half egret
#

Good catch, I missed that!

native hill
#

changing the bullet speed didnt work at all everytime i tried, thank you ill do that

raw token
#

Same same at first - brain autocomplete filled some stuff in for me ๐Ÿ‘€

ornate tree
#
using UnityEngine;

public class BookManager : MonoBehaviour
{
    public GameObject redBookPrefab;
    public GameObject blueBookPrefab;
    public GameObject greenBookPrefab;
    public Transform[] spawnLocations;
    public Collider redZone;
    public Collider blueZone;
    public Collider greenZone;
    private GameObject redBook;
    private GameObject blueBook;
    private GameObject greenBook;
    private HotelSpawner hotelSpawner;

    void Start()
    {
        hotelSpawner = FindObjectOfType<HotelSpawner>();
        SpawnBooks();
    }

    void SpawnBooks()
    {
        // Shuffle locations
        ShuffleArray(spawnLocations);

        // Spawn books at random locations
        redBook = Instantiate(redBookPrefab, spawnLocations[0].position, spawnLocations[0].rotation);
        blueBook = Instantiate(blueBookPrefab, spawnLocations[1].position, spawnLocations[1].rotation);
        greenBook = Instantiate(greenBookPrefab, spawnLocations[2].position, spawnLocations[2].rotation);

        Debug.Log("Books spawned");

        // Ensure the books have Rigidbody components
        AddRigidbodyIfNeeded(redBook);
        AddRigidbodyIfNeeded(blueBook);
        AddRigidbodyIfNeeded(greenBook);
    }

    void ShuffleArray(Transform[] array)
    {
        for (int i = 0; i < array.Length; i++)
        {
            Transform temp = array[i];
            int randomIndex = Random.Range(i, array.Length);
            array[i] = array[randomIndex];
            array[randomIndex] = temp;
        }
    }

    void AddRigidbodyIfNeeded(GameObject book)
    {
        if (book.GetComponent<Rigidbody>() == null)
        {
            book.AddComponent<Rigidbody>().isKinematic = true;
        }
    }

    private void OnTriggerStay(Collider other)
    {
        Debug.Log("OnTriggerStay called with " + other.gameObject.name);

        bool redBookPlaced = redZone.bounds.Contains(redBook.transform.position);
        bool blueBookPlaced = blueZone.bounds.Contains(blueBook.transform.position);
        bool greenBookPlaced = greenZone.bounds.Contains(greenBook.transform.position);

        Debug.Log("RedBookPlaced: " + redBookPlaced);
        Debug.Log("BlueBookPlaced: " + blueBookPlaced);
        Debug.Log("GreenBookPlaced: " + greenBookPlaced);

        CheckBooksPlaced(redBookPlaced, blueBookPlaced, greenBookPlaced);
    }

    void CheckBooksPlaced(bool redBookPlaced, bool blueBookPlaced, bool greenBookPlaced)
    {
        if (redBookPlaced && blueBookPlaced && greenBookPlaced)
        {
            hotelSpawner.IncrementWinCount();
            Debug.Log("All books placed correctly!");
        }
    }
}

i feel like im missing something obvious, but no matter what i do, i cannot get the books to be recognised in the zones, its meant to be i bring the books and place them in the zone, when all three are there im done, but nothing i do seems to work

raw token
ornate tree
raw token
ornate tree
#

no I thought i wouldnt have too since they are called publicly

#

like this i mean

raw token
# ornate tree no I thought i wouldnt have too since they are called publicly

Okay, so here's my confusion: OnTriggerStay() and other physics messages will only be called if the game object to which the script is attached or one or more of it's child objects has a relevant collider. So I didn't understand why this manager script would have some physical presence in the world, or how OnTriggerStay() would get called.

But it's not getting called, so this all makes a little more sense ๐Ÿ˜…

ornate tree
#

is there something im meant to be using instead?

topaz mortar
#

!code

eternal falconBOT
native hill
# raw token Hold up - on re-reading the code, `rb` is the spawning object's Rigidbody. You n...
        if(DistanceBetweenPlayers <= DistanceNumber && ShootReady){
            GameObject BulletInstantiate = Instantiate(bullet,Player.position,Player.rotation);
            Rigidbody BulletRb = BulletInstantiate.GetComponent<Rigidbody>();
            if(BulletRb == null){
                BulletRb = BulletInstantiate.AddComponent<Rigidbody>();

            }
            BulletRb.useGravity = false;
            BulletRb.velocity = transform.forward * BulletSpeed * 0.2f;
        }

    }

    

}``` is this how to do it?
raw token
# ornate tree is there something im meant to be using instead?

There are many different approaches to solving this issue...

You might add a script to your book prefabs - BookController or something. Set it up so that it has a reference to it's respective drop zone collider. In it's OnTriggerEnter() method check if the collider which it collided with is it's respective dropzone, and then have it do something to tell the manager that a book has been placed - it could invoke an event that the manager will subscribe to, or you could give the script a reference to the manager and have it execute some method on it. Do something similar to handle the book being removed. When the manager instantiates the book, have it pass the necessary references along.

You could alternately approach the problem from a script on the drop-zone collider.

Or moving the dropzones to be children of the manager object might just work as-is, but you should probably switch to OnTriggerEnter() as OnTriggerStay() is needlessly expensive for this purpose.

raw token
native hill
#

thank you so much, ill do that

ripe hill
#

hi yall i have a question
i made a village with tons of houses in unity 2d and i want to make them enterable so should i add the inside of the houses in the same scene and just teleport the player to it when he enters or should i make a new scene with the houses ? there are alot of houses so should i make many scene or should i just use 1 scene with just the houses in it ?
give me your suggestions plz

summer stump
#

do not crosspost please

rich adder
ripe hill
summer stump
mint remnant
#

hide the roof of the building they walk into?

ornate tree
deep yew
#

I'm trying to get the object to jump if the spacebar has been touched and if IsOnGround is true, but it doesn't work.
It detects the if statement and it changes the boolean value of IsOnGround to false, but still doesn't work

summer stump
#

Don't mix transform movement with rigidbodies. You will have to move away from the Translate calls

#

Is the rigidbody dynamic? Kinematic does not respond to forces, and thus AddForce will not work

deep yew
#

Nope, it's not dynamic

summer stump
#

Ok, I assume Translate is overriding it then. Combined witb deltaTime making it a miniscule amount of force.

#

This is all assuming that by "doesn't work" you mean it is not jumping

deep yew
#

What shall I use then instead of translate to move the object around?

summer stump
#

Anything that starts with transform. is a no go.
You will either want rigidbody.velocity = or rigidbody.AddForce

deep yew
#

wait hold on, jump still doesn't work

summer stump
deep yew
summer stump
#

Also wait, why are you adding vertical input into the jump?

#

VertiGo should likely not be part of it at all

#

If you are not pressing W, then the whole force becomes 0

#

If you are pressing S, it negates it and sends you down

deep yew
#

Oh

summer stump
#

Pressing W will just... act as if it is not there, because anything times 1 is just that value

deep yew
#

Looks like I still have a road ahead until I get stuff correct.
Thanks for the help/

#

works now ๐Ÿ‘

summer stump
#

No prob!

twilit iris
#

Im new to Unity and I tried to put UI>Legacy>Text on my scene . It shows on my scene but it never shows on my camera. I tried to tweak the Pos z of camera and the text itself and it never work. Any ideas what went wrong? Cause I don't :")

twilit iris
#

is this considered adding to canvas? .-.

eager spindle
twilit iris
#

What even canvas do .-.

eager spindle
# twilit iris What even canvas do .-.

when it comes to displaying stuff theres two types; world space and UI space.
for example on this screen, the X is on UI space. when the camera moves, the UI doesnt move.

#

Placing UI objects in the canvas puts it on the Canvas.

twilit iris
eager spindle
twilit iris
#

Then I want to make the text on world space

eager spindle
#

I'd advise you to use the newer TextMeshPro instead as it's standard now. It will prompt you to add it to the project but after that its smooth sailing.

#

Objects in World Space have a Transform, while objects in UI Space have a Rect Transform. The attached image is what a Rect Transform looks like

twilit iris
#

Okay

#

Wait then I actually make it on UI space?

#

<< been following youtube tutorial but barely understand the basic concept itself

eager spindle
#

The second image are buttons that stay on screen all the time. This is in UI space.

twilit iris
#

wait ill try to make a new 1 in world space and hope that work

#

wait it doesn't show anything

#

I create from UI>Legacy>Text. It spawned on canvas by default. And I dragged it out of canvas

eager spindle
twilit iris
#

eh? QAQ

eager spindle
#

Theres a difference between the text in UI > Legacy > Text and 3D object > Legacy > Text

#

You wanted a world space text so you should get the one from 3D object

twilit iris
#

roger sir working on that

#

wait where

eager spindle
# twilit iris

you're stll looking under UI.
Look under 3D object instead.

twilit iris
#

this?

eager spindle
#

yep

twilit iris
#

ah it shows

#

but how do u show ui space on scene then? .-.

#

I feel like it will be used for game pause a lot so I have no choice to debug this T_T

eager spindle
#

To show text in UI space go to UI->Legacy->Text. Make sure that the created object is under Canvas.

twilit iris
#

what factor do I have in mind to make sure its under the canvas? Since by hierarchy it shows it under the canvas .-.

eager spindle
#

Make sure your element is under the canvas like in the first image.
Check the rect transform of your element and make sure there's an icon there.

twilit iris
#

wait ... it already is right?

#

The thing I did tweak while debugging it myself is pos z, Render mode, anchor on text, Horizontal vertical overflow, The tag and layer thingy. Did any of those could affect it?

#

and the canvas scaler

modest dust
#

Your canvas is in screen space..

#

Press the canvas in the hierarchy, hover over the scene and press F to zoom out to the whole canvas

twilit iris
#

wha

modest dust
#

Yes, now adjust the text correctly

#

So that it's actually inside the canvas, and bigger

twilit iris
#

wait I can't move my canvas. So I have to drag my camera and other object into canvas instead?

modest dust
#

No, you do not move the canvas

#

Your canvas is in screen space render mode

#

It should look like this

#

Just move your text somewhere in bounds of the canvas and make it bigger

#

And play the game and see by yourself

twilit iris
#

uhhh i did put it on the intersection it still doesn't work

modest dust
#

Send a screenshot

twilit iris
#

something like this?

#

Im a bit confused

modest dust
#

Yes, it is now in bounds of the canvas

twilit iris
#

it somehow still doesn't show

modest dust
#

But as you zoom out again, you will see how small it is compared to the canvas

#

The way you see the canvas is how it will render in game

#

It will basically overlay it on the screen

#

Don't place the text relative to the scene objects, think of the canvas as of a blank piece of paper that will be glued to your face no matter where you go or how you rotate

modest dust
twilit iris
#

AH I SEE IT NOW

normal thicket
modest dust
eternal falconBOT
normal thicket
modest dust
#

Read the bot message right below mine..

normal thicket
#

ok

normal thicket
twilit iris
#

So what the correlation between canvas and camera? Can you just put multiple canvas outside of camera and it will just stick to the camera?

normal thicket
modest dust
normal thicket
#

: )

normal thicket
modest dust
#

And you can have as many as you want

twilit iris
#

Okay I'll somehow manage from here . Thanks a lot I debugged that 2 hours crying to my machine like a true programmer even though it does what exactly I did

languid spire
#

the Blender discord?

half egret
#

!blender

eternal falconBOT
ornate tree
#

if anyone could spare a moment of their time, im working on a VR project and i've run into something im not quite sure how to look up the answer for online, i'd be happy to share my screen though

mossy pulsar
#

can anyone tell me how to fix this problem

half egret
#

Do you want to set the text value of the scoreText?

#

You're currently assigning a string to a Text object

languid spire
half egret
#

If you want to assign the text value, it's scoreText.text = ...

mossy pulsar
#

oh i see thank you

#

yep the error is fixed now

twilit iris
#

why does my context menu doesn't show

languid spire
#

because context menu methods cannot take parameters

twilit iris
#

Ahh... Can we somehow make it to take parameters?

#

I saw this documentation but doesn't really understand anything

eternal needle
spare spade
#

Hello. I'm wondering if there's a way to advance exactly one fixed update tick at runtime. I'm setting up some debug tools and want to be able to "frame by frame" in engine without using the editor frame by frame but I'm not entirely sure how to run exactly one fixed update tick when the timescale is set to 0

languid spire
spare spade
#

I think I figured it out

#

I just added a boolean that checks if the game is in frame advance mode and automatically resets the timescale to 0f after the frame advance function flips the boolean and sets the timescale to 1

    private void FixedUpdate()
    {
        UpdateTimer();
        movementTick?.Invoke();
        animationTick?.Invoke();
        hitboxTick?.Invoke();
        if(isFrameAdvance)
        {
            isFrameAdvance = false;
            Time.timeScale = 0f;
        }
    }```
waxen raft
languid spire
#

no, but you could have an empty child game object with a different tag

spare spade
#

What specifically do you need to edit tags for? Damage numbers?

#

np

#

I was gonna suggest using the physics matrix but if you got it you got it

winter tinsel
#

ive been pulling my hair out trying to figure out how to make a jump work

#

i simply cant, and tutorials arent helping either

#

movement code

#

i give up

wintry quarry
#

Every jumping tutorial will address this problem

#

In one way or another

hidden iris
#

for some reason when i use keycode.(whatever key on the keyboard) it just doesnt register

wintry quarry
molten dock
#

is there c# stuff that is not relevant for unity

hidden iris
languid spire
wintry quarry
#

Show the full script

hidden iris
molten dock
wintry quarry
rough hill
#

I am getting an Index Out of Bounds Exception on this. I assume the code is trying to access an index that is not in the arrays length. How can I handle this?

molten dock
#

i have hit a wall in my coding skill idk how to do anything thats not a monobehavior and game mechanic

wintry quarry
hidden iris
wintry quarry
wintry quarry
languid spire
hidden iris
#

rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
Debug.Log("Jumping");

wintry quarry
hidden iris
#

i already have debugs for going left and right and those show

#

this is most defintly a my unity only thing isnt it

sullen zealot
#

hello is there a way to get the sprite location of an image component in script? something like:

string location = transform.GetComponent<Image>().sprite.location // and hopefull it would return a string like "C:/.../Assets/UI/Image.png"
languid spire
sullen zealot
#

not even the name of the png image that contains the sprite(like the spritesheet)?

wintry quarry
hidden iris
#

listen its okay ill find another way to do this since this doesnt seem like a mainstream issue

#

๐Ÿ‘

#

i hate unity's input manager it sucks

languid spire
wintry quarry
hidden iris
#

im going to godot

wintry quarry
#

It just directly reads the key

wintry quarry
hidden iris
#

then why does changing stuff in the input manager affects the code

hidden iris
#

might be diffrent

#

prob not

wintry quarry
hexed terrace
#

nope

hidden iris
#

this is the only script i have

#

damn

wintry quarry
#

Basically... I'm not sure I believe you that it doesn't work as written ๐Ÿ˜‚

hidden iris
#

ill just share it all

#

rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
Debug.Log("Jumping");

#

oh wait

wintry quarry
#

The log will certainly work but the jumping itself isn't going to with how you did your movement code

hidden iris
#

yes this is a subway surfers but no i didnt make it out of my artistic liberty

#

someone asked me to

winter tinsel
#

okay i have a jump, my only requirement now is to make it more floaty

hidden iris
#

reduce grav

winter tinsel
hidden iris
#

nah

languid spire
#

mixing addforce and moveposition is not going to work

hidden iris
#

trust

winter tinsel
#

halfed it rn

hexed terrace
#

if you reduce the project gravity, it will affect everything that uses gravity

hidden iris
winter tinsel
hidden iris
#

n-no

#

just change

#

the players grav

winter tinsel
#

hpw

#

how

hidden iris
#

๐Ÿ’€

#

idk

#

im new

#

rb

#

or

winter tinsel
#

so why are you giving advice??

hidden iris
#

reduce player mass

languid spire
hidden iris
#

using rigid body

winter tinsel
hexed terrace
#

it can go lower

hidden iris
#

or .8

winter tinsel
hidden iris
#

or .0000000001

#

it works

hidden iris
hexed terrace
hidden iris
#

looks like im the pro

hidden iris
#

i shouldnt be talking i cant add a jump

hexed terrace
#

You should certainly be talking a lot less

hidden iris
#

i spent 3 hours on this // Handle jumping based on input
if (Input.GetKeyDown(KeyCode.Space))
{
// Apply a vertical force to jump
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
Debug.Log("Jumping");
}

#

and it wont work

hexed terrace
#

and read this on how to share code properly ๐Ÿ‘‡ !code

eternal falconBOT
languid spire
hidden iris
#

utube code

hidden iris
#

trying to make it work took 2 hours and 59 minutes

hidden iris
languid spire
#

pointless if you dont understand it

hidden iris
#

do

#

tho

#

i do tho?

hidden iris
languid spire
#

and is rb not null? as I said earlier

winter tinsel
hidden iris
#

yes, yes i do

hidden iris
#

it isnt

languid spire
hidden iris
#

ok

#

happy

raw token
# hidden iris

The script in your IDE is playermovement.cs. That appears to be using a separate PlayerMovement.cs

winter tinsel
#

reducing the mass of my rb just makes the jump stronger

#

it doesnt keep the rigid body in the air for longer

#

warum

#

maybe it has to do with this

#

but if i dont actively give it gravity it falls incredibly slow

#

and i dont know why

#

its like the gravity isnt actually affecting it

raw token
#

playermovement.cs contains the PlayerMovement class. PlayerMovement.cs contains the Player_Movement class.

languid spire
winter tinsel
#

figures

#

ill just get rid of it

modest dust
hidden iris
#

nice

winter tinsel
#

what i dont get is why increasing the drag

#

doesnt

#

do

#

what

#

it shoudl

#

i made it an insane value and no dice, im beyond confused

hidden iris
#

listen

#

making mass less

#

will make jump stronger

#

but also make u stay in air a bit longer

winter tinsel
#

not what i wneed

winter tinsel
hidden iris
#

so just make it so that u have low mass and low jump power to stay in air longer

hidden iris
winter tinsel
#

its 0.5

hidden iris
#

do u think ur gonna need mass later on

#

or is this the only instance of its use

#

if so then just make it as low as it needs to be

#

like .0 something

winter tinsel
#

okay

eager spindle
#

video game characters jump really high which is why falling also takes much longer, adjust your gravity scale accordingly
imagine being able to jump 8x your height

hidden iris
#

u should probably not this is like leaving the broken glass under the rug

#

but uh

eager spindle
#

mass doesnt affect the rate you fall btw

#

in a vacuum, a block of steel and a feather fall at the same rate

wintry quarry
#

and because your code is setting y velocity to 0 every frame

#

as I mentioned like an hour ago

winter tinsel
eager spindle
#

1kg of steel or 1kg feathers

#

unless you're working in microsoft flight sim or smth, video game physics dont really take air resistance into account

winter tinsel
hidden iris
eager spindle
#

the steel because steel is heavier than feathers!!

winter tinsel
wintry quarry
#
Vector3 velocity = direction * Moveforce; // poorly named variable :(
velocity.y = playerbody.velocity.y;
playerbody.velocity = velocity;```
You need something like this @winter tinsel
in order for gravity to work normally
hidden iris
#

so turns out sharing a pc with someone working on a seperate unity project without u knowing so isnt a good idea

#

i wanna kms

eager spindle
cosmic oxide
#

My player is at x=0, y=0, Z=0. The values changes to some weird numbers when I hit play but the player is still technically at 0,0,0 in the scene. Can somebody help?

eager spindle
#

nothing to be concerned about

hidden iris
#

๐Ÿ˜ญ

eager spindle
#

this is 7 x10 ^ -11

#

type that into your calculator

#

idk why its yellow though

winter tinsel
cosmic oxide
winter tinsel
eager spindle
#

just set the player's transform.position

winter tinsel
winter tinsel
wintry quarry
#

i was adapting the code from a slightly different version that used it

winter tinsel
#

aha

wintry quarry
#

I would bring up this issue with the asset pack publisher and see what they say

#

also this is not a code issue

hexed terrace
#

You delete the one from here

tulip spear
#

just didnโ€™t wanna remove context for mods no need to get sassy. sorry

cosmic dagger
#

You do it, don't make us (them) have to work . . .

tulip spear
#

๐Ÿซก

winter tinsel
#

im confused

#

nothing makes sense anymore

#

my playerbody is falling incredibly slowly

#

whgat

#

AAAAAA WE HAVE JUMP, FINALLY, 3 DAYS FOR THIS

#

time to make sprint now

rough orbit
#

This is a script for a finish line. Why doesn't this work? Before doing the if statement it worked fine.

hexed terrace
#

read the error message it's giving you

rough orbit
#

I'm a beginner so something being ambigous doesnt really help me

#

"CS0104 'Debug' is an ambiguous reference between 'UnityEngine.Debug' and 'System.Diagnostics.Debug'"

hexed terrace
#

Debug exists in two places (namespaces), it doesn't know which one to use in your class

#

look at the top of the class, at all the lines that start with using

rough orbit
hexed terrace
languid spire
#

if you misuse lerp like that, no, because it will never complete

winter tinsel
hexed terrace
rough orbit
wintry quarry
#

The third parameter you pass into Lerp is t, which is the elapsed percentage of completion. When t reaches 1, the Lerp has been completed.

The implication is you are intended to be incrementing t yourself over time until it reaches 1. So you will know when it's done. But you aren't using Lerp properly.

gusty scaffold
#

does Instantiate return a game object? there are a lot of "instantiate" methods in the docs and i don't know which one i'm using

wintry quarry
#

So in this case, since flipperprefab is a GameObject, yes it will return a GameObject

hexed terrace
rough orbit
eager spindle
#

vs just adds including of namespaces from time to time

hexed terrace
eager spindle
#

always check the top of your file

hexed terrace
#

Top one is from UnityEnigne, second one is from System.Diagnostics and will add it to the top if I select it

rough orbit
wintry quarry
rough orbit
#

Oh well, thanks guys

round mulch
#

Hi, I'm having issues with gravity and wanted to know if there is a work around.
Basically I'm trying to have a falling box that the player needs to pick up, which'll add a point and then move it back up. The issue is it won't respond to being touched with rigidbody outside of landing on top of the player. Is there any work around I can implement so it'll still fall but react to being touched?

hexed terrace
#

"being touched" is what, in the context of your game?

round mulch
#

The player character is moving back and forth to grab falling boxes, and I want the box to acknowledge it's coming into contact with the player character. both have box colliders, and the box has a rigidbody so it'll fall, but I think that's confusing it cause it ends up just sitting on my player character's head

hexed terrace
#

so you want it to pass through the player?

#

that's not "confusing it" .. it's doing what it's setup to do

winter tinsel
#

for some reason, this makes my character, when jumping, go to mars

#

why

#

he sprints right but then when i jump it makes me go to into the stratosphere

wintry quarry
winter tinsel
#

no

#

but wiat what

wintry quarry
#

if you hold the key down for only 5 frames, you will multiply your velocity by 32

winter tinsel
#

if thats the case i should constantly be accelerating

wintry quarry
#

after 10 frames, you will multiply it by a million

winter tinsel
#

but my vertical velocity is fine??

#

i mean horisontal

wintry quarry
#

including horizontal

winter tinsel
#

yea my issue is the horisontal velocity is fine??

#

it doesnt accelerate

#

i dont turn into a train

wintry quarry
winter tinsel
#

huh?

wintry quarry
winter tinsel
#

i said my jump is not working right

#

i mixed it up and said I MEAN HORISONTAL

winter tinsel
#

running doesnt turn me into a train, but if i jump i get sent to mars

#

how and why

#

i do not have the horisontal values clamped

#

x,z

wintry quarry
winter tinsel
#

shouldnt that make my horisontal velocities also become huge?

wintry quarry
wintry quarry
wintry quarry
winter tinsel
#

yea

#

how do i overwrite the vertical velocity then

wintry quarry
#
Vector3 velocity = rb.velocity;
velocity.y = whateverYouWant;
playerbody.velocity = velocity;```
#

same way

winter tinsel
#

wdym by whatever you want

#

i guess the gravity?

wintry quarry
#

no

#

the velocity

#

you asked how do I set the y velocity

winter tinsel
#

overwrite

wintry quarry
#

yes

#

which is the same as setting

winter tinsel
#

so it doesnt go flying

#

then

wintry quarry
#

why would it go flying

winter tinsel
#

its going flying right now??

wintry quarry
#

it's only going flying because of your other code

winter tinsel
#

thats the issue

wintry quarry
#

yeah because your code doubles the velocity each frame

#

stop doing that

round mulch
#

So I was able to figure out my issue with the rigidbody, but now I'm trying to get it to react to being touched. For refrence, here's a video of the game. I want the box to move back up and give the player a point when the player character touches it. Both have box colliders active.

wintry quarry
round mulch
#

i don't know why it saved like that

round mulch
#

The issue is around 35 seconds in

#

I want the box to give a point and move when it collides with the player character's collider

wintry quarry
#

All we got was a zoomed in scene view of the object

#

you'll need to actually set up the physics components and code to do it.

round mulch
#

Here's the code

wintry quarry
#

you should start with that so you can code with intellisense and error highlighting

#

!code

eternal falconBOT
raw token
#

Which IDE is that? ๐Ÿ‘€

round mulch
#

There we go. The ScoreManager is a separate code that'll add one to the UI when that line runs

round mulch
raw token
round mulch
slender nymph
#

why would you put it into hastebin only to screenshot it? you're meant to share the link when you use a bin site.

hexed terrace
#

it's not easier to read code without the syntax colouring..

slender nymph
round mulch
round mulch
#

I'm a genius๐Ÿ˜€

raw token
# round mulch yeah sorry ๐Ÿคฆโ€โ™‚๏ธ I was using that cause i hadn't downloaded vsc and was using i...

You should use either Visual Studio, Visual Studio Code, or JetBrains Rider. Anything else, it won't have official or likely very functional Unity support... A properly configured editor will catch many a error as soon as you type it rather than when you wait for it compile, and will offer a plethora of other invaluable features, like autocomplete and a debugger.

Per this server's scripting #854851968446365696, a properly configured IDE is a requisite for assistance. It really is worth the time investment now - the earlier you do it, the more time and tears it will save you

mint remnant
#
            Ray rayCheck = new Ray(Camera.main.transform.position, (transform.forward - transform.up).normalized);
            RaycastHit hitCheck;
            if (Physics.Raycast(rayCheck, out hitCheck, 1.5f, groundedMask))
                Debug.DrawLine(transform.position, hitCheck.point, Color.white, 5);
            else
                Debug.DrawLine(transform.position, 1.5f * (transform.forward - transform.up).normalized, Color.red, 5); // just wtf

Was expecting this to give me a nice white line in front of the player controller just ahead of where he walks, instead got a red line off at some odd angle and rather long. Anything obviously wrong?

pallid nymph
mint remnant
#

oh crap, you're right

#

too early

wintry quarry
ancient rampart
# raw token Something to the effect of ```cs Vector3 spawnPosition = initialSpawnPosition; f...

hey again, so I'm running into a few issues, the prefabs aren't spawning from the gameobj that has the script, they should be spawning as children of it, not sure how to go about that, figured it'd do that since it's being instantiated from the specific object, also it isn't respecting the "numberOfObjects" variable, it's spawning infinitely, and another issue that I'm running into but I can worry about that after is it's not added the offset, not sure how I went so far off the rails with this hahaha

https://hastebin.com/share/oxiqelomic.csharp

#

ok sike

#

offset is solved

#

I should've read

#

rest of it idk tho

raw token
#

Fire! Chaos!

ancient rampart
#

new coder!

#

that comes with the gig hahaha

#

at least the offsetting works now lmao

#

also it does have to be in update since I want the positions to adjust based on the bpm

wintry quarry
round mulch
#

https://hastebin.com/share/neyipidoco.csharp
Ok I'm still going and it's still not reacting to coming into contact with the other collider. Anyone able to help me figure this out?

ancient rampart
wintry quarry
#

nothing in the code that would stop it

ancient rampart
wintry quarry
ancient rampart
wintry quarry
#

yes

#

it does that whole thing every frame

ancient rampart
#

yeah this is under the number of objects right

wintry quarry
#

frame*. So 20 objects each frame

raw token
# ancient rampart hey again, so I'm running into a few issues, the prefabs aren't spawning from th...

the prefabs aren't spawning from the gameobj that has the script, they should be spawning as children of it

There are two ways to accomplish this here - you can either choose one of the Instantiate() overloads which includes the Transform parent argument, or you can change the parent after the fact by storing Instantiate()s return value in a variable (which will be a reference to the new clone's GameObject) and calling .transform.SetParent() on it

wintry quarry
ancient rampart
#

it's in start so that makes sense

#

figured it was just making objects iterating by 1 up until that amount

wintry quarry
gusty scaffold
#

wow i was just working on the same problem. i used .transform.SetParent()

ancient rampart
#

you just said it does 20 every frame

wintry quarry
#

yes

ancient rampart
#

not 1 every frame up until 20 exist

wintry quarry
#

no

#

20 ewach frame

#

every frame

ancient rampart
wintry quarry
#

in a single frame

#

within the frame

#

and then does it again next frame

ancient rampart
#

so not 1 every frame

wintry quarry
#

no i never said 1 every frame

ancient rampart
#

I did

#

and you said exactly that

wintry quarry
#

never

wintry quarry
#

which is what it does

#

just, within a single frame

#

not over many frames

#

for (int i = 0; i < 20; i++) will do:
i = 0
i = 1
i = 2
...
And so on up to 20

ancient rampart
#

gotcha

raw token
# ancient rampart also it does have to be in update since I want the positions to adjust based on ...

also it does have to be in update since I want the positions to adjust based on the bpm

You might keep it in Update(), but if these are supposed to spawn on the beat, you'll probably need to implement some sort of timer or other control such that the loop only runs if it's time to drop the beat.

If you mean that the already spawned beats should be moved rather than creating new ones, you should spawn them outside of Update(), and store a reference to each beat clone in some collection - probably a List of GameObjects or Transforms - and then iterate through the list and change their positions when the beat drops

ancient rampart
#

yeah I was thinking about how I was gonna do that, especially since I'd need to edit them in relativity to eachother/the first one

#

I'll take it deleting and re-instantiating isn't an ideal way of doing that

#

I do still plan on marking down each beat with a collection btw

#

I need that for the charting stuff to map notes onto the timeline

mint remnant
#

you are including both in the using statements

cosmic dagger
#

you somehow added using System.Numerics statement that has a Vector2 class . . .

slender nymph
#

no it wasn't

cosmic dagger
#

the code does not know which Vector2 you want to use. you need to specify UnityEngine.Vector2 or System.Numerics.Vector2 . . .

#

just remove the using statement you don't need . . .

slender nymph
#

you know what does cause it? when you go to autocomplete Vector2 but don't pay attention and you autocomplete the one from the System.Numerics namespace

wintry quarry
#

depends how you define "better"

#

Easier for beginners: Legacy
More powerful and flexible: New Input System

#

As in more features like:

  • Runtime rebinding
  • Local multiplayer support
  • Event Based input handling
raw token
# ancient rampart I'll take it deleting and re-instantiating isn't an ideal way of doing that

I haven't entirely grasped your intended outcome is here, so it's hard to say either way.

If you'll need the game objects for all of the beats simultaneously at some point, yeah - it probably makes sense to just keep adding to the collection. Or if you know/can calculate how many beats you will need for the full song, you could allocate an array of that size ahead of time, and possibly immediately fill it in with disabled game objects which you just activate as the song progresses...

But if the beat data does or can exist independently of the game objects, and the timeline would not use the same game objects as... whatever this thing is... you might also look into "Object Pooling" at some point - it's a good tool to have in your toolbox.

That said, make something which works first - improve upon it after ๐Ÿ‘

ancient rampart
#

fair, the goal is essentially make a bunch of "beat" markers that'll make up the timeline, individualize them all so the charting data can map to them (1, 2, 3,4, etc) and allow you to change the offset between them if you change the bpm, I think for simplicity sake, just delete and re-instantiate if the bpm has been changed, then readjust the placements of the notes, also I'll look into objects pooling

gusty scaffold
#

how can i associate a variable of type int[][] with instances of an object?

#

there's a "variables" component but it doesn't have that data type

wintry quarry
#

What are you trying to do?

#

in general "associations" can be made with a Dictionary

#

but it's unclear if you're trying to associate a given int[][] or a given int or a given int[] to a particular GameObject

mint remnant
#

is that synonomous with int [,] ?

wintry quarry
#

no

#

they are different

gusty scaffold
#

right, i meant int[,]

wintry quarry
#

but that's also beside the point

gusty scaffold
#

it isn't synonymous in C#

raw token
# mint remnant is that synonomous with int [,] ?

That's a jagged array - the inner arrays can have different lengths, whereas they'll have the same length in a multidimensional array. Because of this property, jagged arrays are an array of references to arrays, while a multidimensional array is contiguous in memory... And some other differences I've forgotten since I last looked them up ๐Ÿ˜…

wintry quarry
gusty scaffold
wintry quarry
gusty scaffold
#

i'm looking at the UI

wintry quarry
#

what UI

polar acorn
gusty scaffold
#

the inspector

wintry quarry
#

it's only relevant for Visual Scripting

polar acorn
gusty scaffold
#

yes, that would suit my need

wintry quarry
#

Ok that would have been a better question to ask

gusty scaffold
#

it doesn't strictly need to show up in the inspector

wintry quarry
polar acorn
#

I don't think those are serializable by default. You could finagle one by making a Serializable class that extends, for example, int[] and making an array of that object. But it makes the code messy

#

Or you could use a custom inspector

polar acorn
gusty scaffold
#

where to put the script?

#

it can't be attached to the game object itself

#

because then every instance would have the same values

#

i assume

polar acorn
gusty scaffold
#

i don't know

#

i guess i need a controller object to assign values to each object

wintry quarry
#

variables on a script are unique to each individual instance of the script

gusty scaffold
#

oh...

polar acorn
#

unless they're static

gusty scaffold
#

but they are initialized in the script

#

so they will get the same values even if they are in different memory locations

polar acorn
wintry quarry
polar acorn
#

They don't initialize themselves, you have to do that

gusty scaffold
#

yes but where to put the initialization code?

wintry quarry
gusty scaffold
#

should i make a controller object?

#

the inspector?

wintry quarry
#

yes the inspector

#

"The muffin man?"

wintry quarry
#

that's kind of the whole point of the inspector

gusty scaffold
#

but when does code run if it's not attached to an object?

wintry quarry
#

generally

#

until you call it

gusty scaffold
#

i need the initialization code to run

wintry quarry
#

what code

#

This discussion is far too abstract right now for us to give you any useful answers. If you want better help, you should start sharing actual details about your situation

gusty scaffold
#

okay

polar acorn
#

How about instead of us needing to bust out the deerstalker caps and magnifying glass you say what your actual problem is and what is happening

gusty scaffold
#

i'll give more details

#

i appreciate the help btw

#

this box displays a bunch of numbers... i want each instance of the box to display a different set of numbers

wintry quarry
#

like you want to just set them up in the inspector somewhere?

gusty scaffold
#

the designer of the level

wintry quarry
#

Or read from a file?

#

Or what

wintry quarry
rocky canyon
#

yup, as a level designer i'd be happiest entering them in an inspector somewhere

gusty scaffold
#

but the inspector doesn't allow for array variables

wintry quarry
rocky canyon
#

u can modify an array

polar acorn
wintry quarry
#
public int[] myArray;``` try this and see what happens @gusty scaffold
polar acorn
#

But why would you need a 2D Array? Each box looks like it contains a single number

rocky canyon
#

^ uncollapse

polar acorn
#

You probably want an int on each box

wintry quarry
#
[Serializable]
public class Row {
  public int[] Numbers;
}

public Row[] Rows;```
Also try this @gusty scaffold you will see it works just fine
gusty scaffold
#

i may need an import

wintry quarry
#

your IDE should tell you that automatically

gusty scaffold
#

thanks, i probably don' thave all the extensions installed for VScode

#

now i'm looking for how that class would be serialized

#

probably a comma-separated list

#

oh dang, i don't need to do that

#

the UI just handled it

#

i wasn't expecting that lol

#

thanks

#

wait...

#

this doesn't solve my original problem

#

wait...

wintry quarry
gusty scaffold
#

oh yeah it does

#

sorry i had a moment

wintry quarry
#

You will of course still have to write a little code to populate stuff from that data

karmic isle
#

hey good news, I figured out how to jump only once with my code that i spoke out yesterday

only problem is. when I press jump the first time my character jumps the highest

but once i land and try to jump again my jump is extremely stunted and at a certain point i barely leave the ground

is this like a gravity problem? or a code problem? I remember having this problem before but i dont remember what I did to fix it

rich adder
#

btw dont post screenshots of !code

eternal falconBOT
gusty scaffold
wintry quarry
#

You'll want to rewrite your code to use the Rigidbody.

#

That's causing your issue because your object is essentially building up a huge downward velocity in the Rigidbody.

karmic isle
#

i gotcha

fringe plover
#

Is it good idea?

karmic isle
#

is there a way to add gravity without my rigidbody? i really dont wanna rewrite all this code since ive spent so much time trying to figure it out...

polar acorn
karmic isle
#

thank you ill try it out

forest pasture
#

can some one help me with UI on Unity ๐Ÿ˜„

ancient rampart
#

ik this is simple but I am struggling to find an answer, how can I check if a gameobject is an instance of a specific prefab notlikethis

polar acorn
#

But if the prefab has some unique script on it you can check for that

ancient rampart
#

ohhh ok

#

that'd explain why it's so hard to find an answer

wintry quarry
ancient rampart
#

clearing all instances and regenerating

wintry quarry
#

then you have a list of all of them at all times

ancient rampart
#

never messed with lists before, how would I go about that?

forest pasture
polar acorn
rich adder
polar acorn
#

you just posted a picture of a canvas

wintry quarry
rich adder
#

are you saying the fullscreenmode maybe ?
double click the Scene Tab @forest pasture

#

or shift + spacebar

forest pasture
#

it works

ancient rampart
muted wadi
#

i have a script that imitates running along a wall for a short period, and I'm trying to lessen the amount of gravity the player experiences while running across, but even when i divide the Physics.gravity value by 10 the player still falls at the same rate. How do i fix that?

    {
        isWallRunning = true;
        canJump = true;
        float wallRunDuration = 1.5f;
        float wallRunTimer = 0f;

        Vector3 tempGrav = Physics.gravity / 10;

        Vector3 wallRunVelocity = wallContact.right * wallRunSpeed;
        body.velocity = new Vector3(wallRunVelocity.x, body.velocity.y, wallRunVelocity.z);

        while (wallRunTimer < wallRunDuration)
        {
            wallRunTimer += Time.deltaTime;
            float wallRunProgress = wallRunTimer / wallRunDuration;
            body.velocity = Vector3.Slerp(wallRunVelocity, tempGrav, wallRunProgress);
            yield return null;
        }
        isWallRunning = false;
    }```
wintry quarry
muted wadi
#

it should be manipulating the velocity of the object directly, so making the gravity 10% of what it was should also slow the descent with slerping

#

i could be wrong