#💻┃code-beginner

1 messages · Page 325 of 1

eternal falconBOT
west sonnet
#

Followed these steps, thank you, but nothing happens when I click on my shotgun

wintry quarry
#

you disabled this, so it's not clickable

west sonnet
wintry quarry
#

but this needs to be enabled for sure

#

something else may be in front of it

west sonnet
#

it was working, but the shotgun was appearing in front of the hand, so I moved the shotgun backwards on the Z axis and now it's not working

wintry quarry
#

yeah it's just behind something now

#

WHy is the shotgun a UI element?

blazing ruin
#

Help me please. I attached Particle System to player. Set Emission Rate over Distance. But Partical systems that simulate dust doesn't work the way I want it to. It only emits during WASD input, when the button is held down, the effect stops emitting

wintry quarry
#

UI drawing order is based on hiaerachy order

#

not z axis

#

it's possible the hand itself is now blocking the shotgun

#

make sure raycast target is disabled on the hand

west sonnet
blazing ruin
#

All was made with UI Unity

wintry quarry
#

I assumed there was code due to the channel

#

BTW your emitter velocity mode is set to Rigidbody. Are you using a Rigidbody?

summer stump
#

You are telling it to move down to -5.5005
Perhaps that is the issue

full wave
#

how do i hide the gizmos icons in game view?

sharp bloom
#

I'm trying to highlight certain areas of an object, but this code changes the color for the whole object, instead of the one segment I want. What is the best way to do this kind of thing?

#

Like is it possible to have "instances" of the same material?

short hazel
full wave
#

but i want to keep the square, can i hide jst the icons?

#

oh, i can just move the 3d icons slider to 0

#

problem solved

short hazel
#

Yes clicking the arrow next to the button will show toggles for each individual gizmo type

hollow dawn
short hazel
#

You have a variable on line 14 that does this

rocky canyon
short hazel
#

Make sure you read the code!

rocky canyon
#

the icons will disappear but the gizmo's will remain

hollow dawn
rocky canyon
short hazel
rocky canyon
blazing ruin
#

then I ask here

hollow dawn
willow scroll
blazing ruin
#

I would suggest simply not adding particles in your project

willow scroll
#

You got it!

blazing ruin
#

Check please

molten dock
#

i am checking if an enemy can attack with a canAttack bool

molten dock
#

which i turn false within that if statement, and call an enumerator to make it true again in a second

#

but it stays false

willow scroll
#

Could you show the code?

molten dock
#

yes fo sho

willow scroll
#

Also, you should write the full question in a single message

#

!code

eternal falconBOT
short hazel
#

(shift + enter to add a new line without sending the message)

molten dock
#

thank

#

thanks

short hazel
#

(up arrow to edit the last sent message)

willow scroll
#

Also Enter doesn't send the message if you're within the code block

willow scroll
molten dock
#

attackCooldown is a private float currently set to 1f

languid spire
molten dock
#

i meant the thing in the waitforseconds brackets

#

sorry if that misled

young fossil
#

How do I deal with order of excution between scripts? Any ideas?

summer stump
languid spire
young fossil
short hazel
molten dock
summer stump
#

You directly called the method

#

The example shows that you need to pass the method into the StartCoroutine method

short hazel
#

You aren't starting the coroutine, you're just executing the function. It'll run up to the first yield and stop. The next instructions aren't executed.

molten dock
#

oh i say start corutine

#

diddnt pick it up

#

thanks

full wave
#

im debuging position.y, the object is very far lmfao

molten dock
#

it does work now btw

livid frigate
#

I made interaction system, it shows Press "E" while u aimed at object with collider and LayerMask names "Interactor", but it shows Press "E" slightly further than the collider limits, how to fix it?

ivory bobcat
full wave
#

i made the Coefficient of restitution (bounciness) 1.5 instead of 0.15, so it just went crazy

short hazel
#

Pretty fast if you ask me

full wave
#

i wonder what time dilation it experienced

finite moat
#

Am I allowed to ask editor related questions here there doesn't seem to be a fitting channel for my question?

finite moat
#

thx

ivory bobcat
#

Assuming you're referring to code

stable lagoon
#

Does anyone know a good place to start learning how vr works in unity?

slender nymph
finite moat
stable lagoon
ivory bobcat
#

Don't cross post btw

patent compass
#

Hello, I am trying to get the money script component attached to the collider. But getting error at setactive. How else can i get it.

    private void OnTriggerEnter(Collider other){
        if (other.CompareTag("Money")){
            GameObject temp = other.gameObject;
            MoneyMovement moneyMovement = temp.GetComponent<MoneyMovement>();
            moneyMovement.SetActive(true);
        }```
slender nymph
#

components do not have a SetActive method, unless your MoneyMovement component defines its own

#

and if it does but you are receiving a NullReferenceException then whatever other is, does not have a MoneyMovement component

patent compass
#

so how can i activate/deactivate a component via script?

slender nymph
#

have you looked at the docs for MonoBehaviour to see what methods or properties it has that might allow you to do that?

patent compass
#

I tried chatgpt. but it keeps crashing. 😦

rocky canyon
#

ewww 🤢

gray pond
#

i've got this animation that only plays once when i press a horizontal input, is this a code issue? if so, here's the code but i'm not sure what's wrong

#

because it definitely plays when i do the horizontal input but if i hold the input, it won't keep running it until it stops

rocky canyon
#

yes.. its both code and animator issue in a way..

#

GetButtonDown (happens one frame)

gray pond
#

OH

rocky canyon
#

GetButton (is the continuous one)

#

but if ur gonna have 2 triggers..

#

just use a Bool

#

isIdle for example

gray pond
#

so i could go like

#

make a function or something

rocky canyon
#

and SetBool(isIdle, true)

#

else ,false

gray pond
#

oh yea in the animation window

#

gotcha i can do that

#

thanks UnityChanThumbsUp

rocky canyon
#

yea,, if(input.getbutton("button"){setbool,true)else(setbool,false)};

rocky canyon
summer shard
#

what's better, instantiate object each time i pull it out, or create objects before and show and hide them

ivory bobcat
summer shard
#

okay thanks

stuck palm
#

why is my rigidbody object so choppy when it cinemachine follows it? i have interpolation on

daring oasis
#

Hey this is more related to c# itself but is there any way in c# to add to the back of an array an element? without running a loop to find the last index of the array that is ocupied?

short hazel
#

You'd need to keep the index where you last added an element into a separate variable

#

If you need to add elements to both sides then consider using a List<T>, where Add(T) adds at the end, and Insert(0, T) at the start

ripe spire
#

hi can someone can help with my script bcs its not working

short hazel
daring oasis
#

also if i have a

OnCollisionEnter2D(Collision2D coll)``` and i want to destroy the object that triggered the collision how can i do that cuz coll.collider deletes only its collider(wich makes sense :))
short hazel
#

coll.gameObject gets the Game Object the collider is attached to

daring oasis
#

tx

short hazel
#

.gameObject is pretty much accessible from any component, where components are things you see in the Inspector (Transform, Collider, custom scripts...)

ripe spire
#

can someone help me with this script because if player go through enemy nothing happens

ivory bobcat
gray pond
#

@rocky canyon haha ok thank you, your help worked like a charm

polar acorn
gray pond
#

had an issue where i didn't change the transition at all so thank u

ripe spire
tulip glade
#

using UnityEngine;
using UnityEngine.AI;

public class NavMeshFollow : MonoBehaviour
{
public Transform target; // Target to follow
private NavMeshAgent agent;

void Start()
{
    agent = GetComponent
    <NavMeshAgent>();

    // Check if a target is assigned
    if (target == null)
    {
        Debug.LogError("No target assigned to NavMeshFollow script!");
    }
    else
    {
        // Set the target for the NavMeshAgent
        agent.SetDestination(target.position);
    }
}

void Update()
{
    // Update the destination to follow the target continuously
    if (target != null)
    {
        agent.SetDestination(target.position);
    }
}

}

#

how can i make it so the agent y rotation is matching to target player rotation?

flint ruin
#

the navmeshagent should do that automatically I believe. If you want to manually do it though, I should be able to whip up some pseudocode

tulip glade
#

yeah he makes it automatically but it faces the wrong rotation

flint ruin
#

If your object is not in the proper orientation, you could put the agent on a parent object and have the actual mesh be on a child. That's kind of how I handle it

#

then your rotation is still controlled by the navmesh agent but you can give it an offset

tulip glade
#

i just want to mention,its a 2d game,and the world is not oriented as in 3d ,its just a wall

#

will it still solve?

flint ruin
#

Yeah, it should. I assume you're doing a 2.5d or a top down so that navmesh can work?

tulip glade
#

no ,its 2d
but ill try the parenting solution

flint ruin
# tulip glade no ,its 2d but ill try the parenting solution

Navmesh doesn't really work with 2D games unless they are either
A: Top down
B: 2.5 D
C: The actual navmesh system itself has been extended upon
There are some alternatives for navigation in a 2D space but they are often not as easy to implement and can be clunkier

tulip glade
#

the game is from this perspective

flint ruin
#

I see, it's top down. that should work

tulip glade
#

the circle has the issue,when i start he rotates -90 on y and 90 on z

#

i tried now parenting

#

didnt work(

flint ruin
#

rotate the object inside the parent?

#

That didn't work?

tulip glade
#

yeah like when i start he instantly rotates

flint ruin
#

the object that the agent is on will rotate itself to the navmesh. Make sure the agent and script are on the parent object

tulip glade
#

something overrides i think

flint ruin
#

it shouldn't mess with it if it's a child off the agent. The agent will still automatically rotate no matter what but you can change the child's rotation so that the graphic appears correct

tulip glade
#

ohhh nice

stuck palm
#

how can i make rigidbody interpolation work smoothly at higher framerates? 100+

tulip glade
#

yeah it fixed

#

appreciate it🔥

tawdry depot
#

hi

#

how kmow thx error how can I fix this

deft grail
#

its just saying you using OnMouse might not be performant on mobile devices

tawdry depot
#

yes but I build the game its not woorking

deft grail
#

whats not working?

tawdry depot
#

game in my phone

deft grail
tawdry depot
#

i downloaded it as an apk version and when i open it it just closes immediately

grand mango
#

might i reccommend trying out unity remote? it might work better for your testing, as then you could see if there is an error begin called in the build using the profiler

tawdry depot
#

what is unity remove?

grand mango
#

Sorry, meant to type unity remote

#

i use it in tandem with my android device and while it requires a wired connection, it works well to see if all the moving parts are correctly working as the game runs on the PC but is streamed to the device

tawdry depot
#

yes I know this app itsi working in the app but I build the game its not open

grand mango
#

i suggest the unity remote app as it may help you find errors that you can then check and see if the launching of the game may be interrupted and causing a crash.

tawdry depot
#

yes bro i know unity remote and i used it, the game works in the app but when i build the game and download it as apk in my phone it doesnt open

grand mango
#

I can run down a few questions to get an idea of where to start looking for solutions at.
does the app open but then immediately close?
Does it have an icon on the page that displays properly?
do you have all the scenes you plan to use in the build index, in the right order you want to use them in?

tawdry depot
#

yes yes yes

grand mango
#

well, that gives me the idea that the build is probably crashing due to either some code/setup related issue, not an android or device specific issue. which means that there may be a problem on the initial loading of the apk. i assume youve attempted to rebuild the project?

#

any info here about errors / warnings you might have in scenes, or the device info would probably help one of the many people here assist better

white sun
#

I have a question about a unity error upon player launch. I am new to unity taking college classes and I ran into a situation. My game can not load up and I dont know how common this is?

#

It is in a endless start up loop

deft grail
#

or show a video

glacial crane
white sun
#

im loading a video of the error

deft grail
# white sun

interesting, do you have any code for switching scenes/restarting it? SceneManager.LoadScene() for example

grand mango
#

that looks like someone put load scene in update

#

but yes i think we would all appreciate throwing in a snippet of the code associated with your scene loading

white sun
#

gif of video if itll make it easier to view

#

let me check that, not going to lie my processor isnt really teaching and we are using a outdated unity book in the modern 💀

#

for a beginner game dev class

deft grail
#

go to all of your scripts or one you know, and just look for SceneManager.LoadScene

white sun
#

the entire class is in the same boat as me with this

deft grail
#

probably the most recent script you edited

white sun
#

should i do a separate screen manager script, my codes are mixed in with other scripts 🥲

deft grail
#

just show the code where you load the scene

#

and where it is

white sun
#

my current unity scripts

#

we add on to it so it can get confusing

deft grail
#

or just ignore the warning

#

you dont need to listen to it, it says might impact performance

glacial crane
# white sun

What’s the Utilities.RestartLevel ? It seems exactly what you are facing

tawdry depot
grand mango
#

if i remember, doesnt on mouse not work with touch screens?

deft grail
#

as i remember sometimes it can close for couple times

#

but after it fixes

deft grail
tawdry depot
#

i opened it a lot of times but it just doesnt work
and the problem is I deleted OnMouse from my code and it still tells me the warning about it

deft grail
#

it wont delete by itself

tawdry depot
deft grail
#

top left of the console i think

white sun
#

utilities code

tawdry depot
# deft grail top left of the console i think

well that doesnt fix the problem, after i clear it and build the game, the OnMouse shows again after the build finishes, do you think the game is not opening in my phone because of it?

white sun
#

im going to get food so ill be right back

deft grail
#

well its more, its definitely not why

rich adder
#

!vscode

eternal falconBOT
#
Visual Studio Code guide

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

https://on.unity.com/vscode

deft grail
#

but with the information we have, theres nothing really to go of to help you

acoustic arch
#

alright ill provide scripts in a second but first, my cards for my game are scriptable objects and same with the abilities

#

each card contains 3 ability slots

#

is there a way i can make a script that allows me to put a card in from the inspector then be able to add what abilities the cards have without creating an entirely new card?

deft grail
#

you would need to give more information on what your trying to do specifically and what your setup is

tawdry depot
acoustic arch
# deft grail just edit the slots on the card?

each card slots can be unique, although i cant find an easy way to allow a scriptable objects to have many unique possible copies of a single card without making an entirely new card

#

i just want to be able to make a new object with enemy card manager and allow me to add the abilities and cards into it directly

#

i could make 3 public variables within it for each card then the script auto adds them to their respective card possibly

north kiln
#

You can surround links with < > to hide their previews by default btw

cinder crag
#

how can i check if a scene is loaded? cause i cant laod my saved data cause it doesnt find the player in the scene so it doesnt load(this is in the main menu btw)

rich adder
cinder crag
torn edge
#

Does anyone know how I can get the player's bullets to go higher or lower depending on the x-value of the player's rotation

rich adder
deft grail
torn edge
#

lemme see ill try to do that

acoustic arch
#

is it possible to have a scriptable object with a method on it, then have that same but new scriptable object with a different method?

#

for abilities or spells etc

tidal parrot
#

how do i like, code/animate a light to turn on/off when the player interacts with it? im assuming i have to turn the light into an npc and code in some sort of sprite change, but i just wanted to ask here

olive galleon
#

What are some things you would potentially use events for?

tidal parrot
#

also for npcs, for each npc i make do i need a seperate npc controller for it?

rich adder
tidal parrot
#

alright cool thanks

cinder crag
rich adder
summer stump
tawdry depot
teal viper
tawdry depot
teal viper
summer stump
#

Is this unity DEVELOPMENT related?

deft grail
tawdry depot
#

downloaded a copy of the game as an apk in my phone and its not opening like the video shows

teal viper
#

Okay, you should train to provide a full explanation and context in your initial question.

rocky canyon
#

you mean, "its not opening, like the video shows"*

teal viper
rocky canyon
#

confuzing myself there for a second

#

guessing it runs fine in the editor?

cinder crag
teal viper
tawdry depot
#

same

deft grail
eternal falconBOT
teal viper
# tawdry depot same

Then I suggest looking at the logcat. The app probably crashes on launch and there should be some crash report/error thrown in the device log.

summer stump
# tawdry depot same

Please provide full information instead of making people drag it out of you. This has been mentioned already.
Really tough when the answers are just "yes" and "same"

teal viper
cinder crag
teal viper
#

Do you know how to read it?

cinder crag
#

i do

#

i think

teal viper
#

Okay, explain to us then. What does the error say? What line throws it and why/what does it mean?

teal viper
rocky canyon
cinder crag
# teal viper Okay, explain to us then. What does the error say? What line throws it and why/w...

well the second is obvious , the scene is not loaded so it cant be set active(line is in the first pic) , and the first one is maybe cause when im pressing the continue button it doesnt find the save and load manager script with is placed on the player in the next scene , the first error probably happens cause im tryign to get a reference only when i press the continue button which is in the main menu(second pic which contains the void which i use on the OnClick event for the continue button)

teal viper
#

What line throws the error?

cinder crag
#

line 68 of this void

summer stump
cinder crag
#

which is also used for the OnClick event for the continue button

teal viper
# cinder crag line 68 of this void
  1. There's no such thing as a "void". It's a method with no return type. Or just a "method".
  2. So what does it mean that line 68 throws a null reference error?
cinder crag
summer stump
teal viper
#

Where do you assign a value to that variable?

cinder crag
#

and at the start of the class i just have this

teal viper
teal viper
cinder crag
teal viper
#

Do you know a difference between declaration and initialization?

cinder crag
teal viper
cinder crag
teal viper
#

declaration

cinder crag
#

so i ahve to declare that var somehow

deft grail
teal viper
cinder crag
#

yeah ik so i dont really understand what is the problem

teal viper
teal viper
#

Var is not a value

cinder crag
#

oh wait no

cinder crag
cinder crag
teal viper
#

So your saveAndLoadSystem doesn't being null means what?

cinder crag
#

it think its being pointed at something?

teal viper
#

It's not pointing at anything. Or rather, it's not referencing anything.

#

So how would you fix it?

cinder crag
#

this time im actually not sure , sorry sadok

teal viper
#

Well, you just assign a value to it. You make it reference whatever you want it to reference.

#

Do you do it anywhere?

cinder crag
#

well yeah i am but i am 100% thats the problem ngl

teal viper
#

Where do you assign a value to it?

cinder crag
#

im assigning a vlue to it in the method ContinuePlay which as said before is used for OnClick event for the Continue button

deft grail
teal viper
cinder crag
teal viper
cinder crag
#

68

teal viper
#

No

cinder crag
#

it is 68

teal viper
#

Then you changed your code since last time

#

The original screenshot said line 67

cinder crag
#

moved it above

teal viper
#

So share the new code

cinder crag
#

its the same code

teal viper
#

It's totally not the same code

#

It's a huge difference.

#

And the error you're getting now has a different cause.

opaque reef
#

Hey, got some troubles using a websocket inside a service. is there any specific channel or forum to post the doubt?

cinder crag
teal viper
deft grail
teal viper
# cinder crag its the same code

Which I don't think you can do at your current level.
You'll need to go through C# basics and learn properly to solve your issue.

cinder crag
deft grail
cinder crag
deft grail
#

or something like that shouldnt be on the player at all

#

its a saving and loading system, theres no reason for that to be on the player

torn edge
deft grail
#

depends what you are trying to do specifically really

tawdry depot
cinder crag
deft grail
#

did you implement ads into your game at all?

#

or try to

tawdry depot
deft grail
summer stump
tawdry depot
nimble apex
#
    if (this == null)
    {
      LanguageDataScript.Instance.OnLanguageChange -= OnChangeLanguage;
      return;
    }```

im optimizing code, because the codebase is 6 yrs old now
annnnd this is weird to me tho, do you really need to check this = null?
#

if this function , or this line can be executed, theres no way the class will be null right?

wintry quarry
#

It can be

#

Because == null in Unity also means "was this object destroyed?"

torn edge
north kiln
#

try normalizing rotation before you pass it to atan2

#

and zero out the z axis before you do that

torn edge
#

okay i did that, lemme run it rq

#

Nope it still doesn't work

north kiln
#

Starting your video in playmode would also make it way easier to help, I can't skip forward because Discord sucks, and I ain't waiting for the million years yours takes to get there

torn edge
#

sorry 🧍‍♀️

slender nymph
#

the arrow needs to be pointed to the right when its parent object is not rotated

north kiln
#

Though it looks just 90deg offset

torn edge
#

i tried rotating both of them and it still doesnt work

slender nymph
#

Rotate Point is the parent in question, the arrow is a child of that object, no?

nimble apex
#

i gonna leave it as it is lol

frosty lantern
#

is there a way to directly plug in the components added in the gameobject constructor, like
GameObject movePoly = new GameObject($"{name} PolyMove {move} ", typeof(Move) moveScript);

Obviously that doesn't compile, but something similar?

#

or do I just need getcomponent for that

nimble apex
#
if(!(bool)condition?)```

```cs
if(condition ?? false)```

are both the same?
#

condition is a nullable bool

frosty lantern
#

I was hoping it chould be deconstructed like a tuple

slender nymph
#

no, you need to use GetComponent. or better yet just AddComponent yourself and you'll get the component returned without an extra GetComponent call

frosty lantern
torn edge
#

it's 0,0,0 for the transform.rotation of rotate point

slender nymph
#

right, but the arrow needs to be pointing towards the right, not up when its parent object is not rotated

#

you are making the Rotate Point object's X axis point towards the mouse cursor, not its Y axis

torn edge
#

wait s econd

#

oh wow it works now thanks

magic panther
#

what is wrong with this?

#

I use cubes with box colliders as walls

#

and this is supposed to not move when one is in the way

eternal needle
# magic panther what is wrong with this?

add debugs to see if the ray even hits. raycast is just checking a single line, you may want like capsule cast or whatever the shape of your object is. Its possible the ray itself is missing, then you shift the whole object forward even though it cant occupy the space

magic panther
#

I'll try that later today

blissful spindle
#

Hi, I have a question is there any method that works the same way Quaternion.Lerp does but for position not rotation?

blissful spindle
#

well, I am back with yet another question who would have guessed. I have a script that handles weapons in my game but for some reason I cant figure out how do I make a weaponBob system, if there is anyone who wants to have a look and help me feel free to do so I would really appreciate it.https://hatebin.com/eszwjqjmvl

summer stump
#

Also, if isSprinting is true, in what case would isMoving be false? I found that interesting

#

But yeah, you don't actually say what the issue is. So those are just observations

blissful spindle
summer stump
summer stump
#

Oh ok. Looked superficially the same so I wasn't sure. I'll look closer

torn edge
blissful spindle
#

so far only thing I need to figure out is how to take 2 positions and move the object up and down from these 2 but I want them to be code made, I have seen people using Mathf.Cos and sin should I try that?

summer stump
wintry quarry
blissful spindle
summer stump
#

And yeah. Bobx and boby have .02 added every frame and you use the MAX, so that would be problematic.
I think using sin and/or cos would be a better route as you mentioned

torn edge
#

let me try changing that and see

wintry quarry
blissful spindle
torn edge
#

it's middle class

summer stump
torn edge
#

i got it to work 🙏 thank yall

summer stump
#

You need a start point and an end point. Not the current point and a shifting target point

Just use MoveTowards or SmoothDamp

blissful spindle
frosty lantern
#

https://gdl.space/uvabokuyik.cpp
Do you guys know why my move objects don't light up when I hover over them?

I have a few suspicions:
Because I need to have mouse down over the gameobject, even though dragging the mouse keeps the onmousedown for the object true, it means that the mouse isn't updating my move object when I drag my mouse to hover

or

because the object is a child, onmouseenter doesn't work. I saw a thread in the unity forums that it doesn't work if the parent has a rigidbody, so I got rid of that, but it might be something else with that parent child relationship

or

I just made an incorrect statement somewhere

#

it seems like the onmouseenter just doesn't get called

#

even switching to onmousedown and clicking doesn't work

wintry quarry
#

!code

eternal falconBOT
iron steeple
#

im confused im making a code that for physics movement based which i use velocity but im having problem where when i put in update and when it moves the gravity didnt effect the object as in gravity while i did check the box for use gravity but it wont go down unless if i stop using velocity using if condition any idea how to counter this to make when an object moves using a velocity its also effect by gravity or is there another other method


public class Player : MonoBehaviour
{
    Rigidbody rb;
    public float speed = 10.0f;
    float Times = 3f;
    
    
    void Start()
    {
        rb = GetComponent<Rigidbody>();
        rb.velocity = Vector3.right * speed;
    }

    void Update()
    {
        Debug.Log(Times);
        Times = Times - Time.deltaTime;

        if (Times < 0)
        {
            
        }
        else
        {
            
            
        }
       
    }
}
summer stump
#

You are directly setting velicity

#

It overrides any downward velocity from gravity

wintry quarry
#

notice how the y velocity there is 0

#

so you're setting it to 0 each frame

iron steeple
#

ah i see

#

but how do i resolve it

wintry quarry
#

Use the existing y velocity

iron steeple
#

do i use move pos instead?

iron steeple
wintry quarry
#

e.g.

rb.velocity = new(speed, rb.velocity.y, 0);```
wintry quarry
iron steeple
#

ohhhh wait

#

rb.velocity.y means it uses gravity?

wintry quarry
#

in other words - don't change the y velocity

#

gravity comes from the fact that it's a dynamic Rigidbody and you haven't disabled gravity on it

frosty lantern
#

if it's physics based movement you could use rb.AddForce

#

instead of setting velocity

iron steeple
#

because my game is like

#

runner type platform where it moves one direction

#

with constant speed but it keep accelerating

frosty lantern
#

ok so like an autoscroller

iron steeple
#

so im forced to use velocity or movepos

#

mhm

#

i still dont get how rb.velocity.y works

wintry quarry
#

well technically if you do the math right you can achieve the same thing with forces but setting velocity is certainly convenient for it

wintry quarry
#

compare that with using 0

#

which is what you did before

summer stump
iron steeple
wintry quarry
summer stump
frosty lantern
summer stump
wintry quarry
#

what do you mean by "default from rigidbody"?

#

velocity is a property on the Rigidbody, yes, naturally. It's the same property you're setting

summer stump
#

It is a property that exists in the rigidbody class, if that's what you're asking

frosty lantern
summer stump
#

You do not need to CREATE a rb.velocity.y

#

You literally just write that

iron steeple
#

idk im not good at explaining

summer stump
iron steeple
#

ah i get it now

#

alright let me try

frosty lantern
iron steeple
#
rb.velocity = new Vector3(speed, rb.velocity.y, 0);
#

im replacing it

wintry quarry
#

Just for reference your previous code was equivalent to:

rb.velocity = new Vector3(speed, 0, 0);```
#

So instead of setting y velocity to 0, we just set it back to what it already is - i.e. we don't change it at all

iron steeple
#

which is rb.velocity.y

wintry quarry
#

what do you mean

#

y is the second number

frosty lantern
iron steeple
#

yeah thats what i meant mb

frosty lantern
#

it's one of the 3 components (x, y, z) of your velocity

#

you're doing an 2d so you don't wanna mess with z

frosty lantern
iron steeple
#

i have no idea how do all of that stuff yet

#

well i used rb.velocity.y and it broke

#

it just instantly broke through the floor

frosty lantern
iron steeple
#

no

frosty lantern
iron steeple
#

the object just no clipped

#
public class Player : MonoBehaviour
{
    Rigidbody rb;
    public float speed = 10.0f;
    float Times = 3f;
    
    
    void Start()
    {
        rb = GetComponent<Rigidbody>();
        
    }

    void Update()
    {
        Debug.Log(Times);
        Times = Times - Time.deltaTime;

        if (Times < 0)
        {
            
        }
        else
        {
            Vector3 movement = new Vector3(1, rb.velocity.y, 0);
            rb.velocity = movement * 2;

        }
       
    }
}
#

nvm

#

i put 2

#

wait

frosty lantern
#

the * 2 doubles the gravity every frame too

wintry quarry
iron steeple
#

well it kinda works but its not moving

#

i erased the *2

wintry quarry
#

why not use:
rb.velocity = new Vector3(speed, rb.velocity.y, 0);

iron steeple
#

because the speed isnt for x axis

wintry quarry
#

what's it for

iron steeple
#

i forgot to removed it

#

thats not supposed to be there

#

well theres a problem now it works but now the x axis isnt moving.

frosty lantern
wintry quarry
iron steeple
#

i mean i did move but it stopped

#
public class Player : MonoBehaviour
{
    Rigidbody rb;
    public float speed = 10.0f;
    float Times = 3f;
    
    
    void Start()
    {
        rb = GetComponent<Rigidbody>();
        
    }

    void Update()
    {
        Debug.Log(Times);
        Times = Times - Time.deltaTime;

        if (Times < 0)
        {
            
        }
        else
        {
            Vector3 movement = new Vector3(1, rb.velocity.y, 0);
            rb.velocity = movement * 2;

        }
       
    }
}
frosty lantern
iron steeple
#

nope

#

actually lets try

wintry quarry
#

which is going to destroy everything

iron steeple
#

alright i deleted it

#
public class Player : MonoBehaviour
{
    Rigidbody rb;
    float Times = 3f;
    
    
    void Start()
    {
        rb = GetComponent<Rigidbody>();
        
    }

    void Update()
    {
        Vector3 movement = new Vector3(1, rb.velocity.y, 0);
        rb.velocity = movement;

    }
}
#

do i put

wintry quarry
#

definitely not

frosty lantern
#

no that's gonna make you exponntially slower

wintry quarry
#

what are you trying to do???

#

You haven't even explained that

#

so it's very hard to help

frosty lantern
#

he's trying to speed up over time

iron steeple
#

i wanna make a runner game its like

frosty lantern
#

acceleration

iron steeple
#

subway surfer

#

nope i dont want accelration

wintry quarry
#

What was wrong with the speed stuff you had before

#

I don't understand why you went away from that

iron steeple
#

its not supposed to be in the code thats all

wintry quarry
#

Why isn't it supposed to be in the code?

iron steeple
#

well its not used / planned to change the variable

#

let me try to ss

wintry quarry
#

You need to explain what this script is supposed to be doing

#

What direction should the player be moving in, and at what speed?

iron steeple
#

i want this player object to go forward

wintry quarry
#

how do you define "forward"

iron steeple
#

vector3.right

wintry quarry
#

then the original code you had with the speed is just fine

iron steeple
#

alright ill try again

wintry quarry
#

just make sure you set the speed to the desired speed

#

in the inspector

frosty lantern
wintry quarry
iron steeple
#

i mean like speed variable isnt supposed to be in the vector3 but i wanted to make another variable for replace that

#

but hey it worked out finally

#

i just gotta freeze the rotation

#

now i gotta make it so when it hit the end of the brick it moves it back to the start point which is my mechanic of the game

#

thanks @wintry quarry

#

and @frosty lantern

frosty lantern
frosty lantern
slender nymph
abstract finch
#

Is using a CharacterController component for something like a dragon a bad idea vs using Rigidbody + some kind of mesh collider? The dragons shape doesnt really fit the charactercontroller's capsule shape

night raptor
# abstract finch Is using a CharacterController component for something like a dragon a bad idea ...

Only if the moving mechanic is very similar to a humanoid I'd consider using CC because if lets say the dragon needs to fly over rocks and change the flying height, you will have troubles getting what you want. The collider being super simplified in itself usually isn't bad thing though and can just make the movement more consistent and smooth (mesh colliders might be bit clumsy againts the walls etc.)

abstract finch
#

it would be more like an egg

#

I just dont want the player to be able to clip into the dragon

night raptor
# abstract finch I just dont want the player to be able to clip into the dragon

That sounds like separate problem from the movement. Most games use compound colliders (or some sort of mesh colliders, unitys mesh collider might not be the best fit) to do the hitboxes and capsule or cylinder (doesn't exist in unity) collider for the movement for smoother experience. Similarly you could have the dragon movement use simplified collider shape and have separate set of colliders for the players to collide against

abstract finch
#

I have a system similar atm where hitboxes are on their own layer

night raptor
#

you can use the Layer Collision Matrix to choose which layers interact with each other on the physics simulation

abstract finch
#

I'm planning on using BOTH navmeshagent and character controller for movement. NavMesh agent for standard movement and the controller for stuff like dashing, or strafing side to side. The reasoning is because if I use navmesh agent for dashing it will try to avoid obstacles and other agents, in this case I just want it to go in a straight path. Is this a good idea?

eternal needle
abstract finch
eternal needle
#

the path from the navmesh already takes that all into account

#

you would just be moving the cc along the same path

#

Itll be more annoying down the line when you have 2 movement systems on 1 object

abstract finch
#

i see i have what you mentioned atm,

    {
        _navMeshAgent.ResetPath();
        var newPath = new NavMeshPath();
        NavMesh.CalculatePath(transform.position, targetPos, _navMeshAgent.areaMask, newPath);
        Vector3[] corners = newPath.corners;
        if (corners.Length > 2)
        {
            BezierCurve[] curves = new BezierCurve[corners.Length - 1];

            SmoothCurves(curves, corners);
            corners = GetPathLocations(curves);
        }
        return corners;
    }```
#

This is one of the functions that generates the paths

nimble apex
#

if a coroutine is executing yield return wait , can stopcoroutine() stop it?

abstract finch
#

it should

eternal needle
slender nymph
#

StopCoroutine basically just stops it yielding and prevents it from resuming

abstract finch
eternal needle
#

i understand that part, i was just referring to the 2 methods which dont exist by default

abstract finch
#
    {
        for (int i = 0; i < curves.Length; i++)
        {
            if (curves[i] == null)
            {
                curves[i] = new BezierCurve();
            }

            Vector3 position = corners[i];
            Vector3 lastPosition = i == 0 ? corners[i] : corners[i - 1];
            Vector3 nextPosition = corners[i + 1];

            Vector3 lastDirection = (position - lastPosition).normalized;
            Vector3 nextDirection = (nextPosition - position).normalized;

            Vector3 startTangent = (lastDirection + nextDirection) * _smoothingLength;
            Vector3 endTangent = (nextDirection + lastDirection) * -1 * _smoothingLength;

            curves[i].Points[0] = position; // Start Position (P0)
            curves[i].Points[1] = position + startTangent; // Start Tangent (P1)
            curves[i].Points[2] = nextPosition + endTangent; // End Tangent (P2)
            curves[i].Points[3] = nextPosition; // End Position (P3)
        }


        // Apply look-ahead for first curve and retroactively apply the end tangent
        {
            Vector3 nextDirection = (curves[1].EndPosition - curves[1].StartPosition).normalized;
            Vector3 lastDirection = (curves[0].EndPosition - curves[0].StartPosition).normalized;

            curves[0].Points[2] = curves[0].Points[3] +
                (nextDirection + lastDirection) * -1 * _smoothingLength;
        }
    }```
#
    {
        Vector3[] _pathLocations = new Vector3[curves.Length * _smoothingSections];

        int index = 0;
        for (int i = 0; i < curves.Length; i++)
        {
            Vector3[] segments = curves[i].GetSegments(_smoothingSections);
            for (int j = 0; j < segments.Length; j++)
            {
                _pathLocations[index] = segments[j];
                index++;
            }
        }

        _pathLocations = PostProcessPath(curves, _pathLocations);

        return _pathLocations;
    }
#

Its to smooth out the paths

green ether
#

add c# to your code blocks

#

For proper formatting

#

!code

eternal falconBOT
onyx tusk
#

how 2 add text 2 3d object? after this lines:c# figure.AddComponent<TextMeshPro>(); figure.GetComponent<TextMeshPro>().text = $"{this.GetType()}";
i have this

#

before was this

vital tartan
#

Try add text to child object

hexed terrace
onyx tusk
onyx tusk
hexed terrace
onyx tusk
hexed terrace
#

the simplist way is transform.localScale

#

RectTransform extends Transform .. and a Prefab is a GameObject with whatever you put in it.

#

If you set up the prefab correctly, you shouldn't need to resize anything after spawning.

young fossil
#

Is it better use a coroutine or make my own timer using Time.time, for let's say, tracking the time between waves in survival game?

fading rapids
#

hi i have this script which loads a scene upon trigger with an object with a certain tag, if the blue obstacle triggers with the object with the tag Red(the red ball) the scene should reset, my ball has a circle collider 2d and my obtsacle box collider 2d with trigger, the issue is that nothing is happening, even if i set both objects to normal colliders it isnt even colliding they are just going trough eachother

fading rapids
#

fixed it

#

ty for help tho

bold nova
#

Does anyone know why ignore layer with raycast may not work? I project a ray from a rifle and depending if it is on the enemy or player it should ignore corresponding layer. But for some reason it doesnt.

        if (enemy != null)
        {
            isOnEnemy = true;
            ignoreLayers = transform.parent.gameObject.layer;
        }
        else
        {
            ignoreLayers = transform.parent.transform.parent.gameObject.layer; // rifle sits on camera that sits on player
        }

and thats how i raycast

        if (Physics.Raycast(rayCastOrigin.position, direction, out hit,
            _weaponInfo.Distance, ~ignoreLayers))
#

Even though it does find the right layer, it just doesnt ignore it

languid spire
#

because a Layer Id is not a Layer Mask

bold nova
#

I should use GetMask? I thought it converts it to integer anyway

languid spire
#

use

ignoreLayers = 1 << transform.parent.gameObject.layer;
#

this turns the layer id into a layer mask for that id

bold nova
#

aahhh, it works now, thanks

sick ocean
#

why there is no error

#

on Debug.Log();

languid spire
#

because it does not say Log

hexed terrace
#

!VS

eternal falconBOT
#
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)

hexed terrace
#

configure your Visual Studio ☝️

fringe plover
#

!code

eternal falconBOT
fringe plover
#

https://hatebin.com/fogombesds
Can someone help?
Failed to save screenshot: Could not find a part of the path "C:\Users\PC\AppData\LocalLow\SBA_FAN\SBA_ Merge\screenshots\Screenshot 29.04.2024 20:45:54.png".

And any way to make code better? I heard that texture may use memory if i wont destroy it, but when i destroy it sprite is white

#

(SaveLastShot() method)

burnt vapor
#

As for the error, perhaps the system gets confused by all the special characters in the path (., :). Consider formatting your datetime better

fringe plover
#

oh.. okay thanks

burnt vapor
#

If you're going to use the first answer, please switch the day and the month from that code because then it actually orders properly

fringe plover
#

okay tysm

burnt vapor
#

NP

abstract finch
#
    {
        if (_state != State.Attack && _currentDistanceToTarget < _closestAttackDistance) // must attack because player is too close
        {
            EnterState(State.Attack);
            return;
        }
        switch (_state)
        {
            case State.Idle:
                break;
            case State.GetInFightingDistance:
                if (_currentDistanceToTarget < _fightingDistance)
                {
                    EnterState(_blackBoard.RequestAddAttacker(this) ? State.TryAttack : State.Strafe); // if there are slots to attack do it if not strafe
                }
                break;
            case State.TryAttack:
                break;
            case State.Strafe:
                break;
        }
    }```

At a glance does this function look bad at all? The fact that there are if statements above the switch cases
hexed terrace
#

It's fine to have an if above a switch

abstract finch
#

thanks

#

I'm finding alot of duplicate code in these switch cases is it better to just get rid of them and use if else?

languid spire
#

also use default

abstract finch
#

is it just creating a function?

#

oh i see,

            case State.Strafe:
                if (_actionCr != null) { StopCoroutine(_actionCr); }
                _actionCr = StartCoroutine(HandleStrafe());
                break;```
languid spire
#
switch (_state)
        {
            case State.Idle:
            case State.TryAttack:
            case State.Strafe:
                break;
            case State.GetInFightingDistance:
                if (_currentDistanceToTarget < _fightingDistance)
                {
                    EnterState(_blackBoard.RequestAddAttacker(this) ? State.TryAttack : State.Strafe); // if there are slots to attack do it if not strafe
                }
                break;
        }

although I see little point of a switch with only one active case

abstract finch
#
            case State.TryAttack:
                float minDist = _state == State.GetInFightingDistance ? _fightingDistance : _closestAttackDistance;
                if (_currentDistanceToTarget > minDist)
                {
                    _mover.UpdatePathfinding(_blackBoard.TargetPos, true);
                    targetVelocity = _mover.GetPathfindingVelocity() * _moveSpeed;
                    targetLookDirection = _mover.GetPathfindingVelocity();
                }
                break;```
Just made a use case for one combining group case together
#

the only different here is one float vlaue

languid spire
#

then use default and add them as required

abstract finch
#

ok

vagrant zealot
#

hey !

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

public class PlayerAttack : MonoBehaviour
{
    [SerializeField] private float attackCooldown;
    [SerializeField] private Transform firePoint;
    [SerializeField] private GameObject[] fireballs;
    float cooldownTimer = Mathf.Infinity;


    void Update()
    {
        if (cooldownTimer > attackCooldown && Input.GetKey(KeyCode.Space))
        {
            Attack();
        }

        cooldownTimer += Time.deltaTime;
    }

    void Attack()
    {
        cooldownTimer = 0;

        int index = FindFireball();
        if (index != -1)
        {
            fireballs[index].transform.position = firePoint.position;
            fireballs[index].GetComponent<Projectile>().SetDirection(Mathf.Sign(transform.localScale.x));
        }
        //
    }

    private int FindFireball()
    {
        for (int i = 0; i < fireballs.Length; i++)
        {
            if (!fireballs[i].activeInHierarchy)
            {
                return i;
            }
        }
        // 
        return 0;
    }

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

public class Projectile : MonoBehaviour
{
    [SerializeField] private float speed;
    private bool hit;
    private Rigidbody2D projectile;
    private float direction;
    private BoxCollider2D boxCollider;
    private float lifetime;

    private void Awake()
    {
        boxCollider = GetComponent<BoxCollider2D>();
        projectile = GetComponent<Rigidbody2D>();
    }

    private void Update()
    {
        if (hit) return;

        float movementSpeed = speed * Time.deltaTime * direction;
        transform.Translate(movementSpeed, 0, 0);

        lifetime += Time.deltaTime;
        if (lifetime > 5) gameObject.SetActive(false);
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        hit = true;
        boxCollider.enabled = false;
    }

    public void SetDirection(float _direction)
    {
        lifetime = 0;
        direction = _direction;
        gameObject.SetActive(true);
        hit = false;
        boxCollider.enabled = true;

        
        float localScaleX = Mathf.Abs(transform.localScale.x); 
        if (_direction < 0) 
            localScaleX *= -1; 

        transform.localScale = new Vector3(localScaleX, transform.localScale.y, transform.localScale.z);
    }


    void Deactivate()
    {
        gameObject.SetActive(false);
    }
}

I have this code. I am trying to shoot with my spaceship but i can only shoot 1 fireball per time. I want to shoot multiple fireballs how can i achieve that?

wintry quarry
#

You'll also need to disambiguate the multiple balls in space somehow.

amber basin
#

I have a question but i am not sure how to go about it. I want to make it so that you can only move (with the camera) around my game a certain amount before the camera stops. I am making a silly little tower defence game and i dont want the people playing it to be able to just fly away from the map with the Camera. I can send the Camera Code i have so far and maybe someone can help me from there?

thorn holly
#

Sure, send code

amber basin
cosmic dagger
amber basin
languid spire
#

So you are clamping y, why not x and z as well ?

amber basin
karmic kindle
#

I'm trying to use this https://docs.unity3d.com/ScriptReference/Mathf.Approximately.html so that my "poison attack" only works on an exact number but it will attack continuously. Have I implemented it wrong or is there a better way to do this? if (poisonEnemy) { countdownPoison -= Time.deltaTime; if (Mathf.Approximately(1.0f, 10.0f / 10.0f)) { TakeDamage(0f, 0f, 0f, magicalStrengthPoison); Debug.Log("I'm taking damage: " + magicalStrengthPoison + " for " + countdownPoison + "."); } if (countdownPoison <= 0) { poisonEnemy = false; //Debug.Log("Poison end"); } }

wintry quarry
#

isn't this just sying "is 1 approximately 1"??

#

Won't this always be true?

#

What are you trying to check with this code?

cosmic dagger
karmic kindle
#

I'm inflicting poison on an enemy but I only want the damage to effect the enemy at each 1s interval - at the moment it's spamming it continuously through the loop

wintry quarry
#

They just blindly copied the doc example it appears

#

It's unclear what you're actually wanting to compare here

wintry quarry
neon ivy
#

so I made a spline using some lerps, but when I look at the image, the blue dots aren't evenly spaced over a bezier curve despite being set at t = i / circle count
I'm afraid that objects following this spline won't move at a constant speed, atleast if I use the speed to set it to a certain t value along the curve.
here's the code: https://gdl.space/tilivacego.cs
is there a way to smooth these blue circles out? or does it not matter? new to splines so trying to learn about them

wintry quarry
neon ivy
#

not using a library, made it myself

wintry quarry
#

Unity's spline library allows calculating distance along the spline as well as the time value

#

If you wrote it yourself you'd have to provide for the ability to interpolate with real distance and not just the t value

neon ivy
#

how do I figure out the distance? xD

wintry quarry
#

IDK

#

math

#

I would have just used the existing Spline library which has this ability already

neon ivy
#

trying to learn splines and Bezier curves so wanted to code it myself, I also need to save the splines in json, wasn't sure if libraries would let me do that so...

thorn holly
neon ivy
#

xD

#

hmm, google suggests chopping it up into pieces and approximating it

languid spire
#

that is indeed the solution. The smaller the pieces the more accurate but slower the answer

neon ivy
#

I don't need to do it every frame so I should be fine

#

it's for a rhythm game to make the notes follow a path, basically just need to load the spline once from the skin data

frigid sequoia
neon ivy
#

what do you mean?

solid cipher
#

@neon ivy do you have any knowledge with AR

neon ivy
#

? xD not really, why?

frigid sequoia
#

You don't neccessarily need a path for that

neon ivy
#

I need a line for it to follow no?

#

I want to give players the option to make their own skins so I want to have as much creative input for them as I can, splines are very nice for that

frigid sequoia
neon ivy
#

yea

frigid sequoia
#

Well that's oddly specific

neon ivy
#

I just think it's neat

frigid sequoia
#

So your issue is that the points along the path are not evenly spaced?

neon ivy
#

I mean the solution has been found

#

if I figure out the length of each curve and the total I can remap the position to a t value on the curve

#

and I can be pretty accurate with the curve approximation as I only need to load like 4

onyx tusk
#

y my cone is bigger than all other figures? all of them r primitives that have the same scale (except cilinders, they have in 2 times smaller y scale). here is with msg a model of the cone

burnt vapor
onyx tusk
languid spire
#

Also you might like to use the correct labels for your pieces. Rook, Knight and Bishop

onyx tusk
swift crag
#

some of those sounds like chinese chess pieces

languid spire
#

then google translate is wrong

swift crag
#

although elephant corresponds to bishops, not rooks

onyx tusk
chrome tide
#

I have a menu canvas, which i scale to create an animation. For and example, this is my opening animation, which happens when the game is launched:

public void OpeningAnim()
{
    rect.DOScale(new Vector2(rect.localScale.x, 1f), duration).SetEase(Ease.OutBack);
}```

the problem is that the only UI element that's visible upon animating the canva is an image (it's called Bar) between the game title and button. I'm sure that the animation is working, because i can see the Bar getting scaled properly, while other UI elements arent visible. I have no idea what the issue is, it started happening after i changed the `rect.localScale.x` to `0.5f`. Here are both of my Play button and Bar configurations, if it helps.
chrome tide
swift crag
#

Select your canvas in the hierarchy and hit F to focus on it

#

A "Screen Space - Overlay" canvas is drawn directly on top of the rendered frame. It doesn't really exist in the game world.

#

Although, it sounds like the UI looked right before you scaled things

chrome tide
#

i might try if it works right when i dont scale it.

bitter crown
#

hey can someone help me out rq

frigid sequoia
bitter crown
#

how do i add an offset to the rotation of a camera

swift crag
#

It would also be helpful to see a non-2D view of the canvas in the scene view

willow scroll
bitter crown
#

imma send a screenshot 1 sec

stuck palm
#

is onenable called on a child of a parent that was enabled

#

if the child was never setinactive itself but set inactive by assoscation

chrome tide
swift crag
#

What are you scaling?

willow scroll
swift crag
chrome tide
swift crag
#

because that causes components to get enabled and disabled as well, yes

willow scroll
swift crag
icy radish
#

hello everyone! I'm newbie at unity and I have exam tomorrow can somebody help me please?

swift crag
#

and enabling or disabling other components (more specifically, behaviours) does not cause a component's OnEnable/OnDisable to run

willow scroll
chrome tide
swift crag
#

It's also now possible for UI elements to wind up getting clipped by the camera, or to otherwise get occluded by other things

#

I wonder if your text is positioned a bit wrongly in the Z axis

#

that could makes it wind up behind the black background when you scale the canvas

willow scroll
swift crag
#

right (:

chrome tide
swift crag
#

Get rid of the black background and see how it behaves.

willow scroll
#

@stuck palm So if you're checking for the GameObject's actual state, you should consider using activeInHierarchy instead of activeSelf

swift crag
#

you can deactivate the entire canvas

swift crag
willow scroll
frigid sequoia
willow scroll
#

Honestly, I don't even know many use-cases for activeInHierarchy

chrome tide
swift crag
#

For example -- my menu system deactivates each menu screen when it's not being used

frigid sequoia
#

By default they seem to work on layers just fine, but, on runtime, specially if you animate stuff on the Canvas they seem to overlap ever so slighty

willow scroll
swift crag
#

Elsewhere, I need to check if the currently selected game object is deactivated, so that I can select something else (so that your selection ins't lost)

swift crag
swift crag
#

I need to know if the object is effectively activated or not

swift crag
#

er, wait, you won't see them by default..

#

yeah, they won't appear in the game view

swift crag
chrome tide
swift crag
#

I wonder if they are z-fighting with the text

#

but that shouldn't really happen with UI rendering, still...

#

and the first piece of text has no background at all

#

and it's missing as well

frigid sequoia
#

It worked for me before

swift crag
chrome tide
chrome tide
bitter crown
#

can someone please help me with this im trying to offset the camera rotation

swift crag
#

quaternions are combined with the * operator

bitter crown
swift crag
#

q1 * q2 gives you the result of applying q1 followed by q2

#

also, RotateOffset is not a quaternion

#

you can get one with Quaternion.Euler

bitter crown
chrome tide
#

it shows the text

bitter crown
#

tbh i dont know what a Quaternion is so how exactly do i fix it?

frigid sequoia
# bitter crown

RotateOffset is a Vector3, Quaternions are sorta of a Vector4

#

Also, camelCase is wrong there, but whatever

bitter crown
#

so make it a vector4?

swift crag
bitter crown
#

alr thx

swift crag
frigid sequoia
#

Quaternions are so weird man, I don't know why I would ever use them instead of Euler

swift crag
#

you don't have to know how quaternion math works, just like you don't have to know how matrix multiplication works to use transform.TransformPoint

#

and how you don't have to know vector math to use Vector3.Dot

#

the struct probably should've just been called Rotation

chrome tide
swift crag
#

I would suggest just using a screen space mode if possible

#

They're simpler to deal with.

chrome tide
#

ok

#

thanks

swift crag
#

Note that you won't be able to scale the canvas in that case: but you can just scale a child of the canvas

bitter crown
#

Tysm btw the problem is fixed

swift crag
#

you can also use += and *= to simplify those lines, btw

frigid sequoia
#

Better use paste sites

icy radish
#

let me rewrite again then

swift crag
#

!code

eternal falconBOT
icy radish
willow scroll
#

The result's x and y axes should be assigned to the object. The z axis should stay the same, as it's always 0 when converted from the initial Vector2

#

Also consider making a single method with a boolean as a single parameter instead of the methods TurnOnWeaponSystem and TurnOfWeaponSystem (maybe you meant Turn Off ?)

#

The OnTriggerEnter and OnTriggerExit' logics can also be simplified using a method

icy radish
willow scroll
#

Also you might consider rewriting this

if (itCanActivate && Input.GetKeyUp(KeyCode.E) && !isUsing)
{
    TurnOnWeaponSystem();
    isUsing = true;
}
else if (isUsing && Input.GetKeyUp(KeyCode.E))
{
    TurnOfWeaponSystem();
}

to this

if (Input.GetKeyUp(KeyCode.E))
{
    if (isUsing)
        ActivateWeaponSystem(true);
    else
    {
        if (itCanActivate)
            ActivateWeaponSystem(false);
    }
}
#

When "translating" literally

#

But I would consider managing everything in that method

if (Input.GetKeyUp(KeyCode.E))
    ActivateWeaponSystem(isUsing);
willow scroll
chrome tide
willow scroll
icy radish
willow scroll
chrome tide
#

its supposed to be this

#

i might try disabling the script and not animating it.

willow scroll
willow scroll
#

Have you tried simply reloading Unity?

chrome tide
#

i will try now

willow scroll
#

It may be the issue with the Camera

#

And I would assume, there is a possibility of it being a Unity's bug

chrome tide
#

it still happens

willow scroll
#

But do you have any scripts which interact with the objects inside of your UI?

#

Change their Materials / z positions, perhaps

#

Are there even any scripts assigned in this scene?

#

Maybe, the camera's position gets changed?

#

Or the texts'

eternal falconBOT
willow scroll
#

This, actually, might sound like your issue

chrome tide
# willow scroll But do you have any scripts which interact with the objects inside of your `UI`?

there's only these lines of code which fill/unfill the bar (bar is a line between the title and Play button):

bar.fillAmount = 0f;

private IEnumerator FillBar()
{
    yield return new WaitForSeconds(1);
    bar.DOFillAmount(1f, duration).SetEase(Ease.InOutSine);
}

public void UnfillBar()
{
    bar.transform.localScale = new Vector2(bar.transform.localScale.x * -1f, bar.transform.localScale.y);

    bar.DOFillAmount(0, duration).SetEase(Ease.InOutSine);
}```

the UnfillBar() flips the bar in horizontal direction so instead of unfilling from right to left, it will unfill from left to right
warm geode
#
if(Input.GetKeyDown(crouchKey)) {

     capsuleCollider.height = 1f;
     capsuleCollider.center = new(0, 0.5f, 0);
 }

 if(Input.GetKeyUp(crouchKey))
 {
     
     capsuleCollider.center = new(0, 1f, 0);
     capsuleCollider.height = 2f;```
willow scroll
willow scroll
#

Also, you don't have to write a cs markdown twice or once inside of the block

warm geode
#

im trying to make my character crouch by changing the capsule height and the center

summer stump
warm geode
#

but it isnt working when i uncrouch, my collider is not getting resized for some reason

chrome tide
verbal dome
warm geode
#

because the center affects the gravity? i assumed that

chrome tide
#

can i scale the canvas if its set to Screen Space - Overlay ?

neon ivy
#

ok so I'm doing a length approximation of my bezier curves by chopping it up into x amount of straight lines and checking their distance, I was checking how high x has to be but for 1000 and for 1 it's giving the same answer so I'm guessing there's a bug.
this is the code

public void ApproximateLength()
{
    float total = 0;
    data.CurveLengths.Clear();
    for(int i = 0; i < data.curves.Count; i++)
    {
        BezierCurve curve = data.curves[i];
        float previousT = 0;
        float curveLength = 0;
        for(int j = 1; j <= data.lengthAproximationAccuracy; j++)
        {
            float currentT = j / data.lengthAproximationAccuracy;
            curveLength += (curve.GetPosOnCurve(previousT) - curve.GetPosOnCurve(currentT)).magnitude;
            previousT = currentT;
        }
        Debug.Log($"curve {i} has a length of: {curveLength}");
        data.CurveLengths.Add(curveLength);
        total += curveLength;
    }
    Debug.Log($"total length is: {total}");
    data.TotalCurveLength = total;
}
``` anyone able to see what is wrong?
warm geode
#

another approach i had previiously was to scale down the entire player and add force downwards

verbal dome
#

If that's even what you meant

warm geode
#

ok i will try without changing the pivot

verbal dome
#

You never said what the problem is though

willow scroll
verbal dome
#

@warm geode To me it looks like it should work. Can you share the whole script in a paste site?

warm geode
#

its a big script but ok

verbal dome
willow scroll
eternal falconBOT
warm geode
#

i pasted the code there now what

willow scroll
verbal dome
warm geode
#

there it is

summer stump
icy radish
warm geode
#

i also search for tutorials but everyone use the scale character and add force down approach

languid spire
warm geode
#

not good for actual 3d models

frosty hound
willow scroll
polar acorn
icy radish
fallen ledge
#

where are the project templates stored? I there are only 2d, 3d and 2d URP templates in C:\Program Files\Unity\Hub\Editor\version\Editor\Data\Resources\PackageManager\ProjectTemplates, but not the other ones

icy radish
willow scroll
icy radish
willow scroll
# icy radish exactly

Good luck! You'll need it if you want to drag objects without knowing how methods work.

sick ocean
frosty hound
neon ivy
frosty hound
verbal dome
sick ocean
#

why there is no error

willow scroll
eternal falconBOT
summer shard
#

do i need to use animator for animating the item being pulled out? rn i have a script that lerps it but when i move my character, it lerps it too, and i don't want that effect

private void Update() {
    if (HeldItemObject) HeldItemObject.transform.position = _handPosition;
    _handPosition = Vector3.Lerp(_handPosition,
        HeldItem == Item.None ? hiddenTransform.position : handTransform.position, (HeldItem == Item.None ? hideTime : showTime) * 100f * Time.deltaTime);
    //Rest of code
}
fallen ledge
#

how can I delete a project template from unity hub? I can't find the option anywhere

hexed terrace
hollow dawn
#

im using this sprint script but when I attached it to my player it doesn't seem to work how do I fix this? using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SprintScript : MonoBehaviour
{

public bool isMoving = false;
public float movementSpeed = 125;

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

// Update is called once per frame
void Update()
{
    if(Input.GetKeyDown("w"))
    {
        isMoving = true;
    }

    if(Input.GetKeyUp("w"))
    {
        isMoving = false;
    }

    if(Input.GetKey(KeyCode.LeftShift) & isMoving == true)
    {
        transform.position += transform.forward * Time.deltaTime * movementSpeed;
    }
}

}

eternal falconBOT
deft grail
warm geode
#

the debug logs are working

#

its weird when i crouch im going slow but when i uncrouch its working fine

#

i can send a video if you want

#

now i figured it out

hollow dawn
warm geode
#

the capsule height is halved and it is floating in the air

#

when i crouch and when i uncrouched it just gets back to its normal size

#

i guess ill use two different colliders instead

deft grail
void notch
verbal dome
warm geode
#

no that doesnt work because it only modifies the postion of the pivot and the collider still floatas

#

i fixed it now by keeping two colliders

#

and added camera movement as well

ebon vessel
#

Guys i really need someones help about unity

stuck palm
#

Does changing target frame rate persist along scenes?

deft grail
ebon vessel
#

Helping with backup files

#

My project has gone

deft grail
polar acorn
ebon vessel
#

I didin't make backup

#

how can i use version control?

keen dew
#

It's too late now, it's not a time machine

hexed terrace
#

don't cross post

warm tree
#

I understand that this is all to do with mathematics and randomness but surely I would have a different result now. I have:

Random.Range(1,2)

It is only printing 1

warm geode
#

now i have even bigger problems f me

warm tree
#

I would've thought that 3 would be included too

polar acorn
warm geode
#

i added camera movement using interpolation but it only works for crouching down and not for crouching up

polar acorn
#

So, since it can't roll a 2 it's only options are 1

warm geode
#
{
    float targetHeight = isCrouching ? crouchingHeight : standingHeight;
    float currentHeight = cameraTransform.localPosition.y;
    float heightDiff = targetHeight - currentHeight;

    float elapsedTime = 0.0f;
    while (Mathf.Abs(heightDiff) > 0f)
    {
        elapsedTime += Time.deltaTime;
        float lerpValue = Mathf.Lerp(0.0f, 1.0f, elapsedTime * crouchSpeed);
        cameraTransform.localPosition = new Vector3(cameraTransform.localPosition.x, currentHeight + (lerpValue * heightDiff), cameraTransform.localPosition.z);
        yield return null;
    }
}```
#

if anyone experienced in making character controllers pls help

warm tree
# polar acorn So, since it can't roll a `2` it's only options are `1`

Right now that makes sense, for some reason this area has had my head all around the place. I have somehow managed to make this whole system I have now without watching tutorials or anything (I have previous coding experience from UE5 / Roblox) but this random number part puzzled me haha

lost anvil
#

what do you need to use at the top of a script to access postprocess volumes?

#

base render pipeline