#💻┃code-beginner

1 messages · Page 803 of 1

wintry quarry
#

C# is case sensitive

small zealot
#

yeah im looking for it

wintry quarry
#

I can see two right there

#
  1. delete the duplicate script
  2. Rename the movement class to Movement
  3. you should be able to assign it properly then
small zealot
#

yeah it worked

#

thanks bro your my goat

quick tundra
#

I have an invisible unity sprite, no clue why its not showing up

#

camera z = -10
GameObject sprite z = 0

wintry quarry
#

instead of SpriteRenderer

#

Image is for UI

quick tundra
#

ah

wintry quarry
#

it also... has a RectTransform?

#

Meaning you put it on a canvas

#

so is this intended to be a UI element, or is it intended to be in the game world?

quick tundra
#

game world

#

i didnt put it in canvas tho

wintry quarry
#

ok well

#

i recommend remaking the object

#

with a SpriteRenderer component

quick tundra
#

thanks

#

it works!

vital barn
quick tundra
#

sprite filter?

#

oh like for pixel art?

vital barn
quick tundra
#

gotchu thanks

distant escarp
#

hey, me again! im having trouble using shader graphs to implement into my game gerstner waves; i want them to move all over the place but they seem to only move back and forth (and not side to side). Does anybody have any ideas on how to fix it? I can send pics if needed

obsidian gazelle
#

how do i fix this

wintry quarry
#

Write your code so it only uses variables that actually exist

quick tundra
#

My two colliders(hook and fish) arent colliding

fish as circle collider and rigidbody, both 2D

#

and the Fish has just a capsule collider 2d

slender nymph
#

well the first collider is a trigger which is not a solid collider for collisions, it is a trigger volume

quick tundra
#

okay how do i fix this, because toggling Is Trigger false does not fix this issue, none of the functions(either OnTriggerEnter or OnCollisionEnter) fire

slender nymph
#

see, if it was about physics messages you should have said that. your message implied you wanted physical contact (a collision) to happen

quick tundra
#

aah that worked, I was using OnTriggerEnter, and not OnTriggerEnter2D

vale granite
#

~~ hey, i'm a complete beginner and i want to add a script to an scene object but i get an error which says "Can't add script behaviour 'inputManager'. The script needs to derive from MonoBehaviour!"
Everywhere i have asked or looks just says that the class name doesn't match the file name, use GameObject.name to find it without actually telling me wtf a class anme is and where i am supposed to run GameObject.name

please help, idk if this is the right place but i couldn't find a "Help" channel sooo.~~

#

fixed it

brazen pumice
#

how would I reset the position of a collection of rigidbodies? Trying to restart a player position and the player is a ragdoll

edgy sinew
#

Not sure if it’s best solution but I never had any glitches

brazen pumice
#

is there an easy way to iterate through all of them and change Kinematic/reset position/change Kinematic back

edgy sinew
#

Yes by doing exactly what you just said stonks

brazen pumice
#

that makes sense lmao

naive pawn
#

is there an issue with just setting the position of the rigidbody directly? it's documented as effectively teleporting the rigidbody

low copper
#

I have two monobehavior classes that I need to run identical code (inserting prefabs into a container). I'm trying to figure out the best way to handle this. I was leaning towards an abstract but don't love the fact that I will have to pass in the prefab and container as parameters since a parent can't access child properties. Other options I found; static class, base class, service locator seem to all have the limitation as well so I assume abstract it is. Figured I would ask for thoughts.

naive pawn
#

what's common and what's different in this "identical code"

low copper
#

When I said child I meant child class (in this case : scene class -> abstract class). Abstract class can't get the scene properties (content + prefab properties) directly. What is duplicate is one method that renders a bunch of prefabs into container.

naive pawn
#

also, the abstract class can absolutely get stuff from the scene

#

an instance of a child class is also an instance of its parents

low copper
#

Content is a empty GameObject. I'm rendering inventory items (prefab) on to a UI panel. So I have the sceneController script, that will have the content + prefab attached to it. But I don't know how to give access to that in the abstract class, so I assume I have to pass it in as parameters.

naive pawn
#

you can have serialized fields in the abstract class, no?

#

inventory items (prefab) on to a UI panel
so prefab instances, gameobjects in the scene, not prefabs

low copper
#

Ahhh....of course...that makes a lot of sense. I didn't even think of that for some reason.

naive pawn
#

technically this doesn't need to be abstract either, with the constraints you've given. just some parent class representing the behavior of instantiating a list of objects into some other object

#

of course if there are other details that would make this invalid on its own, then you would have it abstract

#

another option would be to just have some static utility method somewhere (if it's just a chunk of logic that isn't exactly its own behavior)

low copper
#

Ah ok...so that might be better if I want to repeat this behaviour with something not inventory related.

#

Thanks for the thoughts...I really appreciate it

little swift
#

can anyone help me make ui

#

i honestly have no idea how it works and never made one

polar acorn
little swift
#

thank you

verbal dome
little swift
#

turns out ui toolkit is so helpful 😄

#

this is fun

hexed terrace
little swift
#

i didnt mean to misuse channels sorry

hexed terrace
midnight tree
#

~~I need a little with understand of my problem with Vectors.

So...

I have a enemy and I wanna set a ray(s) at the direction(y) to player BUT at the same time also use vector needs to set ray to require angle(Making a ray of attack). I'll not show this vector(main_dir) 'cause it almost the same as transform.forward.

At the end I want to get vector that is looking at y-pos of player and also rotates along x depending on transform.forward (that is, depending on the enemy's rotation)

My actually problem/issue that when I'm trying to go at the side from enemy's rays these rays are starting to move up and down. I don't understand how its actually possible. I tried to search information and there was also nothing about my sort of problem.

Maybe you can help where do I have an issue in the code?

I am open for all questions.


//dirToTarget is vector to player(not normalized!)
Vector3 planeNormal = transform.right; 

Vector3 fwd = Vector3.ProjectOnPlane(transform.forward, planeNormal).normalized;
Vector3 dir = Vector3.ProjectOnPlane(dirToTarget, planeNormal).normalized;

Vector3 main_dir = Quaternion.AngleAxis(currentAngle, transform.up) * transform.forward;
//currentangle to set angle 

float xAngle = Vector3.SignedAngle(fwd, dir, planeNormal); 

Vector3 direction = Quaternion.AngleAxis(xAngle, transform.right) * main_dir;

//Vector3 direction is going to use for a ray calculating.
```~~
upper token
#

How do I make this action possible on a UI button?

bool isShooting = Input.GetKey(KeyCode.Z);
_animator.SetBool("Shoot", isShooting);

midnight tree
upper token
solar hill
#

well your button needs some kind of script to work

#

something that tells it what clicking, releasing or even hovering on it does

#

it cant know how to do something unless you tell it to do that

midnight tree
midnight tree
upper token
solar hill
#

the issue im seeing is why are you trying to do "input.getkey()" on a ui button

midnight tree
#

I hope its quiet understandable :>

midnight tree
digital coyote
naive pawn
#

might have to draw this out, i'm not seeing the picture

digital coyote
#

thats what im working on xD

wintry quarry
#

It's sounding like you probably just want some kind of vector projection but it's unclear

midnight tree
#

Okey, one moment.

digital coyote
#

i think i understand

#

you rotate your local baised on current angle with transform up and forward yea?

midnight tree
digital coyote
#

oooo

#

so when you rotate a vector by tilting that changes your "up"

#

that yaw happens when your look dir is no longer horizontal

midnight tree
digital coyote
#

you want the rays to sweep left to right?

midnight tree
midnight tree
#

Difficult I know. But... okey I guess there is no "but"...

radiant jacinth
#

HI everyone, I opened Unity earlier this week and am trying to make a basic tower defense game. I found a tutorial on YouTube, but I don't understand why my display is different from theirs. Could someone help me? (1st image is the tutorial, 2nd image is my screen)

midnight tree
wintry quarry
swift crag
#

It looks like you aren't seeing the tilemap's grid

radiant jacinth
swift crag
#

This is because you have scene-view gizmos disabled

#

it's this sphere with dots on it

wintry quarry
#

you don't

swift crag
#

Also, your top bar is laid out a bit differently. This could just be due to different defaults in different editor versions

#

You can rearrange the groups of buttons

radiant jacinth
#

It's good thanks 🎉

naive pawn
radiant jacinth
#

Hey, it's me again. Still struggling with my tutorial 🥲 I'm trying to drag a sprite into my scene, but the sprite goes under the tilemaps and I get this message in my logs: "Sprite Tiling might not appear correctly because the Sprite used is not generated with Full Rect. To fix this, change the Mesh Type in the Sprite's import setting to Full Rect." Except when I look at the Unity documentation, I can't find the steps to do this, and the screenshots are different because it's not the same version of Unity. Do you know where I can change this setting to see if it solves my problem ?

wintry quarry
#

You can change the sprite settings there

#

As for the rendering order you need to look at the Sorting Layer and Order in Layer of the tilemap vs the Sprite Renderer

radiant jacinth
wintry quarry
radiant jacinth
#

So, put the ground in the “Default” Sorting Layer and create a specific one for buildings?

edgy sinew
naive pawn
#

the position of the rigidbody, not the position of the transform

#

modifying the transform would indeed lead to a desync

midnight tree
# naive pawn what exactly is happening here that you want to happen differently?

Blue - player
White shape - enemy
Black - rays attack
Red - direction to the player
Yellow - rotation of the enemy

At the end I DONT want to have an example on 1st image. **I want the scenario at the image number 2. **

The direction of rays changes when player is moving aside the enemy and that is quiet annoying. I want just the rotating on the y-axis without any changes on the another axes.(I mean rays of attack are always looking with transform.forward and I change the y-axis of the rays due the script.)

naive pawn
#

ah, i see, i confused y-axis rotation with pitch

#

this makes much more sense

#

if the player is in front of the enemy, but slightly above or below, would the enemy look up or down accordingly?

#

well, the attack specifically

#

if not, it would just be a projection like praetor mentioned

#

if so, it would use projections, but you'd also have to check how far away the player is from the facing direction, and see if that's in a threshold

edgy sinew
naive pawn
#

If you want to continuously move a rigidbody use Rigidbody.MovePosition instead, which takes interpolation into account.

edgy sinew
#

Sure whatever, if you’re sure then ok cool

naive pawn
#

i mean, i don't doubt that there's an issue, ive heard this recommendation of kinematic -> teleport -> dynamic before

#

but if what you're saying is the issue directly contradicts docs, i'm not gonna immediately believe it lol

#

docs can be wrong, sure, but i'd like to see some evidence or a clear description of the issue

naive pawn
quartz orbit
#

im very new to programming and unity, can someone explain how i can use the activescenechanged event to call my method?

naive pawn
#

you subscribe to it?

edgy sinew
naive pawn
#

have you tried researching events/delegates in c# yet

quartz orbit
#

how do i do that 🙂

naive pawn
naive pawn
mild citrus
#

(code at the bottom) Instead of deleting when clicking on the object this code makes the object delete just when i hover over it and and it doesn't plus suns

magic cape
#

I'm a complete beginner and i'm following a tutorial right now to make a ripoff of flappy bird.
I tried to bind a key but unity gives me an error message about using the wrong imput, please help.

radiant voidBOT
# polar acorn !input
How to Set Input

To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling

• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.

magic cape
solar hill
#

switch the input handling to both and try it out

polar acorn
#

Try it and see

radiant voidBOT
magic cape
#

nvm found it i think

mild citrus
polar acorn
silk night
#

Can you disable root motion on single animations or block it through code?

Right now I only want it on the dodge roll and do it like this:

public void OnAnimatorMove()
{
    if (!IsDodging) return;
    var deltaPosition = _animator.deltaPosition;
    if (deltaPosition == Vector3.zero) return;

    _characterController.SimpleMove(deltaPosition / Time.deltaTime);
}

But I assume with more complex animations that is going to be a can of worms 😄

digital coyote
mild citrus
polar acorn
radiant voidBOT
mild citrus
#

god forget it I'll just ask on reddit someone there will help me

polar acorn
#

There's no point in trying to code without setting up your tools

cosmic quail
lofty sequoia
#

Yo. Got a potentially major bug with unity

#

button callbacks don't work if you lower the resolution

polar acorn
#

As in UI? You're probably covering it up with another object so you can't click on it

swift crag
#

Yes, that's very likely

#

If you are using the old input system, you can select the Event System and look in its preview pane (bottom of the inspector) to see what's being pointed at

#

for some reason, the new input system doesn't show this

lofty sequoia
#

could be--all that I have in my scene are some buttons. When I set the game view to free aspect, all buttons work at normal res (1920x1080 ish) but when scaling down to like 800x300, some buttons become unresponsive

#

canvas set to scale with screen size, match h/w 0.5

#

AH diagnostic text displayed over derp

spare tundra
#

it wont lemme do transform.rotate(); it wants to do transformblocks

wintry quarry
#

not with a capital T

#

second, your IDE may not be configured properly for use with Unity.

#

!ide

radiant voidBOT
spare tundra
#

yea its configured and I have the extension

wintry quarry
#

If so, I'm like 80% sure you don't have it configured. It should be saying "Unity Message" or "Unity Event" over Update()

spare tundra
#

lemme relook at that page I had followed the steps and went thru packaghe manager and got the extension I dunno

#

im not seeing the extension under package manager to update. the extension is installed

slender nymph
#

and what about the other steps?

spare tundra
#

only other step is to set editor as default and it is

slender nymph
#

well no, that's not the only other step. but show where you did that

spare tundra
swift crag
#

this is not set up correctly

spare tundra
#

and yes it is bro

swift crag
#

"Visual Studio Code (internal)" is wrong

spare tundra
#

says do package which I cant find and then default editor

slender nymph
#

if you think that is the only two steps then you are missing the vs code extension

swift crag
#

Note that if you just installed the package, it can't actually compile and start working if there are outstanding compile errors

spare tundra
swift crag
#

you should be seeing something closer to this, with a version number at the end

solar hill
#

does it let you compile your code

spare tundra
#

now im confused do I install that one or not I saw the response but it was deleted sorry had to walk away for a minutes its giving me a headache. I cant seem to get this to work I think your right its not configured correctly im gonna reinstall it and restart see if that helps

grand snow
#

you only need the "Visual studio editor" package in your unity project

#

that covers VS and vs code

median hatch
#
protected override IEnumerator AttackTimer()
    {
        agent.isStopped = true;
        animator.applyRootMotion = true;

        animator.SetBool(enemySO.meleeEnemyAttacks[0].attackName, true);

        yield return new WaitForSeconds(enemySO.meleeEnemyAttacks[0].attackTimer);

        animator.SetBool(enemySO.meleeEnemyAttacks[0].attackName, false);
        animator.SetBool(enemySO.meleeEnemyAttacks[1].attackName, true);

        yield return new WaitForSeconds(enemySO.meleeEnemyAttacks[1].attackTimer);

        animator.applyRootMotion = false;
        agent.isStopped = false;
        agent.ResetPath();
        agent.Warp(transform.position);

        yield return new WaitForSeconds(0.1f);

        SwitchState(EnemyStates.Moving);
    }

does anyone know how to fix root motion issues? when the animation stops the enemy snaps back to the navmesh agent position, basically "rolling back"

using UnityEngine;
using UnityEngine.AI;

public class ApplyRootMotion : MonoBehaviour
{
    [SerializeField] Animator animator;
    [SerializeField] NavMeshAgent agent;

    void Start()
    {
        animator = GetComponent<Animator>();
    }

    void OnAnimatorMove()
    {
        if (!animator.applyRootMotion) return;

        agent.transform.position += animator.deltaPosition;
        agent.transform.rotation *= animator.deltaRotation;

        agent.nextPosition = agent.transform.position;
    }
}

ApplyMotion is in the same object as the Animator

spare tundra
#

yea I cant seem to get that installed into unity

#

its not finding it

slender nymph
#

are you looking in the unity registry

#

also installing by name does not mean using its display name

spare tundra
#

welp I broke unity i uninstalled input package thingy

#

input system

slender nymph
#

that wouldn't "break" unity. but you could also just . . . install it again

spare tundra
#

great got it

#

but ummmm the tutorial is gone in unity lol

#

got it

pure pine
#

!code

radiant voidBOT
pure pine
spare tundra
#

is there a decent video that covers shortcuts in vs code?

#

everything is long and not what im looking for

#

I imagine alot are normal windows keys wbut im not familiar with even all those

grand snow
#

what magical shortcuts are you hoping exist?

#

and im sure the actual docs for vs code will list these instead of a yt video

spare tundra
#

alot of the videos I see people Ijumping aroundf in the code etc without clicking their mouse

grand snow
#

you can do ctrl T to type search, ctrl g to go to line and stuff like that

spare tundra
#

cool im gonna print that

boreal ingot
#

hey can anyone check out my thread in networking. i really need help here

spare tundra
#

Hmmm im lost with tutorial

swift crag
#

this is useful for running commands directly

#

but it also shows you the shortcut if one exists

midnight tree
dreamy lance
#

how can i fix this??

swift crag
#

as the error says: you have code that uses the old input manager, but you've set your project to only allow use of the new input system

#

old input might look like this

#
Input.GetAxis("Horizontal");
dreamy lance
#

i have it Input.getkey("W") 4

#

how would i swap it back to the old one?

#

or how would i convert it into the new one

#

im follwoing an older tuturioal

swift crag
#

open your project settings, go to the Player section, and then set the Active Input Handling setting to "Both"

#

Stick with the tutorial for now

#

There is a marginal performance penalty when you do this, but that doesn't matter at all

dreamy lance
#

this is all i see ?

#

found it ncm thank you

polar acorn
radiant voidBOT
# polar acorn !input
How to Set Input

To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling

• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.

quartz orbit
#

i have an animated button pixelart which i want to add to a button (object) what is the difference between animator, animation and using the button transition "animated"

spare tundra
#

Why the difference when creating a monobehaviour script

#

the one is in tutorial video on left

timber tide
#

Left side has some extra c# libraries, but monobehaviours (at minimum) only need UnityEngine

spare tundra
#

yea I guess ill just mirror the tutorial and type those in

timber tide
#

If you're using lists in your scripts then you'll also be using the Generic's library

spare tundra
swift crag
#

They no longer include using System.Collections; and using System.Collections.Generic;

spare tundra
#

so I dont need to add them to the script even though the tutorial has them?

polar acorn
#

Do you need those namespaces?

swift crag
#

If the tutorial later uses a type from one of those namespaces, you'll want to add the directives

#

e.g. the latter is where you get List<T>

#

the former gives you IEnumerator

#

both of these come up somewhat commonly

#

A using directive doesn't actually "import" anything; it just lets you write a shorter name

#

using Foo.Bar.Baz means I can write:

public Thing myVariable;

rather than

public Foo.Bar.Baz.Thing myVariable;
#

using UnityEngine; means that you can write MonoBehaviour instead of UnityEngine.MonoBehaviour

#

hence why that's still there

spare tundra
#

so if I'm following what your saying using.whatevernamespace just basically allows shorthand in code?

swift crag
#

Correct. It's not actually necessary

spare tundra
#

ok

swift crag
#
public List<int> numbers;
public System.Collections.Generic.List<int> moreNumbers;
#

The first line is only valid if you have a using System.Collections.Generic; directive up top

#

Your IDE should insert this for you if you try to use List

spare tundra
#

ok ok im following

#

using UnityEngine.InputSystem;
Vector2 moveInput = Vector2.zero;
so is this using that namespace? im trying to figure out how to tell or if its just something you learn eventually

polar acorn
#

You could also just look up the class in the documentation and see what namespace it is in

spare tundra
#

oh yea it underlines everything red that requires that namespace

#

the script does change in tutorial smh

#

lol the tutorial has you use chatgpt

swift crag
#

The full name of the type is UnityEngine.Vector2

#

similarly, System.Collections.Generic.List<T> is a type

#

a type is a kind of thing

spare tundra
rocky wyvern
#

successfully found where I was being stupid after 20 mins

#

coding on no sleep is not a good idea

timber tide
naive pawn
#

vsc can also be installed via unity hub as the recommended ide for newer versions on mac

naive pawn
scarlet raptor
#

whats the best book for a beginner but doing "junior programing pathway". Doing 3d games?

young sapphire
#

how do i make the camera follow an objects like 3rd person im very new to unity guys i just want a simple script for testing

#

using the new input system package btw

spare tundra
#

How do I fix this

#

i know its in the player settings but cant figure out which

pure pine
#

switch that one to "both"

#

that should fix it

burnt vapor
# spare tundra How do I fix this

I think the proper answer here is that you get really used to Google and typing in error messages. This one in particular I think you find good fixes for.

spare tundra
#

thanks

low copper
#

Can someone help me learn how variable references work in C#? Here is some sample code :

public class SaveData { public Dictionary<string, int> inventory = new Dictionary<string, int> {}; }

public class SaveManager { public Dictionary<string, int> InventoryIndex(){return saveData.inventory;}}

public class Example { 
    public void Example()
    {
         Dictionary<string, int> inventory = SaveManager.InventoryIndex();
         foreach (var item in inventory)
         {
              item.Value++;
         }
    }
}

Does SaveManager pass a reference to saveData.inventory by default. I just want to make sure I'm not editing the actual inventory in Example.Example(); Is there a rule of thumb on how it works? Google says "In C#, arguments are passed by value by default, whether they are value types (like int, structs) or reference types (like class instances, string, arrays). The mechanism creates a copy of the value being passed into the method's local parameter. However, the "value" of a reference type variable is the memory address (reference) of the actual object on the heap. When this reference is passed by value, the called method receives a copy of the reference, but both the original and the copy point to the same object in memory.". Which doesn't make sense to me. I also know my ServiceLocator passes class objects by reference (one instance) so maybe classes have different rule? Sorry for the vague question...just trying to learn how stuff works and not sure how to ask properly.

naive pawn
#

for variables of reference types, the value stored in the variable is a reference to the actual object somewhere else in memory

#

classes are reference types, so they go by these rules, whereas structs are value types

naive pawn
naive pawn
low copper
#

I'm building a craft system...so I want the inventory on the bottom of the page to change but not what is actually in their inventory

#

So it seems like my current code will not edit the actual inventory. But you said I need to copy it?

naive pawn
#

my current code will not edit the actual inventory
it will

#

sounds like you may need a separate inventory store and an inventory view? but i'm not sure what exactly you're going for

median hatch
#

hey everyone should i use root motion or code to move my enemy attacks forward?

teal viper
#

Though, perhaps they're boxed due to the for each. Not sure why there would be a .Value field...

low copper
#

Ok, dictionaries are a reference type. Got it. So how do I make a copy? I just need to get the correct local Dictionary in my example class and I can take of rendering no problem.

teal viper
#

Aaah, it's key value pairs.

runic lance
#

this was a funny example, it actually does not compile

Property or indexer 'KeyValuePair<string, int>.Value' cannot be assigned to -- it is read only
tawny haven
naive pawn
teal viper
#

And yeah, it should result in a compile error.
public readonly struct KeyValuePair<TKey,TValue>

low copper
#

I found this approach : var copied = new Dictionary<KeyType, ValueType>(originalDictionary);

#

Man...I never heard of boxing before

ivory bobcat
#

If they're simply wanting to iterate the collection and increment the value, they could probably box the integer in a class and increment the value by accessing the object.

tawny haven
low copper
#

I was just trying to give a simple example. What I want is to remove any inventory items used in the crafting system from the actual inventory count. Think minecraft/grid.

ivory bobcat
#

I'm going to assume they'll be eventually adding other features to these values as well, like locked or non stackable etc

naive pawn
#

in minecraft the cursor is another inventory slot

low copper
#

Hmm...I'll consider it. Currently anything going through the saveManager is written to disk. I think I understand things better now. Thanks for the thoughts. I appreciate it.

cunning narwhal
#

How am I supposed to set up a git repo?

I made a repo on my account through the web, cloned it to a local folder which gave it a name with dashes

My project has spaces in the name, not dashes. How is this supposed to work? Do I just put the whole project inside the repo folder so it'd be like "..\My-Project-Name\My Project Name"?

vital barn
vital barn
sharp drum
#

Hello. I am trying to make a simple physics based 3D game. I am using rigidbody and new input system to move the player. I trying to recreate player movement like in animal crossing but I also trying to keep physics interactions like horizontal winds or push pads, friction (I am using physics material for this) etc.

I tried setting the rigidbody.linearVelocity = player input * player speed which gave me the snappy directional movement but this also killed any external forces when there is no input.
I tried using rigibody acceleration but that gave me like true physics movement with curvy movement instead of snappy movement.

Is there a way to have animal crossing like movement and also have external physics interactions?

keen dew
#

If you want to set the linearVelocity directly then you have to apply all external forces manually

sharp drum
frosty hound
#

What other way is there?

#

How would any other system know how you wanted your character to "feel"? Your request is already an contradiction. You cannot have 1:1 snappy movement and have external forces influence that, since your snappy movement by definition is snappy.

#

You're going to have to handle this with some logic that only you can define. If the player is in a wind zone, maybe they store a state (IsInWind), and only then the movement isn't "snappy", so that character can freely add the velocity of the wind to their current movement.

naive pawn
frosty hound
#

The proper way to do a character though is to actual apply forces via input as well so that you can add up the total velocity of the player for that frame. The input can just have a high acceleration. When they're in a wind zone/or boost pad, it simply is just a high external force that pushing against it "takes time" to go against it.

And then coming out of the zone/pad would have the player slowly decelerate by nature because their current speed would have to come down to their max speed (or zero if there's no input).

cunning narwhal
naive pawn
#

that doesn't particularly make sense

#

a git repo is typically the project

cunning narwhal
#

Oh ok let me experiment and try that

naive pawn
#

if you want to go for something atypical like that, you'll have to manage the repo setup yourself, which isn't impossible, but i wouldn't recommend it when you're starting out

#

also, if you already have a project, create the repo as the project and upload that, that'll be easier

#

what git client are you using?

cunning narwhal
#

And yeah I already have the project made so git came after the fact

naive pawn
#

mm, not familiar with fork so i can't walk you through that, sorry

frosty hound
#

Technically, you can just copy paste everything in if you just want to see how it works from "scratch".

#
  1. Create the repo on github (or wherever)
  2. Clone the repo via Fork so that it creates the folder on your PC
  3. Put in the gitignore (found online) for Unity into the folder and commit that. This is important
  4. Copy the entire contents of your Unity project into the repo folder on your PC
  5. Commit the entire thing to the repo

Then you can just delete your local (original) project and then in Unity Hub, just point the project to the repo folder to link it back up.

radiant jacinth
#

Hi everyone, I'm still having trouble following my tutorial, this time with a script. In the tutorial, he writes the script that I copied (see attachment) and he also changes the “Active Input Handling” parameter to ‘both’ in the “Player” category of the Project Settings, except that when I run the game on Unity and try to do what the script is supposed to do, I get an error message and I feel like it's this setting that's causing everything to crash, but I don't know how to fix the problem. Can you help me ?

frail hawk
#

this is not really helpfull

frosty hound
#

Do you have a camera in your scene with the MainCamera tag set?

polar acorn
#

What makes you think it has anything to do with the input handling?

frail hawk
#

half of the code only as image

polar acorn
#

You have a null reference error. Something on that line is null.

frail hawk
#

do we just guess this is the Towerplacer.cs

radiant jacinth
radiant jacinth
polar acorn
frail hawk
#

the tag is important here not the name

frosty hound
#

Your game is looking for Camera.main, which is the camera with the MainCamera tag.

frail hawk
#

by default this is the case but you might have added your own cam and deleted the old one, as Osteel pointed out

radiant jacinth
#

It was set to “Untagged” by default. I didn't know it could be linked like that. It works now, so thank you. 😅

frosty burrow
#

Hello Friends, I'm not sure if this is the right place, but I'm trying to connect my unity hub project to Visual Studios to make a mod for the game ROUNDS.

I've installed Visual Studios 2022 and checked the box next to Game Development with Unity, but VS doesn't appear in my list of options for external script editors in Unity Hub. (Visual Studios Code is there, but that is a different interface that won't work for what I need)

naive pawn
#

damn, what version of unity is that

#

can really only give as much advice as this

#

!vs

radiant voidBOT
# naive pawn !vs
Visual Studio guide

If your IDE is not underlining errors in red or autocompleting code,
please configure it using the link below:

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

frosty burrow
#

it is unity 2018.4.34f1, necesarry for the mod

naive pawn
#

you're most definitely on an unsupported version of unity, you'll be hard-pressed to get help with that here
these kinds of weird restrictions are part of why modding discussion isn't allowed here

frosty burrow
#

ah gotcha thank you for the link

#

it worked thank you sm been trying to figure that out for a while

oblique isle
#

I have my rigid body variable in my code and assigned in the inspector, but when I reference it in my script it gives me a null ref?

frail hawk
#

== instead =

#

just for the Debug Log part

oblique isle
#

I may be dumb

#

Potentially

frail hawk
#

and it seems like you are never making use of MovementInput()

#

and your AddForce doesnt make much sense too

oblique isle
#

It was a test

frail hawk
#

ok

naive pawn
frail hawk
#

i agree, that even happens to us sometimes

naive pawn
#

i mean, i don't know for sure if you're dumb or not, but this in particular is just a sign of inexperience

oblique isle
#

Yeah I haven't actually programmed in unity in a minute

spare tundra
#

hmmm I have two light sources

solar hill
rich adder
#

Ohh discord just updated...

oblique isle
#

I remember now

#

It’s good

rich adder
#

One quirk in unity objects you can omit the == too and do if(rb) or in this case if(!rb)

oblique isle
#

True

grand snow
#

Unity does love overriding comparisons dont they

burnt vapor
#

!code

radiant voidBOT
boreal ingot
#

hey guys. i have a post open on networking for a bit and i haven tbeen able to find a solution. I am really stuck can someone help?

solar hill
#

any reason im still getting an error here for the missing skinnedmeshrenderer even though im directly checking for it in the first if statement?

rancid tinsel
#

I'm super confused - why does this work but switch needs a "constant"?

slender nymph
#

well this works because conditional statements for an if statement do not require comparing against a constant. switch statements do require a constant expression or pattern matching

solar hill
opal zodiac
#

YOO can anyone share some wisdom??

I’m at a stage where I can read and understand most C# code and some OOP concepts, but I struggle to write my own code without constantly referencing documentation or AI-generated examples.
I’ve been learning for about 4 months now.
Any tips or exercises to get better at writing code independently?

solar hill
#

"I struggle to write my own code without constantly referencing documentation "

#

welcome to the life

#

thats kinda how programming works lol

slender nymph
#

there is nothing wrong with referencing documentation when writing code

solar hill
#

i would stay clear of the ai generated answers though

rancid tinsel
rich adder
rich adder
#

Wops mobile autocorrect

opal zodiac
solar hill
#

if you want to get to that point

opal zodiac
solar hill
#

youre going to have to ditch the ai

rich adder
solar hill
#

its a crutch and its only hurting you in the long run

hollow crescent
#

Or maybe climbing

#

leave it to your creativity

opal zodiac
hollow crescent
#

İ have been doing it for 6 years and i am not going for things thats too big

opal zodiac
#

Yeah, the idea is basically sonic x killing floor x hotline miami, im treating it as a whole learning project. its been mad helpful

opal zodiac
solar hill
#

imo thats already more agreeable but its a slippery slope

#

ai is wrong, and frequently

#

even if you use to learn new things it can teach you the wrong things

#

you said it yourself, 4 months in and you cant really write your own code without errors if you arent using ai to help you out, it might be a sign of something

#

try going on a bit of an ai detox, if you have to learn something, google it, look on forums, ask here, try things. It will make you a better programmer overall

#

because its all about problem solving, and if someone else always tells you exactly how to solve those problems you suffer the risk of skill atrophy.

distant escarp
#

hey, me again! ive been trying to implement an HLSL custom function node into my ocean's shadergraph to make waves but im having some trouble doing it; does anybody have any pointers or suggestions?

solar hill
#

whats troubling you specifically

distant escarp
#

honestly im struggling to understand where to begin; i tried looking on github for useable HLSL code but none of it worked when i plugged it in

cosmic dagger
distant escarp
stone heron
#

well then learn

distant escarp
#

fair enough

opal zodiac
#

current issue is trying to design enemy attack combos for close range combat

#

these are all rlly good points i think youre right

hollow crescent
stone heron
# distant escarp fair enough

hlsl can be daunting, but at its core its a very simple c-style language. The confusing parts are the inputs and outputs.

#

i wish i had resources but im sure google will give u some good ones

distant escarp
#

on a separate note, i got the gerstner wave shadergraph working without HLSL but im having trouble syncing it with the physics so my player can actually walk on the waves (i know its on the GPU and doesnt have collisions btw, im trying to add a separate physics object and just sync the shader with the object)

stone heron
#

@opal zodiac one of the skills of coding or game dev in general is referencing documentation. Nobody remembers everything. Coding is about breaking down problems into solvable chunks and then accessing the resources to remind yourself how to do it

#

most stuff in unity i just remember by now after like 8 years but if i forget something I just look it up, find an example etc

cosmic dagger
#

Typically, when you finish a script, you'd understand what that script does. If not, then you go line-by-line until you understand what each term, phrase, method, etc., does . . .

opal zodiac
#

I think my issue is that im moving too fast and i need to practice the fundamentals till theyre second nature. I understand Composition, Inheritance, classes and im able to read/iterate code made by AI however i struggle to create code from scratch without a prompt due to lapses in my knowledge

#

ditching AI for a while and focusing on making a game a week may be the solution. what do yallthink

solar hill
#

i agree

#

i might have something to help you

#

gimme a sec

#

https://20_games_challenge.gitlab.io/ @opal zodiac try this.

#

ive heard nothing but good things about this "challenge" from people who started to learn game dev

opal zodiac
#

hell yeah I'm gonna do that and see where im at afterwords

#

is it useful to study CS along with this or should i just focus on writing games from scratch and learning the concepts as i go

onyx blaze
#

There is a way to use "DefaultAsset" variable out Unity Editor?

I'm trying to compile my project, but get an error when I set it out "if UNITY EDITOR"

#

I want to refer my folder inside the variable

solar hill
#

is your ide properly set up?

polar acorn
onyx blaze
swift crag
#

DefaultAsset is editor-only, unfortunately

#

What do you need to load here?

polar acorn
#

Instead of loading a folder, you should make a ScriptableObject that has references to the other components, then you can do a LoadAll for that asset. Instead of having a Database folder, you'd just have assets that are only containing this specific set of data

swift crag
#

bingo

#

(or just load it by name directly)

polar acorn
#

So, instead of loading the Shinobu prefab, you'd load an SO that has a reference to that prefab

#

Once it's in Resources it all basically blobs into one big pile with no directory structure

onyx blaze
#

This folder will have various characters

So will have various files inside
I was trying to avoid to add one by one

swift crag
#

(you'd need to know the actual asset path for the DefaultAsset, anyway -- the name alone would not be helpful)

onyx blaze
#

Let me share my code

swift crag
#

Literal names get problematic when they're prone to change

#

like if you do Resources.Load("JeffKillblaster")

polar acorn
swift crag
#

and then you rename him to BillMcMurderson

#

now it's broken

#

but Database sounds...pretty set in stone

#

I wouldn't be concerned if I saw Resources.LoadAll<Character>("Database/Characters")

#

(i'd add an extra folder, because I bet you'll want other databases later)

onyx blaze
swift crag
onyx blaze
swift crag
#

Resources.Load does not care about actual file paths

#

File paths do not exist in the built game

#

The names you use are derived from the folder and asset names you used

#

I guess I'm not sure what you're worried about right now

onyx blaze
#

I was worried if typing the exactly name folder will works when compile the game
But, if will works, okay ^^

#

I'm trying to setting a DLC content
Is my first time working with DLC
So I'm confuse :/

eternal pike
#

i was following a tutorial for unity and when i tried to use any kind of Input i got hit with this message
it is from a 3 year old tutorial and i already changed code testing it without inputs and it works but any time the if statement requires an input it breaks

radiant voidBOT
# polar acorn !input
How to Set Input

To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling

• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.

potent portal
#

im following a tutorial and for some reason im getting a weird error from "SimpleMove"

keen dew
#

You can't name your own class CharacterController

versed stump
#

I think your ide is not set up properly.
For your issue, I'm guessing you have named your own class CharacterController as well (it's cutoff in the screenshot), which is where the error comes from. The easiest solution is changing your class name.

lethal meadow
#

is DrawMeshInstancedIndirect available for unity shadergraph?

potent portal
#

Makes sense

#

Im using vscode for my ide

vital barn
rich adder
# potent portal Im using vscode for my ide

If it's underlining errors it's most likely configured , you can double check if you declare a variable of type Rigid.. you should see all the unity options like Rigidbody

kindred forum
#

The type or namespace name 'EnumerableApplyChangesToContextCommand' could not be found (are you missing a using directive or an assembly reference?)

Im getting an error with the Test Framework unity package

#

and its with every unity project I make

#

this is one of the lines thats erroring command = new TaskTestMethodCommand(test);

#

the other is this
command = new EnumerableApplyChangesToContextCommand(command, changes);

versed cove
#

OHHHHHHHHHHH

#

You're having an issue with a built in unity package

kindred forum
#

Yep

versed cove
#

You're not coding anything, you're getting an error coming from that package

kindred forum
#

Si

#

I thought I said that already 😭

versed cove
#

I didn't understand

#

Uhhh perhaps its a problem with your unity version, messed up package for it or something..
You could probably just uninstall the package if you arent using it

kindred forum
#

Its test framework

#

its a dependency

versed cove
#

Oh

kindred forum
#

and I'm using the newest version of both unity editor and Test Framework

versed cove
#

Try switching to an LTS

kindred forum
#

The newest unity version

#

is an LTS

versed cove
kindred forum
#

Don't ask why my unity installs are in my Unity 2021.3.2.21f1 folder

#

I dont know myself

versed cove
#

Sorry not exactly sure without seeing the script that is calling that, but it's probably just missing a using line at the top

kindred forum
#

using System;
using System.Collections;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using NUnit.Framework.Internal;
using NUnit.Framework.Internal.Commands;
using UnityEngine.TestTools;
using SetUpTearDownCommand = UnityEngine.TestTools.SetUpTearDownCommand;
using TestActionCommand = UnityEngine.TestTools.TestActionCommand;

#

I'm so very confused

versed cove
#

Definitely sounds like the test framework package it downloaded has issues
Try closing unity then deleting your library and packages folder and reopening unity

versed cove
#

Try another lts

kindred forum
#

I like 2022 or 2021

swift crag
#

I've seen this happen a few times

#

for whatever reason, a file is just Completely Missing™

#

it results in nonsense errors like this

#

Do the following:

  • Close the editor
  • Delete the UPM package cache. This page tells you where to find it.
    • This will make Unity download the packages again if they need to be reinstalled
  • Delete the Library folder in your project
    • This will force Unity to reinstall the packages
  • Reopen the project
#

If you don't clear the global cache, you'll keep getting the same broken package over and over

kindred forum
kindred forum
swift crag
#

i would suggest removing the editor and fixing your install directory

kindred forum
swift crag
#

yes, which is a folder inside of OneDrive

#

my install path on my Windows machine is C:\Program Files\Unity\Hub\Editor

grand snow
#

who installs a program in the desktop

kindred forum
grand snow
kindred forum
grand snow
#

even projects should not be in onedrive/dropbox/gdrive as its a bad solution

#

that sucks but probably was a better solution

gloomy bison
#

what do you mean by "jitters a lot"?

swift crag
#

completely remove your editor installs and the unity hub

#

restart, then reinstall the Hub

#

do not change any default settings and install the editor

kindred forum
kindred forum
golden bobcat
#

how do i make my movement smooth?

rich adder
#

also that += most likely supposed to be just +

#

& the function should be in FixedUpdate

golden bobcat
#

No it does the same thing even if its just +

#

and yes its in fixedupdate

rich adder
#

so what exactly isn't smooth about it ?

golden bobcat
#

its jittery like

rich adder
#

better off making a video showing the issue

#

do you have a follow camera?

golden bobcat
#

Okay give me a second

rich adder
#

alr , can try it with interpolation enabled, see if helps.. but if you have follow camera it might be the camera itself

verbal dome
#

Should definitely enable interpolation

rich adder
#

mp4

golden bobcat
#

discord wont let me embed it

golden bobcat
#

hard to notice

#

but still there

verbal dome
#

Hard to see on mobile but does it jitter if you stand still and just look around?

golden bobcat
#

No

verbal dome
#

Also show the rest of the code, how is the camera set up, are you moving any rigidbody or its parent via transform or animator, etc

golden bobcat
#

the rest is messy

verbal dome
#

Also a general tip, setting targetFrameRate to a low value makes it easier to debug sync/jitter issues.
I also like to have a toggle for slow motion (Time scale ~0.1 or something) for debugging

golden bobcat
#

ill keep that in mind

verbal dome
golden bobcat
#

its in update

verbal dome
#

Cant help without seeing all the code. Too many different posskble causes for this

#

And is the camera a child of the rigidbody object or what?

#

Usually camera movement is done in lateupdate anyway

#

Otherwise another script might move stuff in Update after the camera has moved for that frame

rich adder
#

unrelated, but also why is that clamp happening after passing it to the camera ? 🤔

burnt crypt
#

hello i need help figuring out why when i set this bool active in another script the gameobject doesnt appear/activate , but when im starting the level the deactivating works

#

public class appearPlate : MonoBehaviour
{
    public GameObject objectToControl;
    public TriggerHandler key2active;

    void Awake()
    {
        
    }




    void Start()
    {
        
        MakeInvisible();

        
        Invoke("MakeVisible", 3f);


        key2active = FindFirstObjectByType<TriggerHandler>();
    }

    
    public void MakeInvisible()
    {
        objectToControl.SetActive(false);
    }

    
    public void MakeVisible()
    {

        if (key2active.appearPlate == true)
        {
            objectToControl.SetActive(true);
        }


    }


    public void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            collision.gameObject.transform.parent = transform;
        }
    }


    void OnCollisionExit2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Player"))
        {
            collision.gameObject.transform.parent = null;
        }
    }
}```
rich adder
#

also fyi big code like this should be posted using link services

#

!code 👇

radiant voidBOT
verbal dome
burnt crypt
burnt crypt
#

fixed it

rocky wyvern
#

you should most likely use a property for that

sly bronze
#

would this be a good place to look for a partner to start learning unity with?

keen dew
#

no

#

!collab

radiant voidBOT
# keen dew !collab

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**

sly bronze
upper token
#

Why doesn't the object in the scene appear in the game?

#

I managed to fix it

verbal dome
#

Neither of these are code questions :/

dawn void
#

that would fall in graphicas i believe

fervent smelt
upper token
fervent smelt
spare tundra
#

hey lookie what I found in my docs hidden

#

docs for asset

naive pawn
neat bay
#

thought that was just for general discussion, didn't realise it was a help forum too mb

red pawn
#

hi guys

#

im a very new unity (beginner) and i need help

twin pivot
radiant voidBOT
# twin pivot !ask

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.

-# For more posting guidelines, go to #🌱┃start-here

compact sandal
#

unity is bugging with sprites on 3d. wrong layers being rendered first

#

is there a solution to this?

naive pawn
#

gonna need more info to go off of

#

show your setup perhaps

grand snow
#

99% user error but wrong channel too

naive pawn
#

oh, that too

compact sandal
#

i was being stupid and it was just ordering layer

naive pawn
#

seems like an unsupported material

#

this is a code channel

spare tundra
#

Whoops wrong channel

fervent smelt
red igloo
#

I have a particle system that isn't a child of the player and I have a empty game object that the particle system follows. I have this script and it should stop the particle system from rotating with the player but it doesn't work. Am I doing something wrong? If I freeze my player's rigibody rotation then the issue is fixed but I need my player to be rotating.

⁨``` public Transform trailTarget;

private void LateUpdate()
{
if (trailTarget == null) return;

transform.position = trailTarget.position;


transform.rotation = Quaternion.Euler(0f, 0f, 0f);

} ```⁩

tender mirage
midnight tree
wintry quarry
#

What is actually happening?

vernal ledge
#

i've never thought i would come across this

#

nice pfp you got there man, peak band

#

🤤

wintry quarry
#

it's following the position of an object that happens to be on the rotating part of the ball

#

Step 1 here is switch your tool handle position to Pivot

#

so you can actually see where the objects are

#

Step 2 is move the position of the TrailTarget object to the center of the ball:

#

or do you want the trail on the ground, rather than the center?

vapid egret
#

Hey everyone! Y'all ready for some dummy questions?

#

What would you define as a vertical slice?

red igloo
wintry quarry
# red igloo I want the trail on the ground

ok all you need to do is this then:

  1. Move the TrailTarget's local position to 0,0,0 (the center of the ball)
  2. Change your code to this:
    cs transform.position = trailTarget.position + Vector3.down * 0.5f;
#

delete the line about ⁨transform.rotation⁩, it's not needed and does nothing

#

Once it's working you can change that 0.5f to be something configured in the inspector somewhere - it's whatever the radius of your ball is

#

you can adjust it as needed to match the size of the ball

red igloo
#

@wintry quarry Thanks for the help! works perfectly now ❤️ 👍

narrow plover
#

Im doing a moovment with animations but the diagonal line IDLE are not working

left fiber
red igloo
left fiber
#

thx though

solar hill
blissful vessel
#

Yo, I'm adding a script component to an object during runtime and then I want that script to change the sprite of the object. How do I do that? I can't preset the sprite in the editor because the script doesn't exist on the object yet

solar hill
#

i might be overthinking it but you could just use SOs for this?

wintry quarry
#

cs public void SetMySprite(Sprite s) { mySpriteRenderer.sprite = s; }

solar hill
#

yeah but if they are adding the script at runtime, he cant "preserialize" the fields 🤔

wintry quarry
#

he can serialize it on the script that calls AddComponent

solar hill
#

yeah thats what i was thinking

#

well i was thinking of using an SO and having the script on the object reference that

wintry quarry
#

⁨```cs
public class Example : MonoBehaviour {
public Sprite theSprite;

public void AddTheComponent(GameObject go) {
MyScript instance = go.AddComponent<MyScript>();
instance.SetMySprite(theSprite);
}
}```⁩

solar hill
#

my suggestion was to use an SO instead of a direct sprite field

#

simply if other run time scripts need to work with other sprites they can all get a reference to their respective one from the same field

#

if that makes sense

#

i guess i was overthinking it slightly but the idea is the same in principle.

wintry quarry
#

basically at some point something needs to reference the sprite somewhere and pass it where it needs to go

solar hill
#

yeah

wintry quarry
#

it's all just a game of references and interscript communication

blissful vessel
#

What would it look like doing it through an SO? I'd like to keep my script that adds the component clean if I can

wintry quarry
#

just an extra layer of abstraction

solar hill
#

the SO would let you keep a list of multiple sprites

#

well

wintry quarry
#

you can keep a list in either case

solar hill
#

the field can do that too on the script itself

#

yeah

#

but i would say its maybe good habit though

blissful vessel
#

ty both 🙏

solar hill
#

its not nescessary i would just use SOs for stuff like that, easier to edit later rather than slouching through scripts, especially if you need to get references to the same sprites elsewhere

boreal ingot
#

if i am in a lobby and force quit the game and then reopen it and try to create a lobby because i never left the other one i get rate limited. is there a way to destroy the other one in this example? maybe when reopen search if my id has an open session?

anyone knows the correct way to handle this guys?

slender nymph
barren iris
#

im making a train game similar to the board game rush hour. and im moving the individual peices along a spline like this. but to move it im transforming the position, which means when my object is supposed to collide with a wall or another train, it just goes straight through the other object. is there another method i can do to move an object along a spline (or path) using the rigidbody instead of transforming the position

#

sorry this might not be the right channel to put this in my bad!

grand snow
#

You would need to instead move the object via physics

#

Meaning you have to grab the next goal pos from the spline and use physics to move towards that

#

translation bypasses physics so will not work (meaning you cant use spline animate anymore)

#

@barren iris

barren iris
#

yeah thats chill

grand snow
#

spline container/spline has functions to sample a position so thats easy

barren iris
grand snow
#

there are also functions to get the relative position 0-1 on a spine for a 3d position

barren iris
#

float splineLength = splineContainer.CalculateLength();
progress += input * (moveSpeed / splineLength) * Time.deltaTime;

grand snow
# barren iris i got this i think

Yea if you have your own "spline progress" float you can increase it, sample new spline position and change the rigidbodys velocity (or use MovePosition) to move via physics.
If you detect the rigidbody stops moving then it "hit" something (or use physics events)

viscid heron
#

can someone take the time to help me with my wall jumping mechanic? My wall check object doesn't flip to where my character is facing and i have no idea on how to fix it

#

specifically how to make it so when my character turns around, the game object flips with it

slender nymph
#

well how are you turning the character around

viscid heron
#

moveInput.x = Input.GetAxisRaw("Horizontal");

slender nymph
#

i didn't ask how you are getting input, i asked how you are turning the character

viscid heron
#

oh uh

#

lemme check

#

gimme a min i didnt write most of this code lol

slender nymph
#

if it is AI generated then i will not be helping you

viscid heron
#

my partner on the project wrote it 😐

slender nymph
#

then why not just ask them

viscid heron
#

dont have there phone number

#

this is a school project

grand snow
#

discord? how do you even have the project

viscid heron
#

its through unity version control, i just signed in through the school email cuz i wanted to keep working on it

#

void Move()
{
moveInput.x = Input.GetAxisRaw("Horizontal");
moveInput.y = Input.GetAxisRaw("Vertical");
moveInput.Normalize();

 if (moveInput.x != 0)
 {
     animator.SetBool("isWalking", true);
 }
 else if (moveInput.x == 0)
 {
     animator.SetBool("isWalking", false);
 }

 // Sprite Flipping depending on movement direction
 if (moveInput.x < 0) // Moving left
 {
     spriteRenderer.flipX = true;
 }
 else if (moveInput.x > 0) // Moving right
 {
     spriteRenderer.flipX = false;
 }

}

solar hill
#

you have a school project with a partner and you dont have a way to contact them?

#

also

radiant voidBOT
viscid heron
#

i dont see why this is relevant

grand snow
#

asking who wrote the code how it works is often the fastest way

viscid heron
#

i am aware

slender nymph
#

also you're going to have a harder time getting help if you don't even understand what is already there and working

grand snow
#

If looking right is the default and flipx is false, they are looking right!

viscid heron
#

oh i thought that was just for the sprites?

#

not the physical object

grand snow
#

It is but if you did the scale -1 trick then flipping the sprite would be wrong

#

Anyway the code flips the sprite based on user input so thats why that works

#

So reading flipx will work to know the "last input direction"

#

or you record your own bool based on input

viscid heron
#

so would i want to flip the wallcheck using flipx in the else if?

slender nymph
#

or just determine which direction to do the wall check in based on the flipX property

grand snow
#

change the direction in which you check for walls? yes

#

you can do something like this:
⁨⁨```cs
Vector2 checkDir = new(spriteRenderer.flipX ? -1f : 1f, 0f);

#

spriteRenderer.flipX ? -1f : 1f⁩ is a fancy way to do:
⁨```cs
Vector2 checkDir;
if(spriteRenderer.flipX)
{
checkDir = new(-1f, 0f);
}
else
{
checkDir = new(1f, 0f);
}

viscid heron
#

i dont think this helps what im trying to do

slender nymph
#

why not

viscid heron
#

i dont think im explaining this correctly

slender nymph
#

show how you are doing this wall check

viscid heron
#

the sprites work fine

slender nymph
#

the advice given is not about fixing the sprite, it is about using that property to determine what direction your wall check goes (because presumably it is a physics query like a raycast)

grand snow
#

its the direction to raycast to check for a wall

#

looking right? shoot to the right.
looking left? shoot to the left.

viscid heron
#

Wall check is an object on the player that detects if it is hitting a wall (which works.)

The problem is that the object doesnt flip to where the character is facing.

I can also send my walljumping block of code if that helps

slender nymph
#

how does it "detect if it is hitting a wall"

#

i certainly hope it isn't just a physics message (OnTrigger/CollisionEnter)

grand snow
#

yea probably is

viscid heron
#

when the object comes into contact with a object with the wall tag and wall layer

grand snow
#

which makes this harder for no good reason 😆

viscid heron
#

would it just be easier if i sent the script, me and this other coder literally dont know what we are doing and we are just following youtube videos

slender nymph
#

typically when someone asks how you are doing something, yes they mean in the code.

#

at least that's the case in a code channel. like here.

viscid heron
#

myb bro i thought you just wanted me to explain it, im new here

slender nymph
#

!code 👇 and don't ignore it this time

radiant voidBOT
viscid heron
solar hill
#

the bot message?

#

its showing how to send code properly, either through pasting services (prefered) or using inline for smaller chunks

viscid heron
#

cant i just send the file like i just did?

slender nymph
#

what do the bot instructions say

viscid heron
#

or did it get hidden 0r something

cosmic dagger
cosmic dagger
#

that's why the bot exists; to explain how to properly send code . . .

solar hill
viscid heron
#

how do i post it with a scroll bar thingy on the side of it

#

or can i not do that

slender nymph
viscid heron
#

ok ok

slender nymph
#

Basic reading comprehension is a prerequisite for using unity

viscid heron
#

its big but thats the wall jump code

slender nymph
#

"its big"
So what did the bot message say about large blocks of code

viscid heron
#

i literally did what it told me to d

#

put three backquotes on the front and the end\

viscid heron
#

i was told by boxfriend here that it would add a scrollbar

slender nymph
#

I said no such thing.

solar hill
#

the pasting services are free and half of them dont require accounts, if you want us to help you, make it easy for us.

slender nymph
#

Again, reading comprehension

solar hill
#

nobody wants to scroll up and down a discord channel just to see all your code at once

viscid heron
#

im sorry that im not making it easy for you guys, i dont know what im doing

solar hill
#

read the bot message

#

please

#

there are links

#

go to the paste service, paste your code, send us the link

viscid heron
#

hope that helps

#

i can do the whole script if you like too

solar hill
#

would be prefered as well but this works too if the issue lies here

viscid heron
#

also thank you for letting me know that one of the links didnt require an account, that was one of the reasons i wanted to try discord first lol

#

i know there was some way to add some sort of scrollbar to the code on discord but i guess not

solar hill
viscid heron
#

yes

viscid heron
#

anything to fix it yet or still looking?

red rover
#

How can I generate two or more numbers within a range that do not repeat? Is the best way to use a list then remove the options as I pick them?

grand snow
dim yew
#

i'm reading up on Physics.RaycastNonAlloc and i'm a little confused as to what the size of the array does. i've tested a little and haven't found out any real differences based on values. what does this do exactly so i don't mess something up?

grand snow
#

That's why it returns the amount

#

Therefore make the array with a good size that you deem is big enough

dim yew
#

so the size of the array translates to the amount of hits the buffer can store?

grand snow
#

Yes the max amount

dim yew
#

cool thanks ^_^

grand snow
#

If it hit/overlapped 15 things but the array is 5 in size then you get just 5

sand glen
#

unity really needs general help but did somebodys unity start behaving weird after 6.3 updates
rotating object in editor with gizmos rotates is really fast, small movement results in 700 degree rotation and such
only on rotating objects and on every platform (windows, mac, linux) 6.3.3 version

frosty hound
#

There's another issue too where if you're reversing the rotation gizmo it goes the wrong way for a bit.

prime goblet
#

im using 6.3.2 and im not experienceing these issues, but then also the latest version is 6.3.6 so maybe try that?

vapid egret
#

Hello everyone. Not sure which channel this question is for. I have a character model from mixamo that is floating above the ground whenever I move it during play. I'm new. Is this a common thing new people come across?

vapid egret
#

Thank you

wanton geode
#

Hi 👋 I've got a little issue... I'm making a script that should be able to use a void of another GameObject but after following and debugging a tutorial and I have an error constantly.

private bool isActive = true;
public GameObject player;
private void OnTriggerEnter2D(Collider2D other)
{
    Debug.Log("Trigger touched by :" + other.name);
    player = __gameObject.GetComponent<player_character_movement>().JumpRefill();__
    if (player != null && isActive)
    {
        
    }
}

(I'm trying to translate my error from french)
Impossible to convert type 'void' into 'UnityEngine.GameObject'
Thanks !

rich adder
rich adder
wintry quarry
rich adder
#

Also they're not "voids" they're methods / functions. Void is no return type

wanton geode
wintry quarry
#

you're trying to do some weird frankenstein combination of these two. You sorta have the concepts floating around but all the specifics of how you wrote it are incorrect/out of place

#

Also naming a class ⁨player_character_movement⁩ is very confusing for everyone.

wanton geode
#

Yeah, I tried following a tutorial but it got me an error so I tried a bunch of things and did not really find anything

wintry quarry
#

follow the tutorial

#

instead of guessing at stuff

#

If you got an error following the tutorial you did something wrong.

wanton geode
#

in the tutorial the guy does
var player = gameObect...
But for me it doesn't work

rich adder
#

Your "player" should be storing a "player_character_movement" then call the method

wintry quarry
#

finish the complete line that is in the tutorial

#

and show what you tried

#

and show what error you got

#

When you fully check over everything, you will see that you did something differently

wanton geode
#

I mean, yeah the code works in theory but it does not work 'cause i need to use a OnTriggerEnter2D instead of OnCollision2D, what I wan't to do is this the same but it just doesn't work with collision because(I think) OnCollisionEnter2D works only if the GameObject isn't set to trigger.

wintry quarry
#

If you want a trigger interaction, you would use a trigger collider and OnTriggerEnter2D

#

If you want a real collision, you use a non trigger collider and OnCollisionEnter2D

#

Neither of those changes all that much about the little code snippet you're having trouble with

wanton geode
#

I've made it so my character has doublejumps that can refill over time, but when I touch a certains object, it instantly recovers 1 double jump.
Here is the code that could work if I used OnCollision2D :
using UnityEngine;

public class JumpRefillScript : MonoBehaviour
{
private bool isActive;
private float resetTimer = 5;
private void OnCollisionEnter2D(Collision2D other)
{
Debug.Log("Refill touched");
var player = other.collider.GetComponent<player_character_movement>();
if (player != null && isActive)
{
player.JumpRefill();
isActive = false;
Debug.Log("Refill done");
}
}
void Update()
{
if (!isActive)
{
resetTimer -= Time.deltaTime;
if (resetTimer < 0)
{
isActive = true;
Debug.Log("");
}
}
}
}

but line 10 has an error if in the void i put OnTriggerEnter2D

radiant voidBOT
wintry quarry
#

and don't just say "has an error"

#

show us:

  • The exact code you tried
  • The exact error you saw
#

We can't do anything without actually seeing the problem. A vague description isn't enough.

wanton geode
#

Ok, so I've played arround a bit more with my code and managed to get a code without any errors in it...
using UnityEngine;

public class JumpRefillScript : MonoBehaviour
{
private bool isActive = true;
private float resetTimer = 5;
private void OnTriggerEnter2D(Collider2D other)
{
Debug.Log("Refill touched");
var player = GetComponent<player_character_movement>();
if (isActive == true)
{
player.JumpRefill();
isActive = false;
Debug.Log("Refill done");
}
}
void Update()
{
if (!isActive)
{
resetTimer -= Time.deltaTime;
if (resetTimer < 0)
{
isActive = true;
Debug.Log("Refill recharged");
}
}
}
}

The issue is, when player and entering in the trigger i get this error :

wintry quarry
#

why did you just throw your hands in the air here and do this completely differently than before

#

You need ⁨⁨other.GetComponent<player_character_movement>()⁩⁩

#

the way you have it right now it's trying to get that component from your own GameObject, i.e. the one this script is attached to

#

you want to get it from the thing you triggered with

wanton geode
#

aaaah alr

wintry quarry
#

you're also probably going to want to check that it's actually the player you collided with.

#

But that can come next

wanton geode
#

oh yeah I saw that. Anyway, it works now so thanks and really sorry if I'm doing things a bit randomly I'm still trying to get around and trying to undertstand what I'm doing and what to do

sinful zinc
#

not sure what channel to put this in but how can i have components such as vertical/horizontal or grid layout group to stack upwards instead of downards vertically?

rich adder
rain solar
#

am i suppose to hard code the distance at which my chunks switch to half resolution?

fervent abyss
#

is there any way to like WaitUntil like in coroutine but in async void?
⁨```cs
while (PhotonFusionWrapper.instance.runner.ActivePlayers.ToArray().Any(p => NetworkPlayer.GetNetworkPlayer(p) == null))
{
await Task.Yield();
}


i do it like this but im pretty sure the thread just stops lol 
(im trying to wait until all players have their player prefabs spawned)
naive pawn
#

their question wasn't about networking at all

frail hawk
#

thought photon is network related and might be a better place

naive pawn
#

did you read their question though

#

or are you saying like, this is an X/Y problem?

frail hawk
#

i looked at the time it was asked and assumed no one knows the answer so i linked the channel

naive pawn
#

if someone did know about async in general i think they'd be here though

naive pawn
#

but i can't verify the accuracy or quality of the answer since i haven't used async

charred monolith
frail hawk
#

so help him then

rancid tinsel
#

does anyone know how to generate either an image file or sprite asset at runtime?

sour fulcrum
#

Have you googled it? Decent amount of resources

rancid tinsel
#

I have but I guess I'm not good at looking

#

best I found was some Unity forum mod taking the conversation to DMs instead of putting the solution in the thread

#

I think I've got it now tho

vital barn
rancid tinsel
rancid tinsel
#

it's not

vital barn
#

How

naive pawn
#

in unity asset terms, Texture2D is an imported asset, and Sprites are assets generated from that Texture2D

frail hawk
#

a sprite is a texture would fit yes but the oppsosite we can argue

naive pawn
#

yes, you can create sprites from textures

#

i just said that

#

that doesn't mean they're the same thing

vital barn
#

In the context of files, it's the same thing

naive pawn
#

a single texture2d can have multiple sprites from different rects

naive pawn
#

so that would be a texture that has multiple sprites, yes

vital barn
#

Well, the point is that a sprite is not just something separate, sprite it's an area on the texture

stuck parrot
#

how do I learn coding for unity? I mean I kinda can read the code and after uning my brain for 5 or 10 minutes it does start making kinda sence but how on earth would I as a beginner write a code like that
⁨⁨```cs
using UnityEngine;

public class PlayerMove : MonoBehaviour
{
public float moveSpeed = 6f;
public float jumpHeight = 1.5f;
public float gravity = -20f;

private CharacterController controller;
private Vector3 velocity;

void Start()
{
    controller = GetComponent<CharacterController>();
}

void Update()
{
    Vector2 input = new Vector2(
        Input.GetAxis("Horizontal"),
        Input.GetAxis("Vertical")
    );

    Vector3 move = new Vector3(input.x, 0f, input.y) * moveSpeed;

    // grounded check
    if (controller.isGrounded)
    {
        if (velocity.y < 0)
            velocity.y = -2f;

        if (Input.GetKeyDown(KeyCode.Space))
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }
    }

    // gravity
    velocity.y += gravity * Time.deltaTime;

    // combine horizontal + vertical
    Vector3 finalMove = move + velocity;

    controller.Move(finalMove * Time.deltaTime);
}

}

 out of thin air. It seems like guessing magic spells for me.
This one is made by AI because no forum or documentation is actually explaining it
naive pawn
#

you would learn, and as you get more knowledge and experience, you can start synthesizing new code from your knowledge/experience

#

you can think of them as magic spells, sure. but mages don't guess, they know from study and practice

#

that's how you get knowledge and experience

stuck parrot
naive pawn
#

no?

#

i feel like that's based off an incorrect assumption

stuck parrot
naive pawn
#

there are beginner resources pinned in this channel, have you tried checking those out

naive pawn
stuck parrot
naive pawn
#

"beginner" is a vague term. if by "beginner" you mean "someone who can't code", you would not write code as a beginner

#

you would first learn how to write code, and then you wouldn't be a beginner anymore

#

it's a long process, this is an entire skill on its own

#

you wouldn't learn masonry by building a whole fireplace without any prior knowledge or experience

stuck parrot
naive pawn
#

they're explained in docs

#

that's what docs are for

#

no-one knows this stuff magically, we use the resources at hand

#

that's what the pinned resources are for

frail hawk
#

but if you are new, i´d recommend learning the basic of c# first

#

just console app or some win forms beginner projects

stuck parrot
# frail hawk but if you are new, i´d recommend learning the basic of c# first

the basics are only that you do math with variables which you assigned values to. thats all what I know about C# so the bigger problem is to guess what functions unity is hiding. I had spend so much time just to find out you can use the character controller insdead of assigning movement to every button and joystick seperatley

naive pawn
#

you don't have to guess

#

you can check docs and/or follow guides or tutorials

#

insdead of assigning movement to every button and joystick seperatley
you still have to do this, input handling is separate from actually moving the character (but there are defaults provided)

stuck parrot
frail hawk
#

you will find out about the most used componenets over the time

naive pawn
#

(also, by "slangs" do you mean specific classes/components, or patterns/idioms? that's pretty vague)

stuck parrot
stuck parrot
frail hawk
#

or you use cinemachine hehe

naive pawn
naive pawn
stuck parrot
naive pawn
#

guides aren't going to explain every single little detail. otherwise they'd all by 8+ hours and take months to make
they make some vague assumptions about your skill level and experience, and they might be wrong, but when they are, you can just seek this information yourself

stuck parrot
sour fulcrum
#

!learn

radiant voidBOT
naive pawn
# stuck parrot and where is the best place? because everyone doing stuff differently and the do...

depends on the specific thing and your past experience. "best" is impossible to define.
docs are the overall most accurate resource (unless you count source code) but they are, by nature, technical documents
if you aren't willing to go to that yet, look for guides or tutorials, like those in unity learn 👆 or pinned in this channel

everyone doing stuff differently
right, because there's tons of ways to do any specific thing.
or providing the base code
not sure what you mean by that. plenty of docs have examples

vital barn
# vital barn Google

To be honest, the ability to search for information is no less important than programming itself

frail hawk
#

i have a feeling that you are not researching enough before starting development.

#

like as you said you started programming your own player controller than found out about the character controller

sour fulcrum
#

Them asking is researching to be fair

naive pawn
#

i feel like they're bringing a lot of unbased assumptions in without being willing to challenge them :/

stuck parrot
# frail hawk i have a feeling that you are not researching enough before starting development...

because with google I always feel like hitting the wall. even for player movement which is like step 1 of bringing a game to life but theres no clear explaiation, or code to copy. Isnt moving a character the same thing in every game and should be a pick of a few different variations (first or third person)? thats the reason I use AI is because google just isnt a good place to look up stuff anymore

naive pawn
#

Isnt moving a character the same thing in every game
no

#

ok mate, just ditch AI. it's not gonna help you learn

sour fulcrum
#

Google is still a good place to look up stuff

vital barn
naive pawn
#

@stuck parrot none of us magically understood programming randomly one day. we started as beginners too. we're recommending these things because they work

stuck parrot
# naive pawn <@1308028699890683955> none of us magically understood programming randomly one ...

so whats the best workflow now. not knowing how do do something > googeling this problem > reading documentations, watching videos and coming up with ideas that eventually work? I understand that programming is not easy, and that unity needs code to work. But shouldnt game development be more of an creative and artistic task? I mean its fun to make 3d models, characters and bring them to like but the coding parts seems like labour

sour fulcrum
#

It is labour

#

Game development is extremely hard

naive pawn
#

not knowing how do do something > googeling this problem > reading documentations, watching videos and coming up with ideas that eventually work
this is a pretty good idea, yeah. if you asked me to come up with something on the spot i'd probably say this too