#💻┃code-beginner

1 messages · Page 11 of 1

sand condor
#

Also It should not be a problem if the function would do what it is supposed to do 😄

#

I fixed it

#

If I delay the function that connects the neighbors by one frame via a coroutine it works.

#

I think the Physics2D might need a frame to catch up with my transformation of the newly created cells.

#

This makes it work. >.>

IEnumerator DelayOneFrame()
  {
    yield return new WaitForEndOfFrame();
    ConnectNeighbours();
  }
wintry quarry
#

Absolutely 100% do not use colliders for this.

wintry quarry
sand condor
#

But its so convenient 😢

wintry quarry
#

Graph algorithms are even more convenient

#

As are array or dictionary lookups

#

Much faster than physics queries too

sand condor
#

Right now I place several rects that are being filled up with cells. Colliders help me prevent overlap with other rects or static cells. You really think I should try to redo this with arrays or dictionaries? :/

ashen ferry
#

with 2d array u can check any combination of tiles a line box sphere custom shape without too much effort does it sound good yet kekW

sand condor
#

Rects in yellow, static cells already there. The rest gets instantiated in first frame.

#

So redo with array[,] ?

wintry quarry
wintry quarry
sand condor
#

I dont want to but I guess its good to learn that anyways. 😄

final kestrel
#

I have a player that moves forward using rigidbody. Is there any way to rotate it say -90 on x in an instant and move towards the new direction without losing speed?

slender nymph
#

when i did the game of life i just used a tilemap and 2 2d arrays (one for current generation and one for relevant changes) and just changed the colors of tiles on the tilemap to apply the changes. it was incredibly easy to set up

wintry quarry
sand condor
final kestrel
wintry quarry
final kestrel
#

So I should also remove add force and manually adjust the velocity for moving forward as well?

wintry quarry
#

If you want? It's irrelevant to the question at hand

final kestrel
#

Does directly setting velocity keep the object from interacting with other objects?

#

I mean can I still see the physics effects?

wintry quarry
#

It doesn't really matter where the initial velocity came from

wintry quarry
slender nymph
neon ivy
#

I'm making a pixel simulation, should I use a class or a struct to store a pixel's data? would be nice to know why as well.

slender nymph
#

It Depends™️
do you need references to the data so that you can just pass the reference around and modify that data without needing to pass it back to the object and reassign? or do you need this for the jobs system where managed data isn't allowed? whether you should use a class or struct depends entirely on your actual needs for the data
also note that the questions at the beginning of the paragraph are simply examples and not in any way exhaustive

oak hamlet
#

hello, does anyone know why my code editor isn't like automatically attached to unity whenever i open it? i use microsoft visual studio code 2022, and im a beginner in unity.. yesterday when i was coding on unity, it was all fine, but now the code editor wont show the assets files that are inside of unity, if yk what i meant, and the attach button should've had "attach to unity" already written on it, but it doesn't, it's just "attach".. and there isnt auto complete why is that?
sorry if you don't understand but i am really really bad at explaining things and problems

slender nymph
#

make sure that it is configured !IDE 👇

eternal falconBOT
#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

oak hamlet
#

ive already done this

#

wait

oak hamlet
#

ill check once again just in case

slender nymph
#

i'm gonna go ahead and guess that the external tools setting in unity got reset

oak hamlet
#

ah yes, that was the problem

#

thanks lol, is there any way i could prevent it from reseting?

slender nymph
#

restart the editor and make sure the setting stuck

oak hamlet
#

or i have to always do this every time i open up my projecty

#

alr

slender nymph
#

if it did not then something is preventing unity from writing that setting so you'll need to launch as admin, assign the setting, then launch without admin privs. that has fixed it every time i've seen that issue come up

oak hamlet
#

no need to do that im pretty sure, i restarted the editor and it didn't reset external tools

#

thanks man, appreciated

#

oh and also, may i ask if you have any good code editor theme suggestions?

#

i dont really like the default ones

slender nymph
#

i use darcula 🤷‍♂️

oak hamlet
#

this one right?

slender nymph
#

wait, the one i linked was the vs code one. hold on a sec

neon ivy
slender nymph
#

yep

spice girder
#

I want to spawn Meteors at a random location outside the gamewindow and add some movement to them so they will pass across the gamewindow. Does anyone a good way to implement this?

oak hamlet
#

oh thanks

#

much better

slender nymph
spice girder
pastel vector
#

Hi,
What can you do if the editor think that a class/namespace doenst exist even though it does?
I renamed a class and got an error. Deleted the script and created a new with the correct name. Vs Studio doesnt see
any errors but its like the editor doesnt want to recognize that the class now exists again

slender nymph
#

can you explain what you mean when you say "the editor doesnt want to recognize that the class now exists"

pastel vector
#

I get an error CS0246 that says the namespace doesnt exist

slender nymph
#

share the full error

#

and the relevant code

covert matrix
#

im trying to make all game objects in my overworld canvas fade when i click the esc button to pause, but objects like the tiles and player are not
https://gdl.space/uvasoyefec.cs

slender nymph
#

it seems you are fading a canvas group. your player and tilemap shouldn't be on a canvas so that wouldn't work

pastel vector
# slender nymph share the full error

This is the error
Assets\Scripts\ResourceGenerator.cs(51,46): error CS0246: The type or namespace name 'BuildingTypeHolder' could not be found (are you missing a using directive or an assembly reference?)

this is my public class:

public class BuildingTypeHolder : MonoBehaviour
{
    public BuildingTypeSo buildingType;
}

This is the code:

 resourceGeneratorData = GetComponent<BuildingTypeHolder>().buildingType.resourceGeneratorData;
#

No errors is VS

covert matrix
pastel vector
#

But Unity is handling it as the BuildingTypeHolder doesnt exist

slender nymph
#

if you see errors in the unity editor but not visual studio, then your !IDE is likely not configured. but you also aren't showing whether that type you are trying to use is in the same assembly you are trying to use it in or whether it is in a namespace you have imported into the file you are trying to access it in

eternal falconBOT
#
💡 IDE Configuration

If your IDE is not autocompleting code
or underlining errors, please configure it:

Visual Studio (Installed via Unity Hub)
Visual Studio (Installed manually)

VS Code*
JetBrains Rider
Other/None

*VS Code's debugger plugin is unsupported.
We recommend using VS or Rider instead.

sand condor
# wintry quarry Or a Dictionary<Vector2Int, Cell>

One small question regarding the grid lookup: Since the data is of interest for different classes I am considering making it a ScriptableObject to decouple the data to prevent one master class that keeps track of everything. Can you give me a short opinion what you think of this? And what helps you to decide when to put data in a SO and when to keep it in one bigger class?

pastel vector
slender nymph
ivory bobcat
pastel vector
slender nymph
#

you're also still not showing enough context for the issue to determine exactly what is causing it

pastel vector
#

Yeah dont really know what else to show. The editor is somehow not aware that the class exists, had similar problems before and reacreating it has worked, dont know why it doesnt now. But thanks for the link, ill try to update the editor

slender nymph
ivory bobcat
#

Could be anything. I'm guessing the meta file is not updating.

pastel vector
long anchor
#

GameObject.Find is okay to use a lot as long as its once per frame and rare right?

#

just checking

final kestrel
#
private void Move()
{
   _rb.velocity = transform.forward * _moveSpeed*Time.deltaTime;
}

Isnt this code moves player to its local forward?

#

When player's forward changes it still moves it its previous forward

wintry quarry
#

Also make sure transform and rb are the same object here

final kestrel
#

Yes they are the same object

wintry quarry
final kestrel
#

https://hatebin.com/unqiypntnv so okay. If i put the move in either updates the rotation on trigger works just fine but the gravity does not work as intended. Character is floaty when jumping. I'm kind of confused here

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

public class Rotator : MonoBehaviour
{
    Rigidbody _rb;
    Vector3 _leftRotation = new Vector3(0, -90, 0);
    // Start is called before the first frame update
    void Start()
    {
        _rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    private void OnTriggerEnter(Collider other)
    {
        if(other.CompareTag("RotatorLeft"))
        {
            _rb.MoveRotation(Quaternion.Euler(_leftRotation));
        }
    }
}

this is how I change its rotation btw if it matters.

jovial mesa
#

MoveRotation is useful to produce a smooth rotation. If you want to "teleport" your object at a new rotation, just set its rotation (Rigidbody.rotation) as someone suggested you

jovial mesa
#

np

vocal fable
#

why is it not working

final kestrel
#

Is it okay to clamp addforce speed so i dont go fast since im using add force in update?

#

messing with the set velocity did not work all that well for me.

wintry quarry
vocal fable
wintry quarry
#

1 - you're trying to modify the x component of a quaternion, which you shouldn't ever be touching really. Quaternions are not euler angles
2 - you're trying to modify a field on a copy of the struct returned by a property. This will do nothing, and the compiler is giving you an error to prevent you from accidentally just doing nothing
3 - you're trying to assign a whole quaternion to a single float
@vocal fable

vocal fable
#

what

wintry quarry
#

also clamping velocity with AddForce doesn't work all that well since the change in velocity is delayed until the physics simulation runs (which is later)

final kestrel
#

I put add force in Start since I got no friction. The issue with that is when player enters trigger It rotates but no force is applied to move its new forward.

#

Do I have to add another impulse on the new forward?

wintry quarry
#

as mentioned before it will be simpler to just modify the velocity directly

#

AddForce is additive

#

meaning if you want to cancel out a previous velocity you'd have to add a force cancelling it out and then another force in the nww direction

final kestrel
#

But when I modify the velocity directly my gravity does not work

wintry quarry
#

much simpler to just set the velocity you want directly

wintry quarry
#

It shouldn't affect gravity since the coide is not running constantly

#

only at this one particular moment

final kestrel
#

Sorry I also have a jump

#

I forgot to mention that

wintry quarry
#

how does the jump matter

#

I don't see how these things are connected

final kestrel
#

Setting the velocity prevents me from jumping

wintry quarry
#

only if you're doing it every frame

#

which again, I didn't think that's what we were doing

wintry quarry
final kestrel
#

Yeah it is just rotating my player in the desired direciton

wintry quarry
#

yeah, don't you want it to also change the velocity?

final kestrel
#

if changing the velocity means that player stops previous forward movement and switches to the new forward movement yes

wintry quarry
#

e.g.

        if(other.CompareTag("RotatorLeft"))
        {
            Quaternion rot = Quaternion.Euler(_leftRotation);
            _rb.MoveRotation(rot);
            _rb.velocity = rb.velocity.magnitude * (rot * Vector3.forward);
        }```
#

though rather than euler angles I would probably just do this:

        if(other.CompareTag("RotatorLeft"))
        {
            _rb.MoveRotation(Quaternion.LookRotation(Vector3.left));
            _rb.velocity = rb.velocity.magnitude * Vector3.left;
        }```
final kestrel
#

All right. So I also want to set the velocity in start?

wintry quarry
#

again it doesn't matter

#

AddForce or setting velocity in start, you'll get the same result

final kestrel
#

The rotation is working perfectly now

#

Can I send a video? A real short one

wintry quarry
#

why not

final kestrel
#

I'll first give the code just so you can see where I put the move.

wintry quarry
#

your jump and your move code are not really compatible

#

that's why your jumps are so harsh

final kestrel
#

If i put the move in start it works just fine

swift crag
#

well, you'll have a very hard time changing which way you're moving if you only set your velocity once (:

wintry quarry
#

right - because overwriting the velocity like this every frame is going to smother the normal physics simulation

final kestrel
wintry quarry
#

we don't really know what you're trying to do so it's really hard to make calls about stuff like that

final kestrel
#

I mean it works just fine atm

#

Let me explain it real short without stealing your time any longer. I am sorry i havent been clear..

swift crag
#

yes

final kestrel
#

As you can see in the video. I have a character which moves without input. There are box colliders checked as triggers on the turning points. What I want is that when I enter the trigger zone. I want my character to turn the way I want, for example left on the first trigger. I also want my character to jump when Space is pressed.

wintry quarry
#

i would just set the horizontal velocioty only in FixedxcUpdate

#

allow gravity to handle the vertical

final kestrel
#

I want the turning to be instant so I can move to my players new forward direction instantly.

wintry quarry
#

e.g.

void FixedUpdate() {
  Vector3 forward = transform.forward;
  float currentYVel = rb.velocity.y;
  Vector3 newVelocity = transform.forward * moveSpeed;
  newVelocity.y = currentYVel;

  rb.velocity = newVelocity;
}```
final kestrel
#

Okay this works

#

I will spend some time understanding what you did. Thanks for the help again. Sorry for not being clear enough

velvet pecan
#

Hi all, does anyone know how to fix this things? or at least tell me how this issue is called so i could google it please.

rare basin
#

not code related question

swift crag
lunar grove
#

Which part should I apply a script when checking for the no. of enemies in a scene then doing something after they all get destroyed?

rich adder
#

if list count <= 0 then you killed all enemies

lunar grove
#

Ok but where do i attach that script though?

rich adder
#

any gameObject would do

#

call it EnemyTracker or something

lunar grove
#

Ah I see i think ill just attach it to the room where they spawn

rich adder
#

yeah any would do, as long as you can reference it to remove elements

lunar grove
#

also is there a way to hide and disable a gameobject and vice versa?

#

do ij ust use gameobject class?

rich adder
#

yeah is just gameObject.SetActive(false)

lunar grove
#

does that include its visibility or?

rich adder
#

if you set it inactive yeah it becomes not visible

lunar grove
#

then doing it vice versa makes it visible and activates any scripts attached to it?

rich adder
#

yea

#

Awake/Start wont run tho

#

if they ran before

lunar grove
#

Ok thank you very much for your replies!

lunar grove
rich adder
# lunar grove Oh okay!

if you ever want to do anything on disable/activation

You can use OnDisable/OnEnable methods respectively

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

public class Rotator : MonoBehaviour
{
    Rigidbody _rb;
    Vector3 _leftRotation = new Vector3(0, -90, 0);
    Vector3 _rightRotation = new Vector3(0, 90, 0 );
    private float _moveSpeed;
    // Start is called before the first frame update
    void Start()
    {
        _rb = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {

    }

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("RotatorLeft"))
        {
            Quaternion rot = Quaternion.Euler(_leftRotation);
            _rb.rotation = Quaternion.Euler(_leftRotation);
            _rb.velocity = _rb.velocity.magnitude * (rot * transform.forward);
            
        }

        if (other.CompareTag("RotatorRight"))
        {
            Quaternion rot = Quaternion.Euler(_rightRotation);
            _rb.rotation = Quaternion.Euler(_rightRotation);
            _rb.velocity = _rb.velocity.magnitude * (rot * transform.forward);
            
        }
    }
}

Whichever rotation trigger I encounter first does its job. But when I try to trigger the next one, my rotations are messed up and player rotates to somewhere else.

wintry quarry
lunar grove
tawdry rock
#

How can i update textmeshpro's text field? (non UI)
I placed a simple TMP above the character that display its HP and it seemslike its not working as the legacy text used to work. (hpNumber.text = enemyHP.ToString();) . im also imported using TMPro;

rich adder
wintry quarry
tawdry rock
rich adder
tawdry rock
#

The middle one

rich adder
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

tawdry rock
#

one sec.. let me clean it up 😄

final kestrel
#

I only know what quaternion identity means. The rest needs researching. I will activate my neurons.

tawdry rock
rich adder
tawdry rock
wintry quarry
rich adder
#

if thats the erro you got

#

hpNum = GetComponent<TextMeshPro>();
Specifically looks for TextMeshPro on this script/object

tawdry rock
rich adder
final kestrel
final kestrel
#

all right thanks.

wintry quarry
#

This is also not the desired rotation, it's an amount we're going to rotate by

#

it's relative to the object's current rotation

#

another good name would have been rotationToApply or rotationToAdd

final kestrel
#

ch_cattokiss got it.

tawdry rock
rich adder
#

try to assign inside inspector when possible

#

avoid GetComponent when possible

tawdry rock
#

Wait. It's working but still gets refference error

rich adder
#

maybe you have a copy somewhere with unassigned field?

tawdry rock
rich adder
#

also a good lesson to start separarting scripts functionalities 🙂

#

ie your HP script should not be mixed with your ragdolling stuff & watnot

tawdry rock
#

Yea its all good now.

tawdry rock
rich adder
tawdry rock
rich adder
#

!learn

eternal falconBOT
#

🧑‍🏫 Unity Learn can offer you over 750 hours of free live and on-demand learning content for all levels of experience! Make sure to check it out at https://learn.unity.com/

rich adder
#

oh

bleak nexus
#

i just deleted and put it in code-general

royal osprey
#

can anyone help?
got this problem where 1 unit in other got a visual bugs
how can i fix it?

cosmic dagger
rich adder
cosmic dagger
royal osprey
#

they need to be like 1 on 1 +- like 1 pic
but they are going inside them, like 2 pic where gray body up costumed guy or pic 3 where in left side we see knife and glasses what on costume guy, but gray guys up him, and they need to close a costume guy
(hope you understand, sorry for my English)

thick goblet
#

I have this issue where when my RedBall collides with my player from the sky it subtracts 1 heart (0.5f) damage but sometimes it subtracts 2 but I want it to remain consistent and subtract 1. Can anyone help please? Here are the scripts: https://gdl.space/eyoyuheyad.cs
startingHealth = 5 in PlayerHealth script *fixed

lofty sequoia
#

Is there a way at runtime to assign the render camera to a canvas using screen space camera mode?

wintry quarry
#

use Debug.log and see how many times it's running and how much damage it's applying

thick goblet
#

Doing that rn

#

ty

lofty sequoia
#

I tried assigning world camera to the main camera but I don't see it updating the render camera in the inspector at runtime

kind gazelle
#

does anyone know how to make a VR HUD?

thick goblet
#

Fixed is Praetor thanks

#

it*

placid solstice
#

So i'm having this issue when spawning enemies, I am trying to randomly spawn enemies of different types and some times they render on top of each other. This is my spawning script

// Start is called before the first frame update
[Header("Spawner Settings")]
[SerializeField] public float spawnRate = 1.0f;
[SerializeField] public int enemyCount = 1;
[SerializeField] public GameObject[] enemies;

private int roundTimer = 120;

void Start()
{
    StartCoroutine(Spawn());
}

// Update is called once per frame
private IEnumerator Spawn()
{
    WaitForSeconds wait = new WaitForSeconds(spawnRate);

    while (roundTimer > 0)
    {
        roundTimer--;
        for (int i = 0; i < enemyCount; i++)
        {
            int choice = Random.Range(0, enemies.Length);
            GameObject enemy = enemies[choice];
            Instantiate(enemy, transform.position, Quaternion.identity);
        }

        yield return wait;
    }
}
#

when the enemies spawn they move towards the castle, how would i flip the sprite to face the castle

lunar grove
#

Apparently for the Gameobject class to instantiate the game object it has to be set to active in the scene, then just deactivate in start method later to make it disappear lol, cant believe i took like 30 mins for that lmao

wintry quarry
#

Also Instantiate is part of the UnityEngine.Object class, not GameObject

wintry quarry
placid solstice
lunar grove
#

for the script to read it

#

before i had it unchecked

#

for whether it was active or not

rich adder
lofty sequoia
#

Solved the camera issue - it couldn't find it in Awake, but it can in Start()

rich adder
#

i think

wintry quarry
#

if you want to wait inside the loop, you obviously have to wait inside the loop

lunar grove
#

hmm weird

wintry quarry
#

Instead you should just use a direct reference, and to a prefab not to an object in the scene.

#

If I understand your issue correctly

lunar grove
#

The code works in the start() method

#

however trying to change it in the update() method doesnt work

wintry quarry
#

what code

#

you're still being really vague

lunar grove
#

Enabling and disabling the activity of a gameobject

#

sorry lol

wintry quarry
#

still vague

#

if you want help with code, share the code in question

#

and explain what errors and/or wrong behavior you are encountering.

lunar grove
#

um ok wait how do i share code to look like in code format

wintry quarry
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

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

public class EnemySequence : MonoBehaviour
{
    private GameObject[] normalEnemyLeft;
    private GameObject bossEnemy;
    void Start()
    {
        normalEnemyLeft = GameObject.FindGameObjectsWithTag("Enemy");
        bossEnemy = GameObject.Find("BossEnemy");
        bossEnemy.SetActive(false);
    }
    // Update is called once per frame
    void Update()
    {
        if (normalEnemyLeft.Length < 1)
        {
            bossEnemy.SetActive(true);
        }
    }
}
#

I'm trying to activate a boss gameobject when 4 enemies have died

polar acorn
#

You're setting it once in Start and then never changing it

wintry quarry
#

Like I said you're using GameObject.Find and that's your problem

#

if you did a direct reference you would not have this issue

#

Change private GameObject bossEnemy; to [SerializeField] private GameObject bossEnemy;
Then just drag and drop the boss into the slot in the inspector this creates. Then delete these lines:

        bossEnemy = GameObject.Find("BossEnemy");
        bossEnemy.SetActive(false);```
#

and you can leave it as inactive in the editor

#

also yes Digi is correct about the enemy count tracking.

placid solstice
wintry quarry
placid solstice
#
private IEnumerator Spawn()
{
    while (roundTimer > 0)
    {
        for (int i = 0; i < enemyCount; i++)
        {
            int choice = Random.Range(0, enemies.Length);
            GameObject enemy = enemies[choice];
            Instantiate(enemy, transform.position, Quaternion.identity);
            yield return new WaitForSeconds(spawnRate);
        }

        roundTimer--;
    }
}
lunar grove
lunar grove
wintry quarry
polar acorn
placid solstice
wintry quarry
placid solstice
#

2 points

lunar grove
placid solstice
#

i found the issue

#

apparently one of the points had 2 spawner scripts on it

covert matrix
#

having an issue where the canvas appears lower than where it should be when running the game

queen adder
#

How do I give sounds reverb?

rich adder
wintry quarry
covert matrix
#

thank you

queen adder
#

things get super small and in the wrong place when i build

#

which one...

covert matrix
#

"make sure scalre with screen is selected"

queen adder
#

that's all?

rich adder
queen adder
#

shrimple setting change

#

oh yeah, one more thing

#

this prefab is a little bitch and the movement thing isn't centered on it

#

unlike literally everything else

#

why is that

swift crag
#

oh so THAT'S why that toggle was randomly changing

#

and X toggles local/global

#

i'm not losing my mind

buoyant knot
#

I think I have a weird case.
I have a trigger with OnTriggerStay and OnTriggerExit. OnTriggerStay calls a function to destroy a gameobject that touches the trigger. The weird thing I think I'm seeing is: OnTriggerExit gets called IMMEDIATELY in that line in OnTriggerStay where the object gets destroyed. Is this supposed to happen?

queen adder
regal kayak
#

I'm trying to make a prefab stop all movement when it touches my player, I tried coinRB.velocity = Vector2.zero; but it still moves after hitting my player.

swift crag
#

first, check if your code is even running

#

Debug.Log("Hello"); would be sufficient

#

second, consider what could move the rigidbody after you've set its velocity

#

if it's not kinematic, then it's going to get pushed around by physics

regal kayak
#

and I dont think anything else is moving it, but if it was, what could I do to stop that?

swift crag
#

well, the player is probably touching it at that point

#

so there's your source of force

buoyant knot
#

is it a dynamic rigidbody or kinematic?

regal kayak
buoyant knot
#

ok, so setting velocity = 0 doesn't stop everything that could move the rigidbody

#

other forces like gravity, friction, etc can still work on it

#

also, if you have other parts of your code using .AddForce or setting the velocity in some way, then you can also get it moving again

regal kayak
#

is there a way I can stop the object and make it so nothing else can act on it?

lime leaf
#

Hey everyone! I am new to game development and would like to get a career in it. Can anyone recommend any good resources for learning?

buoyant knot
# lime leaf Hey everyone! I am new to game development and would like to get a career in it....

GMTK is powered by Patreon - https://www.patreon.com/GameMakersToolkit

Unity is an amazingly powerful game engine - but it can be hard to learn. Especially if you find tutorials hard to follow and prefer to learn by doing. If that sounds like you then this tutorial will get you acquainted with the basics - and then give you some goals to learn ...

▶ Play video
lime leaf
#

Thank your

buoyant knot
#

force send = this object can apply force to anything in those layers (currently set to everything) that it can collide with.

#

force receive is the same, but to receive forces from other objects

#

if I have layers 1,2,3. And 1-2 touch each other, 2-3 touch each other, and 1-3 do NOT have collisions. Then I can set an object to Layer 1, and it will automatically only collide with layer 2, and ignore layer 3 objects

#

If, in my code, I set this layer1 object's collider force receive layers to 0, then this object will no longer take forces to get pushed around by anything.

regal kayak
#

I see, thanks

late yew
#

probs a dumb question, but why isn't this scriptable object creating a drop-down for me to select the typing?

swift crag
#

you've declared a type

#

but you haven't actually given CritterType any members

#

all this does is declare CritterType.Typing to be an enum with the values you listed

#

public Typing myType; would add a field to CritterType

late yew
#

do I need to do ienumerable?

#

oh, right

swift crag
#

this is almost identical to writing

late yew
#

hmm

swift crag
#
public class CritterType : ScriptableObject { }
public enum Typing { ... }
late yew
#

that's embarassing lol

swift crag
#

Nesting a type has some effects (it can access private members of the enclosing type)

#

but in this case, it strictly just means the type is named CritterType.Typing instead of Typing in any context outside of CritterType

late yew
#

I'm trying to figure out the best practice of having a reference to typings/elements that other things can reference so I don't need to put enums in all of the scripts and see if they match in functions

#

so I was thinking having a scriptable object of each 'typing' would work, and then I can just parse the scriptable object reference for my checks

swift crag
#

What would the SO achieve other than holding an enum?

#

You could make it so that each type is defined by an SO asset

late yew
#

nothing, but I tried to do this whole convaluted system of comparing enums from scriptable objects to strings, or something

swift crag
#

you should not have to compare to strings at any point

late yew
#

right

swift crag
#

if (enemy.mainType == move.type) would compare two enums for equality

#

now, you could make an SO that defines an entire type

#

so

#
public class CritterType : ScriptableObject {
  public string typeName;
  public Color color;
  public List<CritterType> strongAgainst;
  public List<CritterType> weakAgainst;

  public float DamageMultiplierAgainst(CritterType target) {
    if (strongAgainst.Contains(target)) return 2f;
    if (weakAgainst.Contains(target)) return 0.5f;
    return 1f;
  }
}
#

You would then deal entirely in references to assets

late yew
#

the simplest way to explain what I want to achieve is to create a pokedex - current thought process is to have the Typing SO so I can have an array of the typings assigned to each 'pokemon'

#

I understand I could also have the enum in the 'pokemon' SO along with all the other info and have two 'typing' fields, but then I don't know what I'd do for the second if it's a 1-element like pikachu

#

I'm worried that leaving it blank could cause issues later on

swift crag
#

If you used an enum alone, then you would need to have a "No Type" enum value

#

Alternatively, you could just use a list of enums

#

so that a monotype creature simply only has one type

late yew
#

I had considered that, but I read online that you shouldn't use enums in a list - they didn't state why

swift crag
swift crag
#

but

#

enums do have one headache: they aren't serialized by name, but rather by value

#

so, if you rearrange your enum values, all of your data gets screwed up

#

you have to assign explicit values to them to prevent that

#
public enum Stuff {
  Foo = 0,
  Bar = 1,
  Baz = 2
}
#

you could then safely update this

#
public enum Stuff {
  Baz = 2,
  Foo = 0
}
#

it's kind of ugly

late yew
#

hmm

swift crag
#

If you used ScriptableObject assets, then you'd just need to make sure you...don't randomly delete the assets

late yew
#

lol

swift crag
#

note that moving assets around and renaming them is fine

#

unity understands that it's the same asset

late yew
#

I think I'll try the typing enum in the SO and then having like

#

Typing TypeOne
Typing TypeTwo

#

and see if i run into issues later

swift crag
#

as in, one SO asset for each creature?

faint osprey
#

hey so i have my player riding a gameobject that moves and changes rotation respective of the mouse movement however when my player gets on the whole thing breaks down and spins all over the place anyone got any ideas

late yew
late yew
#

and then have the same enum setup for the moves SO

hidden citrus
#

What's a good way to "check distance between multiple objects, and get shortest distance to player"?
Essentially iterate through the array/list for distances relative to player, then picking shortest (respawnPoint[i].position, player.position)

wintry quarry
late yew
#

how do you do the coding thing again

#

i always forget

#

the little box

wintry quarry
#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

hidden citrus
swift crag
#

oh wait, wrong algorithm!

#

I was thinking of closest pair

wintry quarry
swift crag
#

not just finding the closest point to an arbitrary point

wintry quarry
hidden citrus
#

like <RespawnWaypoint> has a "vector3 position" field, which registers on awake. Then my function calls "look for nearest" and gets the respawnWaypoint[i].position

swift crag
#

but this isn't closest pair; it's just closest point

late yew
#
    public void FindNearestWaypoint()
    {
        RespawnWaypoint[] objects = FindObjectsOfType<RespawnWaypoint>();
        float closestDistance;
        Transform closestRespawnWaypoint;

        foreach (RespawnWaypoint obj in objects)
        {
            float distance = Vector3.Distance(player.position, obj.transform.position);
            if (distance < closestDistance)
            {
                closestDistance = distance;
                closestRespawnWaypoint = obj.transform.position;

            }
        }
    }
hidden citrus
#

the respawn manager is the one throwing out the signal to see "what is closest to me"

hidden citrus
late yew
#

its missing uhm

#

a transform reference

#

1 sec

hidden citrus
#

is the transform within the waypoint class as a field? like self registering as i mentioned above?

late yew
#

that should work i think

hidden citrus
#

closest distance looks like its the "variable which gets updated" based on the distance info, but running some kind of comparison

late yew
#

I updated it

hidden citrus
#

ok checking

#

looks like a vec 3 to transform mismatch

ashen ferry
#

u need to initialize local variable to something

hidden citrus
#

ignore the player position, the closest distance thing is the issue

ashen ferry
#

float closestDistance = float.Infinity or what that is I forgor

hidden citrus
#

ah yep gotta assign a value, float closest distance has 0 info

late yew
#

^ mb

ashen ferry
#

also idk about that FindObjectsOfType I would drag in references if respawn points are already known if not make them register themselves to the respawn manager in awake

hidden citrus
slender nymph
#

what type is the closestRespawnWaypoint variable?

hidden citrus
late yew
#

can you do just .transform

hidden citrus
#

sec lookin over the code

late yew
#

obj.gameObject.transform.position maybe

#

no? xD

hidden citrus
#

says its a transform defined above, gotta convert it to a field by the looks of it

slender nymph
#

what? no. you just need to give it the transform not the transform's position. unless it's the position that you need in which case your variable is the wrong type

hidden citrus
ashen ferry
#

it could stay local if you use it right then and there that wasnt the problem

hidden citrus
#

that seems like no errors, though i probably need a field array for "objects" right? like a field, not a temp variable

#

then have it self register (waypoints self add themselves to the array/list on awake)

slender nymph
#

yes, that would be better than using FindObjectsOfType. but you'd want it to be a List not an array since arrays are not resizable

hidden citrus
#

gotcha, yeah ive been using lists as of late, they are very useful

#

ait giving it a shot now

slender nymph
#

also the name implies it should be returning the nearest waypoint rather than assigning it to a field. so you should return either the transform or the vector3 position

#

then both closestDistance and closestRespawnWaypoint can go back to being local variables. and closestDistance should be assigned to float.MaxValue not 0

hidden citrus
#

ah i think im following, but the other issue is "assign the list position index as the "spawn anchor" point"

#

sec, trying to process that

#

ah, so would i return the waypoint class (so i can get the anchor point WITHIN the class)?

#

I want to access a field WITHIN the nearest class detected

slender nymph
#

if that it the type you need, then yes

hidden citrus
#

yea rather than the parent object, if i moved it up/etc for visual reasons

#

public RespawnWayPoint FindNearestWaypoint() correct?

slender nymph
#

if you need to return the RespawnWaypoint object instead of a Transform, then yes

hidden citrus
#

quick edit

#

looking at your notes above*

slender nymph
#

now make those two other variables local variables again and instead of that long ass line for the return you could just assign obj.respawnAnchor to it in the if statement

faint osprey
#

hey so i have my player riding a gameobject that moves and changes rotation respective of the mouse movement however when my player gets on the whole thing breaks down and spins all over the place anyone got any ideas

hidden citrus
#

hmm geting s tuck on the return part

wintry quarry
#

why do you have two dots

hidden citrus
#

the format specifically, of what specifically im trying to grab the componet off of

#

mb sorry that was a quick edit

slender nymph
hidden citrus
slender nymph
#

assign null on the line you declare it

sage mirage
#

Hey, guys! I have a problem. I am attending now the Junior Programming Pathway and I have 2 scripts first called Unit second ProductivityUnit and I have the second one inherit from the Unit. I have got a method inside my Unit script that is called BuildingInRange and for one reason when I want to override it in order to do some modifications in my method in Unit Script i ve got an error. I have declared 2 variables in ProductivityUnit script first m_CurrentPile and ProductivityMultiplier the first one variable has a class ResourcePile on it, so it says in my method when I want to override it that it does not exist in the current context. I am sending scripts rn

hidden citrus
#

        public Transform FindNearestWaypoint()
        {
            Transform closestRespawnWaypoint = null;
            float closestDistance = 0;
            foreach (RespawnWaypoint obj in objects)
            {
                float distance = Vector3.Distance(PlayerObject.Instance.transform.position, obj.transform.position);
                if (distance < closestDistance)
                {
                    closestDistance = distance;
                    closestRespawnWaypoint = obj.transform;
                }
            }

            return closestRespawnWaypoint.GetComponent<RespawnWaypoint>().respawnAnchor;
        }
slender nymph
#

can you please read all of the info that has been provided to you before making a change and asking for further help

late yew
hidden citrus
late yew
swift crag
#

oh, you have two completely unrelated Typing enums.

late yew
#

yeah

swift crag
#

just declare it once.

#

use it everywhere

sage mirage
late yew
#

where would I do that?

swift crag
#

just..anywhere

#

maybe a separate file

slender nymph
wintry quarry
swift crag
#

public enum Foo { } does not declare a field. It declares a new type.

wintry quarry
#

Typing.cs

#

I would probably call it CritterType or something though

#

Typing is a confusing name

sage mirage
slender nymph
#

no, it was clearly in response to the person whose message came after yours (and directly preceded my message) whom i was already in a conversation with

wintry quarry
late yew
#

is there any benefit to making it a scriptable object like i had planned in the past? my thought process is I can assign them sprites for the logos and hex codes to colour sprites they're meant to affect

sage mirage
#

Minute

wintry quarry
#

You probably still want the CritterType enum though

sage mirage
#

Here is what I have in ProductivityUnit.cs

{
    protected ResourcePile m_CurrentPile;
    protected float productivityMultiplier = 2f;
}```
late yew
# wintry quarry You probably still want the CritterType enum though
[CreateAssetMenu(fileName = "New Critter", menuName = "ScriptableObjects/Critter Typing")]
public class CritterTyping : MonoBehaviour
{
    public enum Typing { Beast, Fire, Water, Wind, Earth, Nature, Thunder, Spirit, Elemental, Aura, Martial, Toxic }
    public Typing type;
    public Sprite typeIcon;
    public string hexCode;
}
sage mirage
#

So, what happened is the m_current var and productivity multiplier are underlined with red

late yew
#

something simple like that maybe

wintry quarry
#

All ProductivityUnits are Units
Not all Units are ProductivityUnits

#

So Unit cannot do things with fields from ProductivityUnit

#

it doesn't make sense

wintry quarry
wintry quarry
#

not MonoBehaviour

late yew
#

yeah i forgot to change that

wintry quarry
#

and I still recommend declaring "Typing" in its own file

late yew
#

this is its own file

slender nymph
#

no, that's your scriptable object's file (or will be once you swap to SO from MB)

#

you've nested the enum inside your CritterTyping class. move it out of that

swift crag
#

you're having trouble keeping it straight from CritterTyping

#

just call it CritterType. Its values are valid types for a critter.

late yew
#

right, i need it in it's own file for move references

swift crag
#

no, this is not about files

short hazel
#

Enums are types, like classes and structs. They can be put alone in their own file, and you should do that if the type is used in 2 or more places

swift crag
#

this is strictly about names.

sage mirage
proven charm
#

in the engine is sais i aint using isGRounded(its a bool)

wintry quarry
#

See these squigglies

#

you should read what they're telling you

#

Let me ask you this - if you have:

bool x;

And you want to assign the value 5 to it on the next line of code, what would you write?

x = true;```
or
```cs
bool x = true;```
proven charm
#

isGrounded is a bool

wintry quarry
#

bools are not a special type that work differently from everything else.

#

there I changed the example

proven charm
#

ik

#

the second one

wintry quarry
#

you sure?

#

you rewrite the type of the variable every time you want to assign it?

summer stump
proven charm
#

i realised

#

its bc

#

i put bool before isgrounded in on collosion stay and exit

wintry quarry
#

yes

#

when you do that you are actually creating a brand new variable (a local variable inside the function)

#

and the original variable is unaffected

proven charm
#

ye

summer stump
eternal needle
faint osprey
#

how do i make a game object rotate on the spot with moving my mouse as to how much it rotates

slender nymph
#

can you rephrase that in a way that makes sense?

buoyant knot
#

have you tried holding alt while in panning mode?

faint osprey
#

so im in 3d third person view and i want a cylinder to spin on the spot by how much i look around with my cameras

buoyant knot
#

alt + drag with click

faint osprey
#

no not in scene view

modest dust
#

Basically rotate the cylinder whenever you move your mouse in-game, right?

buoyant knot
#

you'd need to tie the rotation of the cylinder to the mouse via code

modest dust
#

^

buoyant knot
#

you basically need to code: everytime I move the mouse, I'm going to interpret it as a command to rotate by X. Then I'm going to rotate the cylinder by x

#

either by its transform, or applying torque to a dynamic rigidbody

uneven swan
#

guys I just realised I was dying trying to get an IEnumerator to count down while the time scale is set to 0 are there any work arounds to count down ?

slender nymph
#

show the code so the issue can be pointed out

uneven swan
#

thanks mate forgot that the count realtime seconds existed I don't think I ever had to use it

midnight echo
#

https://hastebin.skyra.pw/jizutuqaqi.java Hi I wanted to ask. I currently have this code from a tutorial, and I tried to apply it to a 3D model's torso and I was wondering how I would change this such that the torso properly follows the mouse?

bold portal
#

Anybody know why StartNetwork as Host keeps crashing the Unity editor? I have literally never had this issue until yesterday when I started up my game for another edit session.

slender nymph
#

define "craching the unity editor"

bold portal
#

There is a video for help 🙂

#

It's not really a normal crash.

slender nymph
#

most likely you have an infinite loop

bold portal
#

For Start Network as Host?

slender nymph
#

no, in your own code when you start the network

wintry quarry
#

The audio still playing is another hint that the main thread is blocked actually. Audio runs on a separate thread.

#

so the runtime is not crashing

#

but the main thread is blocked

bold portal
#

Odd. The thing was working before, and when I started it up again this happened. I didn't change anything after the last time it worked

wintry quarry
#

you didn't change anything that you remember or that you think mattered

bold portal
#

Like, I saved and quit, and then got on and this happened

eternal needle
#

thats always the classic, "i didnt change anything". you should use version control if you arent, which would prove if you have changed something

wintry quarry
bold portal
#

I'm not going to ignore this advice though. I shall go check out the code and look for infinite if or while loops

bold portal
#

So I am going to start with finding loops

bold portal
#

Oh hey I already have that attached 👍

sick matrix
#

can anybody help me? My question isn't about programming, but I don't know which channel to send this specifically

#

I'm making a procedural system for my game, how can I create a separate tile?

bold portal
#

So I guess I just need to look at it

short hazel
#

The nice thing about having the debugger attached, is when you hit the infinite loop somewhere, you can pause the execution by hitting the "stop all" button and see where the execution is at that point

bold portal
#

It's gonna be just my luck that I did in fact change something. Time to go see 🤦‍♂️

#

MY GOSH WHERE DID THAT WHILE LOOP COME FROM?!

short hazel
#

git blame
You, 3 days ago - commit 8bfe346

bold portal
#

🤣

polar acorn
bold portal
#

Thanks. I shall pin this legendary quote to my wall above my PC. I am just relieved that my game isn't corrupted where I have to revert to an old version. I was about to backup this copy when this happened. 🤣

slender nymph
#

time to learn how to use version control like git

#

!code

eternal falconBOT
#
Posting code

📃 Large Code Blocks
Large code blocks should be posted as links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/
https://paste.myst.rs/, https://hastebin.com/

📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To get C# formatting the first line should only contain cs or csharp.
Add a comment with a line number if there is an error message.
```cs
// Your code here
```
Do not share screenshots of code unless requested.

unkempt locust
#

Guys, I have a problem, I went to import Starter Assets first person from Unity, and so far everything was fine, but after I imported a PREFAB, unity crashed, then when I logged back in, the whole map was purple, Then I saw on YT what I should have done, to import the first person, I should have configured Render Piperline first, now the first person is working, but the map is all purple, can you help me?

short hazel
unkempt locust
#

ok

unkempt locust
short hazel
#

I do not know how to solve your issue

#

I'm a developer

queen adder
#

hey, two questions

#
  1. how can i add reverb to sound effects?
#
  1. how i can prevent sound effects from cutting each other off?
unkempt locust
queen adder
#

oh and where do i store them haha

#

having each sound be its own gameobject seems... suboptimal

short hazel
#

You'd play them via code, with the PlayOneShot() method, that one allows overlapping of sounds

queen adder
#

yep that's how i'm doing it, except need to apply reverb to it

short hazel
queen adder
summer stump
summer stump
queen adder
#

yeah that's what i did

#

i just needed individual gameobjects to organize them

summer stump
short hazel
#

Well it's still referencing the objects here

summer stump
queen adder
#

but if i have a bunch of sounds this is gonna be a pain

summer stump
#

That's what I meant

short hazel
#

Usually you'd have one field of type AudioSource and a few fields of type AudioClip yes

queen adder
#

Idk what a clip is Lol

summer stump
short hazel
#

You can separate the fields in the editor with [Space] or [Header("Name")] if it gets too messy

queen adder
#

ok,

summer stump
#

public AudioClip footstepSound;

queen adder
#

oh that's not allowed

#

1984

#

anyway let me be clear

#

if every single sound effect in the game requires its own gameobject, that is really gonna suck

#

i'd like to not do that

#

but it's the only way i can figure out

summer stump
#

Single object, multiple AudioClip variables

queen adder
#

you have now told me an alternative option

#

i dont see

summer stump
short hazel
#

In your code!

#

Then you drag drop the sound file from your assets

summer stump
queen adder
#

Oh I Have Small Brain I Didn't Realize That it Wasn't A Component

queen adder
crisp pollen
#

How an i make Object snap to grid when in the 2D mode

wintry quarry
#

2d mode just enforces a camera angle for scene view

crisp pollen
#

okay ty

queen adder
#

...why the hell does adding an AudioSource to my charactercontroller cause my fps to halve

#

That's it

#

Changing nothing else

#

If I remove it the performance is normal

slender nymph
#

are you certain it is just the audiosource causing the issue and not perhaps some code you're running?

queen adder
#

no code references it

#

if i create any audiosource anywhere fps tanks

wintry quarry
#

or the inspector for the audio source

queen adder
wintry quarry
#

Rigidbody has a famously slow inspector

slender nymph
#

yeah you should use the profiler to determine the actual source of the issue

queen adder
#

if I also press any input keys fps tanks

#

wtf

#

but only if I have audiosources

#

¯_(ツ)_/¯

#

idk what any of this means

ashen ferry
#

Noone does kekW

#

Look at hierarchy not timeline

#

On the left in the middle there should be button

queen adder
#

There you go

slender nymph
#

yep, looks like it's the editor, not the actual audio source

queen adder
#

how do i fix this?

#

it was not a problem until now

ashen ferry
#

U can change to editor mode to profile editor

queen adder
#

?

ashen ferry
#

Play mode button there

green copper
#

So, my physics material looks like this and is attached to my character controller like so, it moves as expected.

When a moving sphere, with the same physics material, hits the bumper, it loses all velocity towards the bumper and starts drifting to one side or the other depending on the angle of impact.

Expected behavior is that velocity is preserved and it bounces, behavior can be observed when ball hits the walls of the arena.

#

the "Bouncy" material is on the ball, the bumper, and the wall, but ball-bumper collisions exhibit this problem

solid timber
#

Hey, I have an object (A) that I want to be IsTrigger so that I can check when it is colliding/touching another object (B) without physically interacting.

But I need the object (A) **not **to be "IsTrigger" with other objects (C which is ground) so it can stand on something.

Is this possible?

late burrow
#

whats the easiest way of refiling holes in mesh after removing bunch of polygons from it

slender nymph
polar acorn
late burrow
#

no i want the holes

celest spindle
#

Does anyone know how to separate these? Like the dark green thing en the light green squares. These r the codes

slender nymph
celest spindle
#

Ohhhh

#

Oopthy

#

Sorry

#

😭

queen adder
celest spindle
#

Bye🫡

late burrow
#

but the holes with texture in newly made hole not the missing faces

#

i thought about moving polygons instead of deleting them but would be hard to figure out where to move it to be inside mesh still

solid timber
slender nymph
#

does the parent object have a rigidbody? if so, then yes. all children colliders will become part of the rigidbody's compound collider and will have physics messages like OnCollisionEnter sent to the rigidbody

unique violet
#

what code would I do to make this red UI's y position 0? I've tried this but it doesnt go anywhere close:

remove.GetComponent<RectTransform>().position = new Vector3(1311.7f, 0, 0);
solid timber
# slender nymph does the parent object have a rigidbody? if so, then yes. all children colliders...

Yes the Parent has a Rigidbody, and the parent has a Box Collider that is not isTrigger.

The parent carries the script with the OnCollisionEnter().

The Child has a Box Collider that is isTrigger only. And is on a separate layer.

Inside the Parent script I am just running this;
`
private void OnCollisionEnter(Collision collision)

{
    Debug.Log(rb.name + "colliding with " + collision.collider.name);`
#

But it doesn't detect collision with other object it seems 🤔

slender nymph
late burrow
#

so how can i make hole in mesh that will not be missing faces in hole i made

frosty hound
#

At runtime? Complicated procedural mesh.

junior mango
#

can someone explain why the materials dont load when i import a package and how do i fix it

karmic badger
#

Is there any Error messages when you imported? Have you restated?

#

ReStarted

frosty hound
#

The package is using shaders not compatible with your render pipeline.

late burrow
#

i did wanted do that because thats how im editing out vertices to make hole in first place

junior mango
late burrow
#

but im not sure how to auto fill the missing faces

polar acorn
junior mango
karmic badger
#

URP package?

karmic badger
#

Try installing universal rp

#

From package manager

junior mango
karmic badger
#

🤔

#

🤷🏻‍♂️

junior mango
#

making sure this is urp right

summer stump
junior mango
#

i took off urp and all the things loaded 👍

#

ty

solid timber
# slender nymph https://unity.huh.how/physics-messages

Thanks for the help, it seems like even with Physics messaging and a breakpoint I am not getting a response.

But I will investigate cause I really like the concept of having a child collider that acts as just a trigger, it would be amazing if I could get it working.

slender nymph
#

did you go through the rest of the steps to make sure you have your rigidbody and everything set up correctly?

wary sable
#

hello,
I'm making a simple segment of my inventory system where the player can hold down left click to rotate a model of their player in the inventory screen. I want to make it so that the rotation has a bit of energy (that is to say that spinning the camera will increase its velocity so when the player lets go the model spins just a bit) how would I go about doing this? Here is the script I have so far https://hatebin.com/gnisfntzss

#

I should note that this system uses a second camera in the scene that is tied to a pivot which is tied to a G.O tied to the player. The pivot is what rotates around the player giving the illusion that the character "model" is the real thing

EDIT:
Figured it out, just add a rigidbody to the game object, and then use .AddTorque. It works in a very similar way to updating a quaternion without multiplying.

solid timber
#

Here is my Gameobject hierarchy.

Green contains Script + Box Collider without isTrigger + Rigidbody.

Cube contains just the mesh, a cube.

InvisCollider contains the second Box Collider with isTrigger.

slender nymph
#

show the inspector for the collider and also the rigidbody

slender nymph
#

okay now show the layer matrix in the Physics settings

solid timber
slender nymph
#

okay and now show the object that it should be colliding with

solid timber
slender nymph
#

well the Cards layer can collide with the Cards layer so that is fine. do you see it actually reacting to collisions in the game? like the objects are physically colliding?

solid timber
slender nymph
#

okay so this whole time the issue has been the triggers?

#

are you sure you read the site i linked? because trigger colliders do not send an OnCollisionEnter message because they are not entering a collision

#

you should be using OnTriggerEnter for trigger colliders

unique violet
#

How can I completely stop my game? basically making it so nothing happens and I can't do anything until I reset the app

unique violet
#

well I don't wan to crash it I just want to stop it

solid timber
slender nymph
#

OnCollisionEnter is for entering collisions like when two non-trigger colliders begin colliding. OnTriggerEnter is for when any collider enters a trigger collider

solid timber
eternal needle
hollow zenith
#

How would I go about creating a sliding 2D platformer character with various shapes?
Something like this:
https://springboard-cdn.appadvice.com/generated-app-plays/443637419/148302848-quarter-apng/med.png
Can it be done with built in physics system using gravity to speed up the player and slopes being 99% or 100% slippery(so you can go up the slope)
Basically you need to gain speed faster when you go down than you lose it when you go up if that makes sense.
I am open for ideas tho as I am not sure what are my options.

#

The link has an animation if you want to see it play out.

#

Perhaps I need a script that gives player speed when you slide downwards + forward

timber tide
#

Should be fine with rigidbodies and unity's physics

wintry quarry
#

the spline can also be used for the grounded-ness check. e.g. the position of the spline at that point is the lowest allowable y position for the penguin

timber tide
#

I was thinking maybe some techniques to make the level in a paint program then rasterize it all in unity

wintry quarry
#

SpriteShape also has a built in spline framework too

#

and can be used for worldbuilding here as well as the physics sim

covert matrix
#

hi im trying to fix an issue where my character is stuck in a walking down animation after going down a certain point

rich adder
covert matrix
wintry quarry
wintry quarry
wintry quarry
#

meaning when you actuall release the input, it won't run at all

#

so it will never stop

#

shouldn't you move that outside of that if?

covert matrix
#

oh but if i stop before reaching that point thats low enough, i can still move again

wintry quarry
#

Then your other problem might be while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)

#

you should add Debug.log inside the Move coroutine and make sure it's actually finishing

#

you might be stuck in the loop permanently

covert matrix
#

like this ?

    {
        isMoving = true;

        while ((targetPos - transform.position).sqrMagnitude > Mathf.Epsilon)
        {
            transform.position = Vector3.MoveTowards(transform.position, targetPos, moveSpeed * Time.deltaTime);
            yield return null;
        }
        transform.position = targetPos;

        isMoving = false;

        Debug.Log("Movement finished");

    }```
wintry quarry
#

sure - but you probably would want to put a "movement started" one too

covert matrix
#

i see neither of the messages appear on the console

#

oh nvm, im not sure how but it fixed itself?

#

thanks for the help!

gusty void
#

Hi I keep getting a CS0103 saying the name of bulletpoolInsstanse does not exist in the current context
In my Fire bullets script, and I just cannot figure out why this is happening does anybody have an answer or way to fix this

north kiln
gusty void
#

Okay thank you, I put bullet pool with bulletpoolinstanse is that what I’m supposed to do?

teal viper
rich adder
# gusty void

did you change bulletpool from GameObject to bulletpool

gusty void
gusty void
#

Thank you!!

teal viper
gusty void
#

Okay I did this!! This helped but mows it’s saying CS1061 for BulletPoolInstanse

rich adder
#

I bet its "GameObject does not contain definition for bulletpoolinstance and no accessible method blabla"

north kiln
gusty void
#

Yeah, it’s that one

rich adder
#

BulletPool instead of GameObject

summer stump
#

GameObject types only know GameObject things 😄

gusty void
#

Okay thank you!

rich adder
#

wait actually they just need to to use the class directly , the reference isnt needed since its static

#

BulletPool.bulletPoolInstance.GetBullet()

gusty void
#

So don’t delete game object

rich adder
#

you don't need the whole line

#

private GameObject bullepPool

summer stump
# gusty void So don’t delete game object

Oh I missed the static part.

Yeah, static means it belongs to the class itself not an instance (simplifying things). There can only be one, so the compiler will always know which one basically

So yeah, you don't need the variable at all

gusty void
#

OK now it’s saying bullet pool does not exist in the current context

#

OK actually it it works. Thank you so much!!

#

Thank you guys so much it really means a lot. You guys have just saved my freaking project. Thank you.

hollow zenith
fervent siren
#

hey fellas... would you mind helping me out

#

so basically I have a gameobject that when the player collides with it it loads a scene

#

i have a string set as the exact scene name and the code for collision works because when i put destroy game object it destroyed itself

teal viper
fervent siren
#

should I just state that string outside?

teal viper
#

This is just a variable. Unless you assign a value to it, it's gonna be an empty string or null.

rich adder
fervent siren
#

its under a header

north kiln
#

and what's it set to in the Inspector

fervent siren
teal viper
#

I feel like there's a total lack of basic understanding of working with unity...😅

#

Or code.

rich adder
#

learning both at the same time is difficult in the beginning

fervent siren
#

im basically mimicking my code that i used for a button to load a scene

#

execpt when colliding with a game object

#

the game object being a white cube with rigid body

#

although i don't think that matters

#

its just the code thats the issue

summer stump
#

They want to know the value of the string

fervent siren
#

Right

summer stump
#

Show the inspector in unity with the object that has that script selected

fervent siren
#

This is my player movement script

teal viper
#

The issue is that they don't seem to understand what an inspector is...

summer stump
fervent siren
#

unless I should make a seperate script for when the block touches the player instead

polar acorn
fervent siren
summer stump
#

Show it with the MainMenu script on an object

#

That is the one with the string we want to see

#

Right?

fervent siren
#

this is what you are supposed to touch

fervent siren
summer stump
#

You have 3 errors

fervent siren
#

ill pull it up

north kiln
#

Yes but what about the title string that we care about

fervent siren
#

yeah because of the empty script

fervent siren
summer stump
polar acorn
fervent siren
fervent siren
fervent siren
#

this is my WHOLE player scripy

summer stump
#

Ok, so as they thought, the string is empty

fervent siren
#

oh my god

#

i get it

north kiln
fervent siren
#

I GET IT

#

YESSS

#

THANKS

#

it was EMPTY IN THE INSPECTOR

#

OHHHH

#

thanks guys

polar acorn
fervent siren
#

i have a scene named title

#

and gameScene

polar acorn
#

So that'd be your issue

#

You're looking for a scene named

fervent siren
#

works as intended now

fervent siren
#

the empty string

#

mb for not getting the inspector out sooner

#

whenever I clicked on the error as I would it would bring up visual studio

#

so I figured it couldve been an issue with the code

swift crag
#

yes, because the error happened in your code

#

you tried to load a scene that didn't exist

#

that was the error

fervent siren
#

yeah

swift crag
#

did you happen to have this in your code

#
public string title = "mySceneName";
fervent siren
#

no but I stated it through the inspector instead

#

but I would totally do that next time

rich adder
#

assigning value and stating /declaring variable are different

fervent siren
#

just state it right in the code

swift crag
#

well, that's the thing

#

This says that the default value for title should be "mySceneName"

#

but Unity is going to save whatever value you entered in the inspector

fervent siren
#

I getcha

swift crag
#

A common mistake goes like this:

#
  • Create a new field
  • Attach the component
  • Give the field a default value
#

The instance of the component already has an empty string saved for that variable

#

adding a default doesn't change that

#

unity will load the saved values for the component and overwrite whatever the defaults are

gusty void
#

Hi I’ve got some more work done on it and now it’s saying this and I researched a bit on it but the ways I’ve tried or not working

gusty void
#

LISTENN i’m tired y’all I’m I’m using a school computer that doesn’t let me screenshot, so I’m sorry that it looks like dookie but i’m on my last strand i’m losing my mental

spare mountain
#

or open snipping tool

teal viper
#

They probably mean by that they don't have discord installed on that PC.

summer stump
teal viper
#

Sounds like a plan

summer stump
teal viper
gusty void
#

I’m not gonna get into it, but my computer broke early in the week with an actual complete game on it and my two of the games that were saved on another school computer are gone so it’s just kind of been a frustrating week😭

rich adder
gusty void
#

You guys are giving very good advice. I’m just I think I’m just tired

teal viper
#

Can't imagine how you were able to complete a game with the current understanding of C#.🤔

gusty void
#

Listen, it was simple really simple. I’m in the class, so it was really simple and I had my teacher help me.

teal viper
#

Okay. But I still suggest learning the C# basics, so that you can make the game without your teacher's assistance.

spare mountain
#

Discord people be like "guys why doesn't this code work"

gusty void
#

BRUHHHH YALLLl

summer stump
teal viper
summer stump
#

Is it the same line as before?

#

Show your code

spare mountain
teal viper
#

compiler error: could not read the file(it's too blurry)

rich adder
#

new captcha , deblur this image

teal viper
#

Fix all the compile errors in the next code.

spare mountain
spare mountain
rich adder
#

one of us

supple wasp
#

How can I create a car with an npc inside so that they can get out of the car and get into it?

timber tide
#

some code

teal viper
spare mountain
#

step 1: make car
step 2: make NPC
step 3: ???
step 4: profit

rich adder
#

where is the "make npc" button UnityChanPanicWork

teal viper
#

Near the "make a world of warcraft killer mmo" button.

spare mountain
spare mountain
#

object reference not set to an instance of an object

#

least confusing error for newcomers ^

timber tide
#

you'd think so

#

probably the most common question I've seen

fickle lodge
candid steppe
#

Ay

#

did anyone here send me a message request lmao

#

I accidentally declined it and I don’t know who sent it and what server they were from 😭😂

#

it was like 5 minutes ago so if it was from this discord I’m hoping the user is still online

#

eh I’ll figure it out

light moss
#

I have two layers for an enemy. One layer is if I get into contact to that enemy I die. However the second layer is on the top of the enemy head. How can the player jump on the enemy head and kill it.

fickle lodge
cosmic dagger
light moss
#

So if I change the Jump Force to 14 it doesn't do this. But if I change it to 10 is does do this.

timber tide
#

Why dont you just check if you're not grounded

solar tide
#

Is it okay to just have a bunch of classes in one C# script?

cosmic dagger
#

typically, you have one class per script, but sub-classes are fine (as long as they don't derive from MonoBehaviour) . . .

#

you can only have one class derive from MonoBehaviour in a script . . .

summer stump
cosmic dagger