#πŸ’»β”ƒcode-beginner

1 messages Β· Page 142 of 1

deft monolith
#

Hi again! Thanks for the help earlier. So I tried using slerp, but I'm still getting the same problem of the rotation applying on its own axis. So for example, when it rotates 90deg on X axis, I later want to apply a 90 rotation on the Z axis, but it will apply Z axis locally which is Y in world axis.. Why can't I wrap my head around a good solution here..

late burrow
#

whats the best way to spin a disk based on cursor position

frosty hound
#

That could mean a bunch of different things. How is it going to work, mechanically?

wintry quarry
#

It's not essentially any different from any 2d/topdown "aim-at-cursor" implementation I would think

sleek notch
#

Why it doesn't work

#

the cameras are gameObject

polar acorn
sleek notch
#

I don't know how to check if it is active

hollow field
#

Feel like I should know this but I'm a bit rusty. I currently have a Game Object with a Canvas as a child and a Text (TMP) as a child of the Canvas.
I am trying to instantiate the object and change the text. I currently have

GamObject NewDot = Instantiate(Dots, new Vector3(Random.Range(-10, 10), Random.Range(-5, 5)), Quaternion.identity);
NewDot.GetComponentInChildren<TextMeshPro>().text = i.ToString();

but it keeps returning " reference not set to an instance of an object" for the 2nd line.

Any tips?

polar acorn
#

Considering you said it was a canvas, you probably want to get a UI TextMeshProUGUI instead of a world-space TextMeshPro (or just use their shared parent type, TMP_Text)

languid spire
#

<TMP_Text>

hollow field
#

thanks both

#

its been too long since I did Unity stuff. more used to the old fashioned Text fields

dark oak
#

Hi guys, I'm having issues using unity 2017.4: finding text mesh Pro: how can i fix This?

languid spire
dark oak
languid spire
#

win 7 32 bit, none, win 7 64 bit, docs say anything up to 2021, whether it works or not is another question

jaunty wing
#

Does anyone know how I would go around clamping the camera to 90 degrees?

PlayerCamera.transform.Rotate(-MouseDelta.y * Sens,0,0);
slender nymph
#

don't use transform.Rotate if you want to clamp the rotation. instead keep track of the current desired rotation in a float variable that you add to when you have mouse input. then you clamp that and assign it as the rotation using Quaternion.Euler or something

#

if you search "clamp camera" in this discord you'll find plenty of examples of how to do that

#

also obligatory: use cinemachine. it already has clamping built in

jaunty wing
#

Thanks

#

πŸ‘

delicate portal
#

I implemented a pickup and a drop system for my FPS game, but if I drop a 'pistol' for example, it starts flying in the Y axis upwards. It has a rigidbody, and I'm just enabling gravity when dropping and adding some force relative to the player's forward vector. Why can it be? Also other objects dont do this, they work just fine.

wintry quarry
polar acorn
jaunty wing
#
// Mouse & Camera Movement
        Cursor.lockState = CursorLockMode.Locked;

        DesiredRotationX += Input.GetAxis("Mouse X") * Sens;
        DesiredRotationY += Input.GetAxis("Mouse Y") * Sens;

        var ClampedRotationY = Mathf.Clamp(DesiredRotationY,-90f,90f);

        transform.rotation = Quaternion.Euler(0f,DesiredRotationX,0f);
        PlayerCamera.transform.rotation = Quaternion.Euler(-ClampedRotationY,0f,0f);

My Player is rotating correctly on the X axis but my camera doesn't move with the player

#

On the rotation

#

it keeps looking in the same direction

wintry quarry
jaunty wing
#

Yeah but the Y rotation is working correctly

wintry quarry
#

show how the hiearchy is set up

jaunty wing
wintry quarry
#

and the inspector of the script (and which object the script is on)

wintry quarry
delicate portal
delicate portal
rotund hull
#

how can i delete a tile in a tilemap in code

dry tendon
#

Good night everyone... I have one little question related to boxhelps... and if someone could help me i'll really appreciate it: How do I make Right BoxHelp automatically adjust vertically to the size of Left BoxHelp in real time in this case? so that in height the right always measures the same as the left. This is the both boxhelps code https://paste.ofcode.org/rHEZVn9pNbh8KGBgFxnKjB

little oak
#

why does this happen?

swift crag
#

you asked for a child transform that didn't exist

#

look at line 48

little oak
#

wym doesnt exist

swift crag
#

an object has three children

#

i ask for the fourth child

#

the fourth child does not exist

little oak
#

but it does

#

its just in a prefab

#

the top one works

swift crag
#

well, yes, the if (chance == 1) block doesn't try to get any children

little oak
#

that block uses the parent instead of the children

#

but it works

swift crag
#

yes, I would expect the first block to work just fine

little oak
#

then how can i instantiate children of a gameobject seperately?

swift crag
#

I noticed that you're using transform.GetChild

#

not pipe.GetChild

little oak
#

oh

#

lol

swift crag
#

it also seems very weird to get child transforms of a prefab and instantiate those individually

little oak
#

im dumb

slender nymph
swift crag
#

especially since there is probably important logic on the root object of the prefab

little oak
#

i want the pipes to be touching

swift crag
little oak
swift crag
#

of course you can

#

why would you think you can't do that?

little oak
#

but theyre children

swift crag
#

but you've already demonstrated you know how to get the children of a transform

little oak
swift crag
#

just do that on the instance

swift crag
# little oak

your code completely loses the MiddleTrigger object

little oak
#

what even is transform lol

swift crag
#

that seems like a problem to me

little oak
#

it doesnt

#

theres a seperate script

#

in the prefab

swift crag
#

which you aren't instantiating...

little oak
#

its apart of pipe

#

OH

#

yes

#

youre rirhg

swift crag
#

every game object has a Transform component on it. the Transform tells you where an object is, how it's rotated, and what size it is

#

along with what objects are children of it and who its parent is

little oak
#

OHHHHHHHHH

#

so i can just change the transform.getchild

tacit birch
#

bump, still need help with this if anyone knows what's wrong T T
Been trying to find workarounds for the past few hours to no avail and it's burning me out now looool

swift crag
#

your Pipe Spawner component or whatever this is

swift crag
#

correct

little oak
#

mb

swift crag
#

it's your transform

little oak
#

so pipe.getchild

#

.transform?

swift crag
#

what is the type of pipe?

little oak
#

gameobject

#

its the parent

swift crag
#

okay, so you need to get its transform property

#

then ask for a child

little oak
#

alr ill be back

swift crag
#
GameObject instance = Instantiate(pipe);
instance.transform.GetChild(0)
#

e.g.

little oak
#

and thatd instantiate it?

#

ur getting it on that second line but ur not calling any functions

#
  Transform pipeTop = instance.transform.GetChild(0)
#

dont u need to do this

#

and then modify pipeTop

polar acorn
#

So that part is left up to you

little oak
#

this lol

#

works fine it seems

slender nymph
#

okay but again, why do you need to change the positions of the pipes individually? just change the position of the parent object

#

in fact you can just tell the parent object to spawn at a specific position

little oak
#

but i want them to be touching

#

the pipes

slender nymph
#

what do you mean you want them to be touching?

little oak
#

the pipes need to meet

#

instead of having a gap

slender nymph
#

and you can't do that in the prefab why?

little oak
#

i need them to sometimes touch and sometimes not

#

beautiful

timber tide
#

how do you get through that then

little oak
#

not sure how ill implement that yet

#

its supposed to blow a hole thru

#

i gotta figure out how to do it

#

trying to delete an instantiated object after a while using this but it doesnt work

#

i even tried destroy(instance)

swift crag
#

what does "doesn't work" mean?

little oak
#

the object isnt deleted

swift crag
#

no errors in your console?

little oak
#

nope

swift crag
#

what is that code destroying?

little oak
swift crag
#

no, it's destroying gameObject

little oak
swift crag
#

gameObject is whatever object your component is attached to

little oak
#

yes

#

thats why i tried instance first

swift crag
little oak
#

u mean script?

swift crag
#

no, what class is this screenshot a part of?

#

your script file declares a class

slender nymph
little oak
#

exactly thats why i throw it into the abyss

swift crag
#

it might be something like public class Foo : MonoBehaviour { ...

little oak
#

oh

swift crag
#

okay, you just destroyed the spawner's gameobject

#

the spawner is gone

little oak
#

i changed it to instance

#

gameobject like u said destroys the component connected

#

so it shouldnt work

swift crag
#

this will still only check if the instance is out of bounds once

#

the moment you fire the arrow

little oak
#

ohhh

swift crag
#

Perhaps the arrow should have a component on it that checks if it's out of bounds

little oak
#

OH

#

i have an idea

#

ok im dumb

little oak
#

thats probably what i shud have done

#

works, beautiful

#

i need to start using my brain

timber tide
#

this is where you learn to debug.log

#

when you have a long chain of dot operators going on, you want to check if each and everyone of them is null, ideally start with the last element

slender nymph
timber tide
#

actually you debug from the start because it'll still throw a exception with logging if the null is earlier

#

one or another lol

stuck palm
#

Im having an issue where it still executes the bottom code even if it touches the player, how can i fix this?

#

the first if statement should stop that

wintry quarry
#

Add debug.log

#

Print the object you're hitting

stuck palm
#

does an audiosource play its assigned clip when it starts up?

wintry quarry
#

If play on awake is enabled

stuck palm
#

thats probably it thne

sacred egret
slender nymph
#

you overwrite the velocity in Update

sacred egret
#

thx

queen adder
slender nymph
#

your raycast has nothing to do with opening doors. your keypad will open a door whenever E is pressed

#

if you remove that code from the keypad's update method and instead check for input when your raycast hits something in your PlayerInteract component it will do what you expect it to

queen adder
slender nymph
#

i just explained how

#

check for input in your PlayerInteract component. not in the Keypad component

slender nymph
#

you do know i have no idea what you've just tried because i cannot see your code in your code editor, right?

#

but you're probably calling Interact on your PlayerInteract object instead of on the Interactable component you get with that convenient GetComponent call you have (though that should probably be a TryGetComponent call since you null check it immediately anyway)

slender nymph
# queen adder

also if the error is not underlined in red in your !IDE then it needs to be configured πŸ‘‡

eternal falconBOT
stuck palm
#

if i do audiosource.play, then while its playing i change the clip and play the new clip does it stop the old clip

queen adder
slender nymph
#

why would you put it there

north kiln
#

Also, I don't see anything underlined in red, did you fix the error or is your IDE not configured?

queen adder
#

it doesnt underline anything in red ever ☠️

north kiln
queen adder
#

so i meant, i pasted it here:

#

and it returns with this after i paste it

slender nymph
#

configure your ide. it is a requirement to get help with your code here

queen adder
#

ok πŸ‘

#

sec

long tangle
#

how do i fix this

#

i cant open any of my projects

slender nymph
#

that wouldn't prevent a project from opening. it's just an editor issue

long tangle
#

nvm i fixed it

#

just the layout

slender nymph
#

yes, i already explained what you should be doing instead

north kiln
#

Look at your braces and indents, it's a mess

queen adder
slender nymph
# queen adder done,

also is that not you checking input in that last if statement to call the BaseInteract method?

#

or did you not write this code so have no idea what it actually is?

rich adder
queen adder
slender nymph
#

yes you already have that. that's what that last if statement is supposed to be doing

queen adder
#

i moved the getkeydown check to the Interactable.cs file, and when I did it removed the error, but just doesn't work

slender nymph
#

okay you clearly have no clue what your code is actually doing. i suggest you start by learning the basics instead of blindly copying random tutorials

queen adder
slender nymph
#

there are beginner c# courses pinned in this channel and the pathways on the unity !learn site are a good place to learn how to use the unity engine

eternal falconBOT
#

:teacher: Unity Learn β†—

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

queen adder
eternal falconBOT
#

:teacher: Unity Learn β†—

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

slender nymph
#

c# first imo, but it's up to you

meager sentinel
#

Idk in which channel to talk about this, but when i try to install VSC ide the unity asset do not appears, and it seems like there's no place where i can download it

slender nymph
#

!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

meager sentinel
slender nymph
#

what asset

meager sentinel
#

Visual studio editor in the package manager

slender nymph
#

well have you looked in the package manager to see if it is already installed? because unless you've uninstalled that manually then it should already be there

meager sentinel
#

Oh, am sorry. I din't check the unity registry

queen adder
timber tide
#

ya not getting far without knowing your c#

slender nymph
meager sentinel
#

I know this may be a very begginer question, but someone can pass me a tutorial in the DM about how to alternate a bool between different scripts? Basically i want to make that in the start you dont have a gun, but when i pick up the object i want to make the bool of the script that checks if the gun has been picked true

timber tide
#

Well, you need a way to get a reference to the gun, so youll need a method to pickup on your player. The item itself can have a collider such that you'll cast in the area when you call your pickup method.

meager sentinel
timber tide
#

Probably best to lookup a tutorial on youtube as you're dealing with quite a few concepts here.

meager sentinel
timber tide
#

Well, you need the reference to the item first which is the bulk of the code.

meager sentinel
#

welp i just found a 1 min tutorial that helped me, ty tho

amber spruce
#
GameObject smokespawnedin = Instantiate(SmokePrefab);
DontDestroyOnLoad(smokespawnedin);
Smoke = smokespawnedin.GetComponent<ParticleSystem>();

why doesnt this work it spawns in and is added to the dontdestroyonload but smoke doesnt get set to the particle system

wintry quarry
amber spruce
#

there is

wintry quarry
#

BTW why not just use ParticleSystem As the prefab reference type then you won't need GetComponent

amber spruce
#

didnt know you could do that

wintry quarry
wintry quarry
#
public ParticleSystem prefab;

void Spawn() {
  ParticleSystem instance= Instantiate(prefab);
}```
#

Exactly as you'd expect

polar acorn
#

Also a DDOL particle system is... Odd

amber spruce
#

but it works

#

hopefully

polar acorn
amber spruce
#

because basically the player and the ps need to be seperate but when the player moves through scenes it needs to follow

#

its a smoke screen ability the player has

frosty hound
#

Really, the player (and managers) should be in a root scene and all your other scenes are loaded aysnchronously.

#

That way you don't have to deal with DDOL's, since it's always the same object.

meager sentinel
#

This happens when i trigger an object that is supossed to dissapear when i pick it

#

But it only appears when the starting voice is sounding, otherwise it will not even trigger any of the debug logs

frosty hound
#

The object you're destroying has the camera on it? πŸ€·β€β™‚οΈ

north kiln
#

Seems self-evident that you are

frosty hound
#

Where's the camera in your first screenshot?

eternal needle
#

thats a cursed == true at the end of that statement

north kiln
#

why not actually print useful logs, with the object name and passing it to the context parameter

#

Also, your code seems very under-highlighted, which would indicate that your IDE may not be completely configured

meager sentinel
frosty hound
#

And also ... where is the camera in your first screenshot πŸ€”

meager sentinel
frosty hound
#

Where in your first screenshot is the "bean"?

meager sentinel
#

Oh

#

i just saw in scene

#

the player gets deleted

#

not the object

frosty hound
north kiln
eternal falconBOT
meager sentinel
#

am sorry, am stupid

meager sentinel
livid tundra
meager sentinel
livid tundra
livid tundra
#

Oh right

#

Mine works... πŸ€”

#

Did you restart your computer yet?

meager sentinel
livid tundra
#

If you only just got Unity and just started trying to code VSC with C#, you might just need to restart

meager sentinel
#

Well, am goin gto

livid tundra
#

Ok

meager sentinel
livid tundra
meager sentinel
meager sentinel
summer stump
# meager sentinel Oh i had to?

C# dev kit extension should install an sdk, and you either need to restart or manually add it to your computers PATH variables for it to work

near wadi
#

Edit: Fixed below
I am taking basic tutorials in c# for Unity. All iwant to do is add a vertical offset of 1 to the instantiated prefab.

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Instantiate(projectilePrefab, transform.position, projectilePrefab.transform.rotation);
        }

this is launched from the position of a Farmer character that moves left and right. if i do this:

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Instantiate(projectilePrefab, transform.position = transform.position + new Vector3(0,1,0), projectilePrefab.transform.rotation);
        }

it moves the Farmer up 1 every time i press space, too. the goal is to have the instantiated Carrot at a height of 1, always

#

Ok, i should not have added the second transform.position after the equals.
This seems to work

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Instantiate(projectilePrefab, transform.position + new Vector3(0,1,0), projectilePrefab.transform.rotation);
        }
verbal dome
near wadi
#

Thanks

verbal dome
#

You probably just want transform.position + new Vector3(0,1,0)

near wadi
#

Done, in the message above your response. πŸ™‚

verbal dome
#

Ah

chrome wasp
#

Okay so I have been trying to figure something out for over an hour

#

I am trying to make something like a computer, where when you hit a button a tab opens, and when you hit that again a tab closes

#

I have it so that it can detect when you hit the button, and even do so much as make it appear or dissapear when holding down on it

#

But I cannot for the life of me figure out how to make it toggle

#

`using UnityEngine;
using System.Collections;

public class Hide : MonoBehaviour
{
public GameObject Square;
public GameObject App;

void Update()
{

    if (Input.GetMouseButton(0))
    {
        Square.SetActive(false);
    }
    if (Input.GetMouseButtonUp(0))
    {
        Square.SetActive(true);
    }
}

}`

#

that is my code

#

I have another code for another thing

slender nymph
#

instead of using GetMouseButtonUp/Down keep a bool that determines what state it should be in, flip the bool each time the button is pressed (but not when released) and pass that bool to SetActive

chrome wasp
#

so like

#

bool variableName = true ?

slender nymph
#

i mean, that is how you declare a boolean variable, yes. i don't know what you are expecting that to demonstrate here though

chrome wasp
#

im not super familiar with bool

slender nymph
#

there are beginner c# courses pinned in this channel. you should start there

chrome wasp
#

Okay thank you!

chrome wasp
slender nymph
#

give it whatever state the tab should be in. true == on. false == off

chrome wasp
#

alright

ivory bobcat
chrome wasp
#

`using UnityEngine;
using System.Collections;

public class Hide : MonoBehaviour
{
public GameObject Square;
public GameObject App;
public bool onOrOff;

void Start()
{
onOrOff = false;
}
void Update()

{   
    if(Input.GetMouseButtonDown(0))
    {
        onOrOff = !onOrOff;
    }
    if(onOrOff == true)
    {
        Square.SetActive(true);
    }
    else
    {
        Square.SetActive(false);
    }

}
}`

#

okay so

#

I got it to work

#

thank god

slender nymph
#

please go learn the basics of c#

chrome wasp
#

but it happens when I click anywhere on the screen and I wanted it in just a square

#

okay

polar acorn
chrome wasp
#

which

slender nymph
#
if(onOrOff == true)
{
    Square.SetActive(true);
}
else
{
    Square.SetActive(false);
}

this is honestly painful to see. you know you don't have to check the current status of the bool, just pass it right into SetActive

polar acorn
#

Just toggle the object inside the input if statement

chrome wasp
#

ah

#

well i mean

#

it works

#

listen okay I know I don't really know how to program but I'm just trying to get through this part before I dedicate a ton of time into learning

#

I have no idea how to get this to only work when hitting a specific square though is my main issue

timber tide
#

You need some type of raycasting method

#

if you're going to use the mouse controls

chrome wasp
#

isnt raycasting a beam though?

#

If my object is a square then how does that work with raycasting

wintry quarry
#

So your code knows which square to toggle

#

BTW if you deactivate it, it won't be possible to Raycast it anymore

#

You should only disable the renderer or something

chrome wasp
#

how would I go about disabling the rendering?

#

Disabling the whole thing was all I could find on google

wintry quarry
#

As with most components you get a reference to it and do .enabled = false on it

#

Assuming they have 2d colliders

chrome wasp
#

thank you!!

sturdy wren
#

why can't i click my button?

slender nymph
ruby ember
#

i don't know if im in the correct channel

so i added a new FPS controller and im kinda having some issues with gravity i was trying to find tutorials but it dosen't work for me and i only added public float gravity

slender nymph
#

CharacterController does not apply gravity automatically unless you use SimpleMove. but if you use that you cannot jump

#

also !code

eternal falconBOT
ruby ember
#

i don't need jumping system

sturdy wren
slender nymph
#

well at the very least it is required to get input for the Button component and other UI stuff

ruby ember
slender nymph
#

it's how you share code correctly

ruby ember
#

how can i share it?

#

just copy and paste the code in here?

slender nymph
#

you read what the bot told you to do and share it that way

lunar tapir
#

Hi, I have a 2D game and I'm trying to rotate my player whenever it moves in a direction. I'm simply setting transform.up to the moveDir like this:

transform.up = normalizedMoveDir;

However I notice that when the move direction is directly downwards, it changes the X rotation of the player instead of the Z rotation. In every other case it changes the Z rotation correctly. But when I move directly downwards it changes the X rotation. Any idea why this is happening?

slender nymph
#

instead of assigning transform.up you could get the desired angle for the Z axis and just set the rotation using Quaterion.Euler instead. it's probably flipping around the X axis because it's the quickest way to get to the desired rotation or something equally as simple as that

lunar tapir
slender nymph
#

well you see what a possiblity of assigning it does. it's not that it isn't reliable, it's that it really only cares about pointing the Y axis in that direction. it doesn't care about the X or Z axis

lunar tapir
#

I see, got it, thanks!

tawdry mirage
#

how to use Invoke? Invoke(nameof(StopSelf), flightDuration); right? what difference between nameof(MethodName) and "MethodName"?

#

garbage?

slender nymph
#

if you were to change the name of the method without using the refactoring tools it would give a compile time error instead of a runtime error. it's just generally better to use nameof when you want to use the name of some method or variable instead of hardcoding the string

tawdry mirage
#

but it generates same amount of garbage?

slender nymph
#

pretty sure they are both interned at compile time so yeah, i guess you could say its the same amount of garbage

tawdry mirage
#

thanks! so, if i want to reduce garbage collector calls to minimum, i should go with tons of "if" in Update instead of Invoke?

slender nymph
#

i mean, it's not related to garbage collecting the strings. invoke uses reflection which is where its performance impact comes from

tawdry mirage
#

i hope i understand this)

vast haven
#

Hello! Does Unity support C++?

gaunt ice
#

you can write plugin in cpp

vast haven
#

Ah, so I can't write anything other than plugins via CPP.

slender nymph
#

correct. C++ is used for native plugins, and C# is used for regular scripting of your objects

vast haven
#

Ah.

#

Do you guys think it's worth it to learn C#?

#

Or should I just move to another engine that utilizes CPP like UE.

slender nymph
#

do you want to use unity?
if yes, then you'll want to learn c#
if no, then why are you here but also it depends on what you do want to use

vast haven
#

I simply want to create, indie games, Unity seems like the best option.

#

Are there any good C# Unity tuts?

#

I have a strong understanding of CPP, not sure if that changes anything. πŸ˜…

slender nymph
#

there are beginner c# courses pinned in this channel. and the pathways on the unity !learn site are a good place to start learning the engine

eternal falconBOT
#

:teacher: Unity Learn β†—

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

vast haven
#

Got you.

#

Thanks for all the help!

icy grotto
#

hi, just wondering why is it that both characterSkills and CharacterSkillsList have been cleared when I only called .Remove for characterSkills?
GetRandomSkills() was called 3x in a coroutine.

slender nymph
#

lists are reference types. that first line in the method makes them the same list

gaunt ice
#

they are the same thing

icy grotto
#

ohhhhhhh

#

that's a good learning for me.

slender nymph
#

you can copy a list by passing it into the List<T> constructor or calling ToList on it

icy grotto
#

would have been a disaster, glad i've asked here

vast haven
#

What's the big difference between C# and CPP? πŸ€”

icy grotto
gaunt ice
#

cpp class and struct are the same but not c#, completely different things

teal viper
arctic harbor
#

i was just thinking about this. if i make some variables on PlayerController, it makes sense to me to have them private and make getters and setters for them, but in this particular example, Rigidbody2D and Rigidbody2D.velocity are already accessible anywhere. i can still make a getter/setter for the velocity of the rigidbody attached to the player, but is that really the right approach?

charred spoke
#

Otherwise you need to get the rigidbody over and over again and chances are you are also getting the player controller as well

arctic harbor
#

or maybe done like a other.GetComponent<PlayerController>().SetVelocity(testVelocity); , and inside PlayerController, private Vector2 playerVelocity; and public SetVelocity(Vector2 velocity) { GetComponent<Rigidbody2D>().velocity = velocity;}

charred spoke
#

Well dont get the component in the Set method. Get it once in Start for example and cache it to a variable

arctic harbor
#

okay sure

#

but i mean like, should i have PlayerController itself have a private velocity variable

charred spoke
#

Not needed you can set it directly to its private rigidbody variable

arctic harbor
#

with getters and setters for that, and the setter operates on the velocity of the attached rigidbody2d component within PlayerController?

charred spoke
#

Unless you are doing internal velocity calculations

#

Like gravity friction etc

arctic harbor
#

so PlayerController has a private Rigidbody2D rb;, rb = GetComponent<Rigidbody2d>(); inside Start(), and then a public SetVelocity(Vector2 velocity) { rb.velocity = velocity; }

#

is that the general approach i should be taking

charred spoke
#

Again it depends this will set the velocity directly overwriting any AddForce that happened before it

arctic harbor
#

well yes, but just as an example

#

if i want an object on the scene to set the velocity of a player that touches it or smth

#

basically if i want a gameobject external to the player to modify the player's velocity, then PlayerController should have a private Rigidbody2D variable that is cached with GetComponent in Start(), with some public methods that other classes can use to modify the player's velocity?

charred spoke
arctic harbor
charred spoke
#

Well technically the player is always falling onto the jumppad and we wanted a trampoline effect so what the jump pad does is it takes the current player velocity inverts the y adds its force too it and set the new external velocity. The whole system is a bit more complicated than this but this is the main idea

arctic harbor
#

okay sounds good. i'll work on refactoring some of my stuff

#

on that note though, i get that adding velocity will preserve existing momentum and stuff, but how did you solve the problem of your player having a negative vertical initial velocity when they hit the jump pad?

#

ie they jump/fall onto it. if you're simply adding a velocity, then running into it will produce a different height than falling onto it

#

oh okay. doesn't seem applicable to my use case but that's pretty cool. gonna try playing with dot products of the player's velocity and the transform.up of the jump pad

#

thank you for your help

delicate portal
#

I implemented a pickup and a drop system for my FPS game, but if I drop a 'pistol' for example, it starts flying in the Y axis upwards. It has a rigidbody, and I'm just enabling gravity when dropping and adding some force relative to the player's forward vector. Why can it be? Also other objects dont do this, they work just fine.

#

The rigidbody's velocity's changing constantly

eternal needle
delicate portal
#

it was the animator's fault, I just disabled it when dropping

dim halo
#

how can I change the background color of the text button in the unity

gaunt ice
#

the background color is driven by the image iirc

rare crater
#

Can someone help, I don't know why my Roslyn is eating up so much memory? I've only begun my project a few days ago.

ivory bobcat
#

Maybe expand on the details

fringe plover
#

Why it doesnt detect pathfinding/NavMesh?

#

i have installed it

true yacht
fringe plover
#

πŸ’€

short hazel
#

English please

#

Do these errors only appear in VS, or also in the Unity console?

fringe plover
#

i mean in unity too

short hazel
#

Make sure the package is installed via the Package Manager

fringe plover
#

it is

short hazel
#

Unity says otherwise, it seems

fringe plover
fringe plover
short hazel
#

Are you sure it's not UnityEngine.Pathfinding instead of just Pathfinding by itself?

true yacht
# fringe plover

Em check using UnityEngine.AI or smth with UnityEngine namespace maybe? Cause all unity namespaces are in UnityEngine namespace usually

fringe plover
true yacht
true yacht
#

Okay

short hazel
#

Or you can check the docs, it will display which namespace the types are in.
Or you could make a variable of a type, and use the VS Quick Actions to complete the namespace for you

ivory bobcat
#

Type your wanted code and auto import

true yacht
ivory bobcat
fringe plover
true yacht
#

Unity.AI.Navigation

ivory bobcat
fringe plover
#

i commented

#

nothing changes

short hazel
#

Now use the quick actions to import the namespace

#

It's the light bulb icon that appears when you hover over an error with your mouse

true yacht
#

Looks similar to your problem

little copper
#

i have the same script on 2 object how can i make them work separately?

ivory bobcat
true yacht
fringe plover
#

idk what you mean

short hazel
#

The light bulb icon

fringe plover
#

oh i see

#

it says that i can add System.IO to using but when i do it i get more errors cuz its NavMesh path

short hazel
#

Yep so it's not detecting that the package is installed

#

Restart VS and try the same thing again

fringe plover
#

i did

#

Nothing changed

short hazel
#

Then close VS, go to Edit > Preferences > External Tools, and click the Regenerate Project Files button. Then open VS again

ivory bobcat
#

Wherever you got it from, make sure to copy all steps exactly as they've done.

fringe plover
#

Well, i got it from some guy, and this it not my game

opal cove
#

Hey, do any if you know a good tutorial to sart scripting and actually understand what you’re doing?

fringe plover
ivory bobcat
#

!learn

eternal falconBOT
#

:teacher: Unity Learn β†—

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

fringe plover
#

Yeah this one is good one too, but i did only 3 lessons end went to youtube

opal cove
opal cove
fringe plover
#

but i just continued learning and now i mostly code with no tutorials

opal cove
#

Like the only thing I coded mostly myself is a button to switch scenes

little copper
#

how do i remove a game object from an array

short hazel
charred spoke
#

Or set it to null

charred spoke
#

But that brings other problems

naive harness
#

So, I am setting my game state based on Axis input from idle to running, which works; however, if I immediately switch the cursor key from holding right to left, my character slides over the floor with its first frame rather than utilizing the running animation

#

is this some limbo state that I enter into that does not properly run animator?

verbal dome
naive harness
#

I suspect it has to do with this:

"If you’re using Input.GetAxis it will return 0 when both are pressed."

#

(reading something on Reddit)

#
            spriteRenderer.flipX = false;
            state = MovementState.running;
        }  else if (dirX < 0) {
            spriteRenderer.flipX = true;
            state = MovementState.running;
        }```
solid yew
#

Hey, this might be a stupid question. Which axes does Rigidbody.angularVelocity use?

#

Is it world or local axes

naive harness
#

Ahhh, interruption sources, interesting

rare crater
#

I have a scriptable object and I'm trying to pass a generic script into it but its not letting me add anything? Any ideas why?

wintry quarry
rare crater
#

Just a script that plays additional functions etc

wintry quarry
#

What precisely are you dragging

#

The script itself?

rare crater
wintry quarry
#

You drag GameObjects with that script attached to them OR if it's a ScriptableObject then an asset of that type

#

What exactly is SkillBase?

#

MonoBehaviour?
ScriptableObject?

rare crater
#

Skillbase is monobehaviour

wintry quarry
#

Assets cannot reference objects from scenes in the editor

rare crater
#

mmm okay, im not referencing anything in the scene anyway. But does that mean I have to basically create 3 objects for each skill?

#

Sounds cumbersome, I'm only doing this because I cannot access monobehaviour within a scriptable object. Is there another workaround?

wintry quarry
#

I don't really understand why SkillBase is a MonoBehaviour

rare crater
#

i figured cuz a scriptable object doesn't inherit monobehaviour so

#

I'd be locked out on creating certain functions

wintry quarry
#

So? But why does it need to be a MonoBehaviour in the first place

rare crater
#

umm i dont really have a concrete reason why, but isn't there some limitations because it doesn't inherit monobehaviour

#

like lets say instantiation, or whatnot. Anything that would be in a normal unity script

wintry quarry
#

It's a static method in UnityEngine.Object

#

You can call it from anywhere

rare crater
#

mmm okay

#

I guess i'm going about doing it the wrong way

hoary locust
#

Hello there! Does anyone know any resources to do something similar to this in unity? Where the game scales up or down dynamically depending on the window and not using a fixed resolution?

lament birch
wintry quarry
hoary locust
#

Not UI. The game itself.

wintry quarry
#

The game itself always scales according to screen resolution

#

You don't have to do anything special

hoary locust
hoary locust
wintry quarry
hoary locust
glad field
#
        if(victimPiece == "Knight" && attackerColor == thisColor){
            curCount++;
        }
    }```
#

Identifier expected

#

did i screw up with syntax or something else?

short hazel
#

Yes

#

You need to give types to the function parameters

glad field
#

what python does to a mf

#

thanks

queen adder
#

Hi guys. I know physics things should go into FixedUpdate but I'm not sure where just adding fixed velocity should go also in fixedupdate?

myRb.velocity = moveVector.normalized * moveSpeed;

wintry quarry
#

Yes, also in FixedUpdate technically but you can get away with that in Update

queen adder
wintry quarry
queen adder
#

setting a constant speed into x direction

wintry quarry
#

It doesn't do anything until the physics simulation runs

#

When the physics simulation runs it moves the object

#

FixedUpdate runs at the same cadence as the physics simulation

queen adder
#

ah okay that makes sense yeah, just setting it on its own does nothing

wintry quarry
#

So by setting it during FixedUpdate that's the appropriate time to make changes to it right before it gets used by the simulation

queen adder
#

hence why i can also put it in udpate but best practice would be to put it still in fixedupdate?

wintry quarry
#

Yes

queen adder
#

ok thank you very much πŸ™‚

upbeat stirrup
#

Would it be more efficent to instantiate prefabs with a Vector3 offset or a "Spawn Point" gameobject? Or does it not matter?

wintry quarry
upbeat stirrup
#

Ok, thanks

waxen oracle
#

Is it possible to have an image/object show up a fixed position on the screen

#

such as a health bar ect, im confused about how to achieve this

timber tide
#

easier to do with UI

waxen oracle
#

wdym Ui

timber tide
#

unity UI canvas component

#

which you can specifically use screen coordinates

waxen oracle
#

thats probably what im looking for

#

thanks

cosmic quail
# wintry quarry you're definitely prematurely optimizing

@upbeat stirrup actually i dont think thats premature. a spawn point gameobject would require you to have an extra gameobject in your scene, depending on how many you have it may start affecting performance since gameobjects have a performance overhead. and if it becomes a problem later then fixing this would waste a lot of time (manually going through every single one of these prefabs, removing the spawn point gameobject and assigning a offset instead)

upbeat stirrup
#

Alr, thanks alot!

queen adder
#

quick question

#

i am trying to have it so that if you are holding left shift and press a move it does the reverse

#
 if (Input.GetKeyDown(KeyCode.U) && !isRotating) MakeMove("U");
        if (Input.GetKeyDown(KeyCode.U) && Input.GetKeyDown(KeyCode.LeftShift) && !isRotating) MakeMove("rU");

#

it doesnt appear to be working

languid spire
#

what? why the ;

#

and the repeating conditions

short hazel
#

It's pretty unlikely you'll be hitting both U and Shift down in the very same time frame (of 16 milliseconds at 60 FPS)

queen adder
#

yeah i thgoutht that

#

thought

short hazel
#

You should use GetKey for the Shift key

queen adder
#

does that mean if im holding it down

short hazel
#

Yes

queen adder
#

cool let me try it

short hazel
#

Wtf images don't seem to load on my side, anyone else?

queen adder
#

images wont send for me

short hazel
#

Yeah I've seen the Discord Status page, they're aware of it

swift sedge
#

since when is discord down like that?

willow scroll
compact saddle
#

think its back

waxen oracle
#

For some reason, i cant move a text mesh pro which is the child of an image, into the text mesh pro public field of a script attached to the image, why is this?

fringe kindle
#

Is there a way to destroy an item's parent?

willow scroll
#
Destroy(transform.parent.gameObject);
fringe kindle
#

As in when you latch on to the bottom part of the vine (where the collider is), and after a few seconds, the whole vine itself disappears

languid spire
#

Destroy(transform.parent) or Destroy(transform.root) if there multiple levels in the heirarchy

rich adder
#

prob the former

waxen oracle
#

it should def match

rich adder
#

prove it

waxen oracle
#

and theres no prefab

#

public TextMeshPro textcomp;

#

thats the line i have exactly

rich adder
#

ok show what ur dragging into it

#

screenshot it

meager sentinel
#

Guys, i have a cube that is supposed to represent a coin (with a trigger), the thing is. When you start the game a audio sounds, but when you touch the block after the audio sounds nothing happens, i even have a debug log and the log dont even works, the trigger only works when the voice is sounding, anyone could help?

rich adder
#

unless you specified so somehow..

#

check console for errors

meager sentinel
meager sentinel
#

it looks like this

#

when the audio is over

rich adder
#

cant tell whats happening

meager sentinel
#

the code makes it to destroy when u enter on trigger

meager sentinel
#

Am placing it via unity since it takes a year to load VSC

rich adder
waxen oracle
#

trying to drag the selected text into image

#

is that not text mesh pro

polar acorn
# meager sentinel

So whenever this object collides with anything you destroy whatever object thing is

rich adder
#

change type to TMP_Text

waxen oracle
#

alright

#

thanks

meager sentinel
polar acorn
eternal falconBOT
meager sentinel
polar acorn
fringe kindle
#

Instead of deleting the vine, this comes up after 1 second

#

This is the code I got

rich adder
meager sentinel
polar acorn
fringe kindle
meager sentinel
polar acorn
languid spire
#

then transform does not have a parent

polar acorn
# meager sentinel

Okay, so whenever this object collides with anythinf, delete the cube you've dragged in. Do you ever get your debug log

fringe kindle
#

I thought it does

I'm trying to destroy the entire 'quickvine parent'. Section 6 is where my character swings from, and has the collider

meager sentinel
fringe kindle
polar acorn
rich adder
fringe kindle
#

The collider is attached to the Section 6

polar acorn
fringe kindle
#

No

meager sentinel
polar acorn
meager sentinel
#

log dont even appears

polar acorn
rich adder
meager sentinel
fringe kindle
polar acorn
meager sentinel
rich adder
polar acorn
fringe kindle
#

I'm trying to destroy the parent to the section I'm holding on to, i.e. the vine itself

polar acorn
languid spire
#

he just copy/pasted the code I gave him without thinking about it

meager sentinel
rich adder
#

on swing

polar acorn
fringe kindle
#

I tried doing it with 'other.', which has the tag I applied to the vine section, but it didn't work earlier

polar acorn
languid spire
meager sentinel
wintry quarry
#

It would not take a long time to fix later either

#

But it's so exceedingly unlikely to be a performance problem unless there's thousands of these things in the scene

rich adder
boreal tangle
#

does someone know how I change the width of a orthographic camera. I can change the size but I need the camera to be long and changing the size only leads to a bigger cube.

rich adder
#

also not code question

boreal tangle
#

oh sorry

vast vessel
#

Hey guys, i want to implement this function for humanoid characters, that when called will disable the animator, and then it will enable the rigidbodies on every limb that has one. I have that part done but its the next part that i dont know how to do.
I want to add a force to each limb, so that they would continue moving in whichever direction with the same speed they were already moving in, when the animator was active.
How do i achieve this?

rich adder
#

so a ragdoll

vast vessel
#

Yes, i want to have death animations that will turn my rig into a ragdoll at some point

#

I will call the function uaing animation events in the death animation

rich adder
#

yeah so whats the problem rn?

vast vessel
#

If i only used a death animation the character wouldn't interact with the world, and if i only use ragdolls the rig will just drop to the floor. I want to have a death animation, that mid way through the animation turns the character into a ragdoll, and have evrey limb thrown in the same direction they were moving in before the character turned into a ragdoll

#

Read the original message in its entirety please

rich adder
#

eh..I know what you're trying to do

#

Im asking which part you cannot figure out since you seem to have the process already in mind

vast vessel
#

How do i know how fast a evrey limb was moving so i can calculate the force required for each limb when the ragdolling function is called

rich adder
#

normally animator already moves the limbs so it can just continue from there, you can also keep track the velocity

#

another way to track is checking where the limb was last frame compared to current frame and that gives you move direction

vast vessel
rich adder
#

something like that

#

you want (currentPos - lastPos).normalized or something

vast vessel
#

I dont think i would want normalized since i need the limbs to move at the same speed as when the animator was active

vast vessel
rich adder
sleek notch
#

How to fix this acceleration of vehicle?

vast vessel
# rich adder why would it be problem

Maybe you get a random lag spike causing incosistant frame rate, making it so the prevpos-newpos is higher then it should be.
Some calcultions with time.deltatime should be able to fix it ig

wooden leaf
#

Hello everyone. I'm just digging into Unity and coding and I've gotten stuck. I'm following a tutorial, copying the code written, yet I'm getting the error "The associated script can not be loaded. Please fix any compile errors." The only thing I see different is that my script is colored differently, I thought maybe there was a simple fix somewhere. Any help is appreciated.

rich adder
vast vessel
sleek notch
#

You must have anywhere red underline

gaunt ice
#

!ide

eternal falconBOT
vast vessel
#

Mouse input is already a delta why do tutorial youtubers do this anyways lol

eternal needle
rich adder
swift crag
#

it's also a natural mistake if you don't understand why you use deltaTime

#

if your understanding is "I use deltaTime so that things are framerate-independent", then of course you're going to use it there

wooden leaf
swift crag
#

that is not the compile error

#

there will be at least one other error in your console

gaunt ice
#

please configure your vscode first then it will underline the lines with errors

wooden leaf
#

I thought I did that, but things kinda got messy

vast vessel
#

Any way to sample a frame of an animation in code? Like for getting the position of a transform, on a specific animation, on a specific feame?

wooden leaf
#

Oh shoot! things are happening, the unity extension wasn't fully installed yet

gusty sorrel
#

why does addforce induce a bit of rotation even if applied perfecly through the center of mass, while addforceatposition keeps my rocket flying straight?

swift crag
#

It shouldn't. Can you show the code you're using?

#

(both versions)

timber tide
#

one or another

gusty sorrel
#

i changed a different unrelated part of the code and somehow it got fixed??

mellow elbow
#

is there any good way to learn raycasts?

#

This is mind melting

rich adder
mellow elbow
#

I have a tiny brain

rich adder
#

you make a Ray and get some data from it

mellow elbow
#

It's easy to understand but hard to grasp fully

timber tide
#

pick point, give direction and distance

rich adder
timber tide
#

the harder concept is the bitwise layer mask

mellow elbow
#

Docs are not making it clear for me

rich adder
#

yes their example is stupid

#

"Optionally provide layermask"
why not just show the layermask type instead of bitshifting

#

also TransformDirection method randomly put in there lol savage

shrewd swift
#

in edit mode, can I apply the same effects that this eye icon from code ?

#

i suppose this get the GO and all childs, and disable the renderer ?

rich adder
mellow elbow
#

I will understand in time

rich adder
shrewd swift
rich adder
mellow elbow
rich adder
cosmic quail
#

just watch tutorials and youll get it eventually

rich adder
#

**keep doing it

#

watching will not engrain knowledge, repetition does

#

I used to keep the whole raycast line inside a copy & paste clipboard because i never knew how to make one. the more I used it, the more it made sense and became muscle memory

timber tide
#
public static bool Raycast(Vector3 origin, Vector3 direction, out RaycastHit hitInfo, float maxDistance, int layerMask)

Vector3 origin : starting point in space represented by a Vector3
Vector3 direction : direction vector from the starting point represented by a Vector3
out RaycastHit hitInfo : struct of information from which object that was hit by the raycast (you declare the variable inline using the out ketword)
float maxDistance : distance value represented by a float
int layerMask : bitwise component to filter out layers which you want to ignore or hit

https://docs.unity3d.com/ScriptReference/Physics.Raycast.html
https://docs.unity3d.com/ScriptReference/RaycastHit.html
https://docs.unity3d.com/ScriptReference/LayerMask.html

mellow elbow
spring skiff
#

What I am searching for, if I want to collect items by pointing the middle of my screen to an objects while pressing [E] to collect the item?

I jsut find some cheap guides that only use colliders where it doesent matter in what direction the player is looking but This is not enough!

The player needs to look at the items + beaing inside of a collider, to make sure the player is in range to collect it and to make sure the playing is pointing with the middle of his screen to this item.

cosmic quail
gusty sorrel
#
if (Input.GetKey(KeyCode.LeftShift))
    throttle += Time.fixedDeltaTime;
if (Input.GetKey(KeyCode.LeftControl))
    throttle -= Time.fixedDeltaTime;
if (Input.GetKey("z"))
    throttle = 1f;
if (Input.GetKey("x"))
    throttle = 0f;
Mathf.Clamp(throttle, 0f, 1f);

why does throttle go outside the limit? i can just keep holding shift and it goes beyond 1

cosmic quail
#

a raycast should be enough, cause you can give it a range. no need for a trigger

#

and u wanna have an interface on your collectible items

rich adder
#

thats not how Clamp works..

gusty sorrel
#

wdym

rich adder
#

you never assign the clamp

gusty sorrel
#

oh

#

im stupid

#

thanks

spring skiff
queen adder
#

can anyone help how do i fix this idk what it is?

rich adder
queen adder
rich adder
#

Seems like an Editor error

queen adder
#

so hiw do i fix it?

#

how;

rich adder
#

try restart unity maybe ?

#

what did you try doing prior to error ?

queen adder
#

just make a map idrek tbh

rich adder
#

could be Probuilder bug

mellow elbow
#

Did you delete the map

queen adder
#

no

cosmic quail
mellow elbow
rich adder
#

do note , the receiving objects do need colliders for raycasts to work

mental chasm
#

Hello I'm new to Unity and coding and starting my first project, I have a ball im controlling and trying to increase the movement speed when holding down shift, but I don't know how to write the code for that. This is what I thought it would be but clearly it's wrong lol

rich adder
mellow elbow
#

Show the errors I wanna see

rich adder
#

more likely you're trying to pass ShiftKey as a keycode in a button(string) function

#

addorce Im gonna guess youre multiplying two vector3s

mental chasm
rich adder
#

AddForce wants a vector3 not a float

mental chasm
#

should I change addForce?

rich adder
#

wwhat?

rich adder
mental chasm
#

oh

rich adder
#

Vector3 would be that, find out which direction you want

mental chasm
#

Ohhh ok I changed m_MovePower to moveDirection

chrome wasp
#

I was wondering if I could get help with an error but I dont want there to be two converations at once should I make a thread?

rich adder
#

or yeah make thread

#

dont listen to me I just didnt have my coffee today

mental chasm
#

but my ShiftKey is unrecognizable, whats the Shift key name in Unity or do I need to add it somewhow?

mental chasm
#

YES

#

thank you!

rich adder
chrome wasp
#

Unexpected preprocessor directive

rich adder
#

change it to GetKey instead of GetButton

mental chasm
#

ahh okay thank you

rich adder
#

GetKey is held and GetKeyDown is pressed once

odd marsh
#

so im trying to mod a game and need to make an inputfield but its not working, do yall know how to fix this

mental chasm
rich adder
odd marsh
#

ah

#

alr

rich adder
#

more likely you're missing namespace though

wintry quarry
mental chasm
#

the code works thank you guys so much for the help!

rich adder
mellow elbow
#

I want my raycast to activate a button if it hits it, how should I go about doing this

dry tendon
#

I have one little question related to boxhelps... and if someone could help me i'll really appreciate it: How do I make Right BoxHelp automatically adjust vertically to the size of Left BoxHelp in real time in this case? so that in height the right always measures the same as the left. This is the both boxhelps code https://paste.ofcode.org/rHEZVn9pNbh8KGBgFxnKjB

rich adder
#

a physical object in the world space ?

mellow elbow
#

A cube

rich adder
#

make script that does what you want when hit, make the method public

mellow elbow
#

How do I reference the method

#

im stuck on that

rich adder
sleek notch
#

rb.AddForce(transform.forward * reverse * Input.GetAxis("Vertical")); how to do it reverse?

wintry quarry
sleek notch
#

transform.back doesn't work

wintry quarry
#

-transform.forward

mellow elbow
sleek notch
#

I did it but still same

wintry quarry
#

it will be opposite

cosmic quail
rich adder
wintry quarry
#

Shouldn't that be -1 if you want to reverse it?

rich adder
#

its good practice to use Interfaces absolutely

sleek notch
#

same as speed

sleek notch
#

Just it have to be different number

wintry quarry
rich adder
wintry quarry
#

under what circumstances do you want to reverse

cosmic quail
# mellow elbow What is an interface

if you want the best option use an interface, if its just some beginner project where u dont really care about the best option just do something like hit.gameObject.GetComponent<Button>().PressButton();

mellow elbow
#

ah

rich adder
#

always use TryGetComponent imo

sleek notch
#

It works but not. It goes reverse about 0.05 and forward goes nice

mellow elbow
rich adder
#

in case Button isnt found you don't null ref (trying to run a method on something that wasn't found potentially)

cosmic quail
#

yea cuz what if you interact with something that doesnt have a Button component

sleek notch
#

Anyway thanks it work

rich adder
#

just dont name your component Button lol

#

cause there already is a class like that UnityEngine.UI.Button

cosmic quail
mellow elbow
cosmic quail
rich adder
#

its just an example of a class you can make

mellow elbow
#

The component is the name of my script right?

rich adder
#

xD

mellow elbow
rich adder
cosmic quail
mellow elbow
#

I see

rich adder
#

btw gameObject is redudant

if(hit.collider.TryGetComponent(out ButtonScript btn))
btn.Press() //some public method on the button```
odd marsh
mellow elbow
#

Like this?? cause it says it doesnt exist in the current context

rich adder
#

not at all

#

you need a reference to ButtonScript

#

stored in a var

mellow elbow
#

OK so I store it first

rich adder
#

yes

mellow elbow
rich adder
#

but yes what I wrote is a shortcut

mellow elbow
#

ah

rich adder
#

its the same as this

ButtonScript button = hit.collider.GetComponent<ButtonScript>();

        if(button != null)
        {
            button.Pressed();
        }```
chrome wasp
#

with the box

#

that the code is inside of

mellow elbow
#

Three `

rich adder
mellow elbow
#

then end it with three `

#
damage```
chrome wasp
#

test

#

thanks!!

mellow elbow
#

you can also just see by copying the text

#

Thanks navarone

rich adder
mellow elbow
#

Yes :)

#

It returns on the logs that I hit it

rich adder
#

nice!

fringe kindle
wintry quarry
fringe kindle
#

That didn’t really do much

rich adder
fringe kindle
#

I’m using the Third Person Controller

#

With some extra bits of code added in where the character is β€˜grounded’ when on the bottom of the vine, so it can jump off

rich adder
#

are you talking about the CharacterController one?

fringe kindle
#

This one

#

It's the one I got off the asset store

rich adder
#

something you did to controller though is making that weird glitch, you have to show hat you did

#

the TPC controller script alone doesn't do that afaik

fringe kindle
#

I think it's coming from me disabling and re-enabling the TPC whenever I was in the vine's hitbox

rich adder
#

how are you moving it on the vine box then ?

#

also CC prefers to be moved on the Physics update with Move

fringe kindle
#

It's attached to the collider's position as it swings

#

Before you ask, I followed a video tutorial on getting swinging to work

#

It demonstrated the code working with a cube and I was trying to replicate the effect with a proper character controller

rich adder
#

was the cube just a rigidbody or what

fringe kindle
#

It was a rigidbody, yes

#

With a constant force to give it movement

rich adder
#

CC is just tricky to sync with rigidbodies properly

#

maybe convert to a rigidbody only whilst swinging

frosty hound
#

This conversation already happened yesterday πŸ€”

fringe kindle
#

I have it so that the rigidbody is kinematic whenever I'm not on the vines

#

Completely disabling it outside the vines makes my character plummet to the ground

rocky canyon
#

anyone know any resources or some tips that might help me make a click -> move top down style selection system.. does the clicker mechanic need its own state machine? you reckno?

desert elm
#

is there a way to combine multiple gameobjects into one?

wintry quarry
#

what are you trying to accomplish?

desert elm
# wintry quarry In what sense?

In the scene window. I just spammed a gameobject with a sprite render to create a placeholder level layout, but I want to turn all of these gameobjects into one- is that possible?

wintry quarry
#

What are you hoping to accomplish ultimately

desert elm
wintry quarry
desert elm
#

oh that works thanks

swift crag
#

You can select a bunch of objects, then right-click and click "Create Empty Parent", btw

honest haven
idle elk
#

Hi Can i ask a few question

#

I dont whats the problem .. im using player prefs to save the data .. and debug say its display but in my screen the stone dont appear

swift crag
#

you'll have to show us the code you're using

idle elk
#

Sure

rocky canyon
#

!code use a paste-bin website.. the compression on thats awful.. i can barely read it on a PC, mobile has no chance

eternal falconBOT
rocky canyon
#

tell me what this says πŸ‘€ lol

idle elk
#

using UnityEngine;using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class PyramidStoneSceneController : MonoBehaviour{
public Image stoneImage; // Reference to the Image component in the UI public Sprite spriteForOneStone;
// Set these values according to your desired position
public float newX = 0f; public float newY = 0f;
public float newZ = 0f;
void Start() {
// Log the initial local position Debug.Log("Initial RectTransform position: " + stoneImage.rectTransform.localPosition);
// Retrieve the collected stones for the previous level
int collectedStones = PlayerPrefs.GetInt("StonesCollected_Level" + (SceneManager.GetActiveScene().buildIndex - 1), 0);
// Debug log to show the retrieved stone count Debug.Log("Stones retrieved: " + collectedStones);
// Display the image based on the number of stones collected
DisplayStoneImage(collectedStones);
// Set the local position of stoneImage stoneImage.rectTransform.localPosition = new Vector3(newX, newY, newZ);
// Log the final local position
Debug.Log("Final RectTransform position: " + stoneImage.rectTransform.localPosition); }

#

void DisplayStoneImage(int stoneCount)
{ // Debug log to show the stone count
Debug.Log("Stone count: " + stoneCount);
// Display the image only if there is one stone if (stoneCount == 1)
{ // Set the sprite for the Image component
stoneImage.sprite = spriteForOneStone;
// Debug log to show when the stone is being displayed Debug.Log("Stone displayed!");
} else
{ // Set the sprite to null or an empty sprite if you don't want to display anything for other cases
stoneImage.sprite = null;
// Debug log to show when no stone is displayed Debug.Log("No stone to display!");
Debug.Log("Assigning sprite: " + spriteForOneStone);
stoneImage.sprite = spriteForOneStone;
Debug.Log("RectTransform position: " + stoneImage.rectTransform.position); }
}}

#

Sorry for that

rocky canyon
#

use a paste bin website..

rare basin
rocky canyon
#

click one of those links in the embed i sent.. and copy and paste it.. it'll give u a link

idle elk
#

Orite sure