#💻┃code-beginner

1 messages · Page 324 of 1

rocky canyon
#

ya, then it probably just going to take some tinkering w/ the function some bit of modifications to the results, etc to get ur working

stuck palm
#

i'll have to give it a try then, cant hurt, problem is baseballs are meant to bounce of players that only have trigger collisions

rocky canyon
#

u can achieve that with some layers.. (collision matrix)

#

and some physics materials.. (material for the ground/diff for the player)

#
  • custom stuff applied to that to get it to feel right
stuck palm
#

so i'll have to rewrite that too

#

thank goodness i only have to change 2 scripts

#

praise the lord for inheritance

#

if players bounce off the floor they use the same system 😭

#

i guess i could make it so rigidbody is enabled and disabled when the player is stunned or something

#

how can i make gravity stronger?

#

the weight appears to be a lot lighter after i changed it to rigidbody movement

lost anvil
#

ive got a problem in this script where the WaitAtPt() IEnumerator is being called when he comes from another state into Patrol - ive tried resetting the path and stuff but i dont know why its being called

https://gdl.space/camivokina.cs

swift crag
#

isPatrolling gets set to true if canPatrol is true

#

Perhaps the path isn't ready yet

#

SetDestination can return before it actually figures out a path.

charred spoke
swift crag
#

but acceleration due to gravity is constant :p

stuck palm
swift crag
#

that'll just make everything else weaker

stuck palm
#

i was gonna say

stuck palm
#

in the project settings

#

works like a charm

swift crag
#

if gravity feels too weak, your objects might be too large

slender nymph
stuck palm
#

things arent that big in my game

slender nymph
#

then show your code because it may be messing with how gravity is affecting that object

stuck palm
lost anvil
swift crag
#

I know that it can take longer for a very distant destination

#

especially if it can only get close to the destination

dusk cedar
#

so im tryna find the distance between a gameobject and an array of different gameobjects then store it in an array. is there a way to not go through and put a separate line for each value that needs to be stored?

ivory bobcat
#

Maybe describe what you're attempting to do better.

dusk cedar
#

yeah im not really sure

ivory bobcat
#

Why do you need to acquire/store this list of distances? For what purpose?

tawny bolt
#

https://gdl.space/qenaguqiso.cpp
hello i really dont understand the problem with my code basicly if i touch a trigger i should start a timer and the text get enabled for a few sec and then just go to setactiv(false) what can be the problem ?

dusk cedar
#

"PlayerDistanceFromTrees[1] = Vector3.Distance (player.transform.position, trees[1].transform.position);" works but i wanna do it for all of them not just 1

#

alright thanks

#

ima go study for a bit and then come back to it

#

will probably make it clearer

ivory bobcat
#

Just iterate the collection and keep a reference of the closest object.

timber tide
stuck palm
#

how can i disable a rigidbody?

#

i know i cant directly disable one

#

but how can i effectively disable a rigidbody influence?

slender nymph
#

either remove the rb component or make it kinematic

ivory bobcat
#

Set it to kinematic and possibly disable to collider

stuck palm
#

why does it feel like the character is getting dragged around? i made rigidbody kinematic and stuff

#

and i disabled the collider so it shouldnt be dragging along the floor or something

#

as u can see when rigidbody is removed it goes back to normal

#

after some testing, it appears to be because i enabled interpolation

spiral narwhal
#

Co-variant array conversion from Galaxy[] to IGalaxy[] can cause run-time exception on write operation
Why is this warning shown?

            Galaxy[] array = // ...
            _gameMap = new(array); // constructor takes IGalaxy[]
tawny bolt
deft grail
tawny bolt
#

so how to make 0

deft grail
#

you can check <= 0 for a quick solution

#

which would be less than or equal to 0

tawny bolt
#

ok will try that

#

fixed it thanks

timber tide
spiral narwhal
#

Hm I understand

lost anvil
#

nevermind it doesnt 💯

dusk minnow
#

I Instantiated a ui Panel and i want to Destory it at some point, but when i do that it tells me cant destroy so no data gets Lost

rocky gale
deft grail
#

probably the prefab?

dusk minnow
#

Destroy(instancePanel.gameObject);
instancePanel = null;

    instancePanel = Instantiate(PanelPrefab, panelInstantiatePosition.position, Quaternion.identity, panelHeader);
deft grail
dusk minnow
#

A empty Transform at the beginning

#

And PanelPrefab ist a transform

deft grail
dusk minnow
deft grail
dusk minnow
#

wait

deft grail
dusk minnow
#

nothing

#

its empty

#

its supposed to hold the prefab so i can destroy from both functions LoadNamePanel and LoadWord...

deft grail
dusk minnow
#

line 54, buttom one

dusk minnow
polar acorn
dusk minnow
#

instancePanel = instantiate

polar acorn
#

What does it start as

dusk minnow
#

as null so first it destroys null meaning it works

#

second try the error fires

polar acorn
#

If it starts as null then you'd be getting a NullReferenceException, not a message about destroying an asset

dusk minnow
#

well iam not

polar acorn
#

Put this log as the first line of LoadNamePanel:

Debug.Log($"LoadNamePanel instancePanel is {instancePanel}",instancePanel);

And then show what it logs before the error occurs

dusk minnow
#

tomorrow, imma sleepnow

rocky gale
north kiln
#

(and to avoid running that excess logic)

rocky gale
scarlet skiff
#

cant u name the return types? so i dont have to variable.item1

north kiln
#

name it in the actual method declaration

#

(GameObject player, PlayerMovement ...)

scarlet skiff
#

ok thanks

velvet marsh
#

anyone know how to add footstep sound fx to any game easily im very new to unity so I have no idea

cosmic dagger
velvet marsh
cosmic dagger
#

huh? i didn't say anything about multiplayer . . .

velvet marsh
deft grail
cosmic dagger
#

play around with the timing because it depends on the player speed and how fast or slow the footsteps are . . .

waxen adder
#

Are dictionaries like hash maps?

cosmic dagger
#

yeah . . .

waxen adder
#

gotcha, ty

dire tartan
#

im having issues with gameobject.find i have a player prefab which is instantiated and a roundsystemmanager object with script which is also instantiated in the scene i am attempting to get some values from the script but the gameobject.find is returning null?

summer stump
cosmic dagger
ruby ember
#

does anyone know how to make unlockable thing using timers record

for example: it has question mark and you need to survive 20 minutes to get the thing

you survived 20 minutes and you get the thing

https://hastebin.com/share/vizewijavu.csharp (best time script)

https://hastebin.com/share/upileyinub.csharp (Timer Unlockable script)

the third image is an example of how it needs to be when you survived 20 minutes

deft grail
ruby ember
deft grail
#

but you can figure that out im sure

ruby ember
regal bear
#

Hello, so im a beginner, first follow a youtube tutorial, did some animations, but i have a weird error. i have 100% the same code, but unity gives me this warning, and my animations not work. I already read posts about it, some ppl say its a bug, but closing Animator, and reopen Unity and rebuild not fixed my problem. So whats wrong?

shy ruin
#

Make sure the name of the parameter is correct.

#

It says the problem in the error

regal bear
deft grail
shy ruin
#

not in the script probably

regal bear
shy ruin
#

Yeah, make sure the animator window has the correct name.

regal bear
#

wym?

deft grail
#

the code says upper case p

regal bear
#

yea, cuz i already tried with lowercase uppercase, let me fix it, but still same error

deft grail
#

show the name of the paramater in your animator

regal bear
deft grail
regal bear
#

I have a player with the script, then i have a children for the player graphics, with the animator. My whole script is this:

using UnityEngine;
using UnityEngine.AI;

public class CharacterAnimator : MonoBehaviour
{

    const float locomotionAnimationSmoothTime = .1f;

    NavMeshAgent agent;
    Animator animator;


    // Start is called before the first frame update
    void Start()
    {
        agent = GetComponent<NavMeshAgent>();
        animator = GetComponentInChildren<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        float speedPercent = agent.velocity.magnitude / agent.speed;
        animator.SetFloat("speedPercent", speedPercent, locomotionAnimationSmoothTime, Time.deltaTime);
    }
}
deft grail
regal bear
#

Maybe a possible fix deep in the video comments: Just a note for people who run into this problem. Do NOT create the PlayerAnimator script in the script folder. Make sure it is made inside of the Assets project hub. Other wise it'll throw an error that the parameter SpeedPercent does not exist.

teal viper
teal viper
#

Aah, didn't notice it in the screenshot somehow

regal bear
teal viper
regal bear
#

btw i misread the comment, i should move the script, not the animator, but tried still same error.
@teal viper no whitespace, tried ctrl+a but only the text in here

rocky gale
teal viper
regal bear
#

Okay guys, as im said i am a beginner, dont be mad at me haha, this float wasnt a float, it was a layer, i didnt switched to the parameters tab.

ruby ember
regal bear
#

Ty for your help, your tips will be good in the future for debugging haha

deft grail
#

whats the BestTime.bestTimeMinutes part for?

#

what are you trying to do

ruby ember
deft grail
ruby ember
deft grail
#

oh variable doesnt exist

#

probably

ruby ember
deft grail
#

whats the error

ruby ember
#

what

deft grail
ruby ember
deft grail
ruby ember
deft grail
#

that doesnt help me at all, screenshot the unity console where it shows what the error is

ruby ember
deft grail
# ruby ember

alright, so bestTimeMinutes is made as a local variable in some method which means it doesnt exist outside of where you made it

rocky gale
#

https://hastebin.com/share/odufabuvol.csharp why when the first animation plays after the loop it is delayed and sometimes goes to idle'

deft grail
ruby ember
deft grail
deft grail
deft grail
#

of how local and not local variables work

ruby ember
#

uh okay i guess

rich adder
deft grail
#

wdym what? he means what he said

ruby ember
#

i know some codes but i never tried coding with timer systems

rich adder
#

"some codes" isn't the basics

cosmic dagger
#

what you mean by, "what?" they stated a clear sentence . . .

rich adder
#

i mean just accessing another variable in a class or differences between local and member variables, etc.

deft grail
#

your struggling with a float

cosmic dagger
#

it's hard to help or go further because you lack the basic knowledge of C#. you can't understand the help or information they're trying to convey . . .

summer stump
ruby ember
#

are yall trying to fight with me or what?

deft grail
#

i told you waht to do and you are doing the complete opposite

#

its not possible to help

ruby ember
#

i just asked anyone of you to know of how to make a gameobject enable using timer record

deft grail
#

you have the code written

#

the problem is not in this script

#

its in another script

ruby ember
#

this is menu record

#

so idk if this is the problem or not

deft grail
#

is the problem

deft grail
#

your bestTimeMinutes is local to Start

ruby ember
rich adder
ruby ember
#

he did this

deft grail
#

im telling you what to change

#

you dont want to do it

#

for some reason

ruby ember
deft grail
#

but your actions say that

summer stump
ruby ember
deft grail
#

the problem is still the same

ruby ember
summer stump
ruby ember
#

so i need to change it to private or something

deft grail
#

so it would need to be public

ruby ember
#

oh my god this is getting confusing

even it would be easier if sending the script or i don't know

summer stump
ruby ember
#

im not going in there that's a waste of time

deft grail
summer stump
#

It is a few words and example code

rich adder
#

going back n forth with you teaching basics, you could learn on your own is a waste of everyones time

rich adder
#

lol I can't even react emoji since I'm blocked

summer stump
#

This is so extremely simple. I don't understand what part is stumping you, except a refusal to try
"Not going in there that's a waste of time" notlikethis

ruby ember
deft grail
ruby ember
deft grail
boreal dagger
#

Hi everyone. I want to learn how to code in C# for Unity. Do yall know any good resources?

boreal dagger
rich adder
#

learning the basics first

boreal dagger
summer stump
deft grail
eternal falconBOT
rich adder
boreal dagger
#

Thank you guys for the help

cosmic dagger
summer stump
#

And still doing its job haha

rich adder
#

could make it a Github markdown with links?

cosmic dagger
#

i think that's around when i started . . .

boreal dagger
#

:))

cosmic dagger
ruby ember
#

il just leave

it dosen't mean leaving the server

deft grail
#

after i told you what to do

ruby ember
#

no

boreal dagger
ruby ember
rich adder
ruby ember
#

a person knows how to do this type of script

deft grail
#

because i told you how

summer stump
#

It's literally removing one word from a line, and adding another line

#

That is it
Don't think it is too much. You can do it

ruby ember
rich adder
#

you should very least try to put in some effort on the help given

#

they literally give you code and you still refuse to try

ruby ember
#

ok

cosmic dagger
# boreal dagger How long did it take you to learn?

i learned quick, but that's because i really wanted to and like learning new shit, and it was easy to follow. everyone learns differently; it really depends on their drive and willingness to learn

what helped me most was typing out all the code myself and understanding each line and concept before moving to the next. i completed the links from rbwhitaker's website, then went onto the unity beginner and intermediate tutorials. after that, i was ready to follow along from youtube tutorials . . .

cosmic dagger
meager nova
#

@summer stump

meager nova
summer stump
#

ChestNewWithAnim3 is the character?

meager nova
#

yes

summer stump
#

And remember I said whole editor

#

You have it cropped

meager nova
summer stump
#

Ok... move it up. It is clearly in the ground.

#

Set it to like 2 y

meager nova
#

Nope

#

like, i wait until IsGrounded is true, then i copy it and set to the base Y

#

However

#

Only 1 frame later it updates it

#

if (characterController.isGrounded) { isGrounded = true; animator.SetBool("IsGrounded", true); } else { isGrounded = false; animator.SetBool("IsGrounded", false); }

#

This is on void Update()

#

should it be on lateupdate

#

or something

rich adder
#

btw this can just be
animator.SetBool("IsGrounded", characterController.isGrounded)

meager nova
#

didnt know that

#

let me change it

rich adder
#

its not the fix though

#

isGrounded from character controller is very flakey

meager nova
rich adder
#

use spherecast or overlap etc

meager nova
#

:(

#

fml

#

so what are my alternatives

rich adder
#

I just said it lol

meager nova
#

meh i think im

#

what's an overlap

#

i think i'll just make it ignore first few frames...

#

:)

cosmic dagger
#

!code

eternal falconBOT
green hinge
#
using System.Collections.Generic;
using UnityEngine;

public class PlanetGravity : MonoBehaviour
{
    public List<Rigidbody> objectsToAttract = new List<Rigidbody>();
    public GameObject planetCenter;
    public float gravityForce = 10f; // Adjust this value to control the strength of the gravity

    private void OnTriggerEnter(Collider other)
    {
        Debug.Log("Trigger entered");
        if (other.gameObject.GetComponent<Rigidbody>() != null)
        {
            objectsToAttract.Add(other.gameObject.GetComponent<Rigidbody>());
        }
    }

    private void OnTriggerExit(Collider other)
    {
        Debug.Log("Trigger exited");
        objectsToAttract.Remove(other.gameObject.GetComponent<Rigidbody>());
    }

    private void FixedUpdate()
    {
        // Apply gravity force to each object in the list
       foreach (Rigidbody body in objectsToAttract)
{
    // Calculate the direction from the center of the planet to the object
    Vector3 direction = (planetCenter.transform.position - body.position).normalized;
    Vector3 localUp = body.transform.up;

    // Apply gravitational force
    body.AddForce(direction * gravityForce);

    // Rotate the object to align with the gravity direction
    body.rotation = Quaternion.FromToRotation(localUp, direction) * body.rotation;
}
    }
}``` Hey i'm trying to make a gravity bubble like Angry Birds Space that attracts objects toward the center, It wont work, it just gets pushed off, and I dont understand and know how to get the force to be pulled toward the center, thank you
jade rose
#

and it'll use the colour formatting

green hinge
#

ok

#

but any ideas on how to fix the issue?

jade rose
#

your on the right track

// create a grav zone

// calculate direction from object to center

// apply force

it looks like you just have the force going the opposite direction

meager nova
#

Moving it to lateupdate fixed it

green hinge
jade rose
#

try what navarone said - it should be that simple

cosmic dagger
#

think of the direction as (destination - origin) . . .

green hinge
#

Alright so A - b

cosmic dagger
#

if it's going the opposite direction, i'd start off by flipping the direction . . .

jade rose
#

do any of you know much about initializing objects via script?

summer stump
green hinge
#
Vector3 direction = (body.position - planetCenter.transform.position).normalized;```
#

is this correct?

jade rose
cosmic dagger
green hinge
#

it got pushed off

cosmic dagger
#

using the opposite direction should not create the same effect. one way should pull while the other way pushes . . .

summer stump
cosmic dagger
jade rose
#

a prefab with a .fgb model and a mesh collider

summer stump
#

Instantiating it with a parent would not cause it to not exist

jade rose
#

like - its not anywhere even though the transform values should be the same

#

i posted here

green hinge
#

cs```
cs
private void FixedUpdate()
{
// Apply gravity force to each object in the list
foreach (Rigidbody body in objectsToAttract)
{
// Calculate the direction from the center of the planet to the object
Vector3 direction = (body.position - planetCenter.transform.position).normalized;
Vector3 localUp = body.transform.up;

// Apply gravitational force
body.AddForce(direction * gravityForce);

// Rotate the object to align with the gravity direction
body.rotation = Quaternion.FromToRotation(localUp, direction) * body.rotation;

}
}``` here's the code i have. I think it's either the direction or the addforce, i dont really know

jade rose
#

again.. put c# at the top

#

so its legible

#

your making it alot harder to quickly read after having it explained repeatedly lol

green hinge
#

alright sorry

summer stump
jade rose
slender nymph
jade rose
#

c# works too

slender nymph
#

must be a fairly recent change because it didn't for the longest time

jade rose
#

its worked for atleast a few years

jade rose
summer stump
green hinge
#
 private void FixedUpdate()
    {
        // Apply gravity force to each object in the list
       foreach (Rigidbody body in objectsToAttract)
{
    // Calculate the direction from the center of the planet to the object
    Vector3 direction = (body.position - planetCenter.transform.position).normalized;
    Vector3 localUp = body.transform.up;

    // Apply gravitational force
    body.AddForce(direction * gravityForce);

    // Rotate the object to align with the gravity direction
    body.rotation = Quaternion.FromToRotation(localUp, direction) * body.rotation;
}
    }``` Ah there we go
cosmic dagger
jade rose
cosmic dagger
summer stump
jade rose
#

all good!

summer stump
jade rose
#

i didnt want to spam the same post in multiple places

summer stump
rich adder
jade rose
green hinge
#

Wait i know

summer stump
green hinge
#

maybe i should do directionX directionY and directionZ to attract it in 3d

jade rose
summer stump
#

You are setting the LOCAL position, which is the offset from the parent. Without a parent it uses the world origin. With a parent the parent is the pivot

jade rose
#

unityexplorer is basically just like the edditor

#

gimme a sec

#

i broke it trying to change stuff around

jade rose
#

ok so this is the object that exists

#

this is the object that doesnt exist

#

for some reason its making 2 objects when it should only make one

#

i can manually assign the clone object to the parent object

#

and it will exist

cosmic dagger
jade rose
#

which is why im assuming its a scripting error

green hinge
#

WOOWOWOWOwOwwjdwqindndjqqdegyhbdqdiqeddieqasw

jade rose
#

and im doing something incorrectly

green hinge
#

It works!!!!!!!!!!!!!!

jade rose
#

so it shouldnt be affecting anything

#

atleast to my understanding?

rich adder
summer stump
jade rose
#

im assuming the issue has to do with

#

why are there 2 objects?

#
            if (sceneName == "MainGame")
            {
                GameObject va01system = GameObject.Find("SingleplayerGame/GameMaster/VA01");
                if (va01system != null)
                {
                    // load thomas
                    if (!thomasLoaded)
                    {

                        if (thomasModel == null)
                        {
                            LoggerInstance.Msg("Loaded Bundle Successfully.");

                            thomasModel = AssetBundle.LoadFromFile("Mods/AssetBundles/thomas");

                            // load thomas once
                            GameObject thomasPrefab = thomasModel.LoadAsset<GameObject>("Thomas the Tank Engine");
                            Vector3 thomasPos = new Vector3(-30488.41f, 489.5023f, 38069.4f);

                            // set thomas's scale
                            thomasPrefab.transform.localScale = new Vector3(20, 20, 20);

                            // set thomas's local position
                            thomasPrefab.transform.localPosition = thomasPos;

                            // test parent
                            thomasPrefab.transform.parent = va01system.transform;

                            // initialize thomas
                            modelInstantiator.LoadModel(thomasPrefab);

                            LoggerInstance.Msg("Thomas Should be waiting for you outside planet Vauldric!");

                            // set loaded to true
                            thomasLoaded = true;
                        }
                        else
                        {
                            LoggerInstance.Msg("Failed To load Bundle.");
                        }
                    }
                }
            }
public class modelInstantiator : MonoBehaviour
{
    public static void LoadModel(GameObject model)
    {
        Debug.Log("Object Instantialized!");
        Instantiate(model);
    }
#

this is a post of my code again

#

im only instanitalizing a single object

cosmic dagger
#

bruh, what is this screen we are looking at?

rich adder
jade rose
#

theres no easy way to access the objects

#

i dont really have full access to source

rich adder
#

ofc there are

jade rose
#

if i was making the game myself for sure but - im trying to set up mod-tools for the game

jade rose
cosmic dagger
jade rose
#

its a mod called unityexplorer - it basically just puts the editor in the game so you can use it and play

#

VAO1 is the parent object im linking to

Thomas (Clone) is the parentless object that works

and Thomas is the child object that isnt working

summer stump
#

I don't see anything jumping out at me, but it may have something to do with the base game you are modding. I see only one instantiate call.
If it was the whole method running twice, it would be the same settings.

Because it says (clone), then something must be instantiating another one FROM the model you just instantiated.
That makes me feel like it is from different code

#

But that doesn't answer why the first one is not working

jade rose
#

the clone is - presumably the first one

#

is that not how

#

assetbundles work?

summer stump
#

Clone means it was instantiated from an instance in the scene already

jade rose
#

if i dont do parent transformation the clone is the only one that exists

#

i was assuming that was how asset bundles work

summer stump
#

Well, I dunno. I don't use asset bundles, so that may be it.

jade rose
#

because i can make it so theres only one thomas and it'll be a clone

jade rose
jade rose
#

i have to link-in and patch methods if i want to do stuff like that

#

but im not utilizing that feature

#

how does instantialize work without asset bundles?

#

not sure if this is outdated

#

but presumably instantiating prefabs assigns the clone

jade rose
#

and it works fine

#

i just dont understand how to do that in script

summer stump
jade rose
#

i wasnt aware i could do that

#

i'll pull up instantiates api again

summer stump
#

I would do the position AND parent in instantiate

jade rose
summer stump
#

You must do all the the parameters for the selected overload

olive galleon
#

I'm following a tutorial and have a question about how this code works, the only confusion I have is how can "TestingEvents_OnSpacePressed;" be accessed by the Start() function if TestingEvents_OnSpacePressed is a private void. Is it because they both reside under a public class so functions can access one another ?

summer stump
#

The class being public is irrelevant

jade rose
summer stump
jade rose
#

whats the difference sorry?

summer stump
jade rose
#

thank you so much

#

ive been stuck on this for over a week 😭

jade rose
# rich adder ofc there are

out of curiousity

what way would you suggest linking to a game object that has a persistently changing name

rich adder
#

a component

#

dependency inject it when possible

gleaming elk
#

Hi! I’m so new to unity and I’ve been having an issue with fungus ;-;

rich adder
#

finding something by name is pretty brittle

jade rose
#

or i'd have to rewrite a large chunk of code just to add it

#

the ship object is a parentless object

#

and im not really sure how to access it

#

like i have this
but - i dont know how to call the field

#

because the field exists on the object that has a changing name

#

i cant just call as-is

rich adder
#

huh ? doesnt it have a component?

#

components are Object

#

not sure I follow, this seems to be some type of mod so I'm not sure 🤷‍♂️

olive galleon
#

Should I try to have 1 class per 1 script? Or will there be times when I'll need to have multiple classes in 1 script?

jade rose
summer stump
#

Sometimes you may want to have classes INSIDE of other classes, or small non-monobehaviour classes alongside monobehaviours, but other than that, separate them

#

Definitely never do two or more monobehaviours in a single script. That will cause issues

rich adder
jade rose
#

you can look for components that you dont know the gameobject of? :O

rich adder
jade rose
# rich adder why would you look for specific name?

so both of these game objects have names that change depending on what system you are in or what ship you are flying

i wasnt aware that i could get these objects in other means without storing an object refrence somewhere which isnt nessesarily something i can do easily

delicate portal
#

Hey! For some reason I cannot build this, because EditorUtility doesn't exist in the current context.
I know it can only be used inside the editor, but how should I open the explorer then in a built version?

delicate portal
teal viper
#

This is all googleable btw

delicate portal
#

Works!

#

What should I use instead of WWW ?

#

It works,but who knows one day if it will

rich adder
delicate portal
#

There is no .texture in that class

#

I tried that

rich adder
eternal needle
#

did you look at the link even? it has an example

#

if you scroll down like once

delicate portal
eternal needle
#

it shows the other way around for me, but yea regardless the example shows what to do. there is indeed no .texture

stuck palm
#

@rocky canyon hey man, just wanted to tell you how I fixed my system yesterday

I decided to use rigidbody like you suggested and by changing the unity gravity values to my system's values (4x gravity) and stuff I was able to achieve a near identical feel to my old system. To this end, I also implemented a character controller / rigidbody hybrid with my players, so that when they enter a bouncy state they deactivate the CC and enable dynamic rigidbody. I made the floor have the same bounce values as my old system as well, and it has achieved a near identical effect 😊

#

I didn't actually have to change much in my scripts, and just replaced my old moveVector thing with rb.velocity with most of the values and it just worked out the box

rich mountain
#
'string' does not contain a definition for 'Interact' and no accessible extension method 'Interact' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
    void Update(string currentInteractable)
    {
        CheckInteraction();
        if (Input.GetKeyDown(KeyCode.F) && currentInteractable != null)
        {
            if(!OpenInventory.Instance.CheckIfFull())
            {
            OpenInventory.Instance.AddToInventory(currentInteractable);
            currentInteractable.Interact();
            }
            else
            {
                Debug.Log("inv is fulll");
            }
        }
    }

Im trying to make a inventory for interactable objects but i get this error.

green ether
#

what are you expecting to happen?

#

string.Interact() doesnt exist

scarlet skiff
#

i want this to return a random object from this list, or rather hashSet, or playerObjects, and get their components too, but when i use it, even tho there is one in the scene, it says null reference, am i missing something here? cant figure it out

gaunt ice
#

where you create the hashsets?

#

btw learn how to create a custom sturct/class for grouping the data

scarlet skiff
# gaunt ice where you create the hashsets?

public static HashSet<PlayerMovement> playerMovementScripts;

foreach (PlayerMovement script in FindObjectsOfType<PlayerMovement>())
{
playerMovementScripts.Add(script);
}

#

or is something missing

gaunt ice
#
public List<int> ints;
public List<string> strings;
turn to
public struct MyStruct{
  int theInt;
  string theString;
}
public List<MyStruct> myStruct;
```how to use struct
```cs
public static HashSet<PlayerMovement> playerMovementScripts;<---declaration

foreach (PlayerMovement script in FindObjectsOfType<PlayerMovement>()){<-- you use it
     playerMovementScripts.Add(script);
}
public List<int> ints;<---variable declaration
ints=new List<int>();<--assignment/create the instance
vague tiger
#

how to move object with the same speed using rigidbody.addforce?

#

and not like accumulate force

languid spire
#

Forcemode velocitychange

vague tiger
gaunt ice
#

you need to calculate the opposite force by yourself then add the force back, force must change the velocity

gaunt ice
scarlet skiff
#

ok thanks

west sonnet
#

I'm using OnTriggerStay2D and when the player presses the E key, it should show a debug.log message. But it only seems to work every few seconds. Anyone know why?

gaunt ice
west sonnet
#

Any way to change the rate of it being fired?

#

What would be the best way to detect when a player presses a key while inside a trigger collider?

eternal needle
#

dont try changing the physics to accomodate, it wont work either as expected

west sonnet
#

Okay, I'll check for input in Update. But how can I only check for it while the player is within the trigger?

eternal needle
#

you dont, you check for it all the time and then set a value. Check that value whenever you want

west sonnet
#

I'm not sure I get what you mean. Check for it all the time and use a bool?

eternal needle
#

actually, can you show code? are you using GetKeyDown?

eternal needle
#

my bad ignore what i said above, its incorrect.
https://docs.unity3d.com/ScriptReference/Input.GetKeyDown.html This is only true for one frame. Physics stuff doesnt run at the same rate as update, so this is why its rarely working. If you have 2 frames between a fixed update (which is very likely) then in frame 1 it can be true, in frame 2 it'll be false and fixed update never ran between these
You might be able to get away with just using GetKey instead

#

If you really need to use GetKeyDown here, if it matters that you're doing the logic over and over, then i would approach this differently.

gaunt ice
#

toggle a bool in enter and exit to indicate the player in the zone, then check its value in update

eternal needle
#

this code does seem a little odd though, the collision doesnt seem to be checking anything. if you enter any trigger at all, then you can press E. Is this what you want?

west sonnet
eternal needle
tidal basin
#

HI, I am trying to use new input system for my fps game. But i cant find how can i use the mouse raw input. Is there a way?

summer shard
#

how can i do something like this

public enum Interactions {
    use = "Użyj", pickup = "Podnieś"
}

public Interactions interactionText;
public UnityEvent interactEvent;
gaunt ice
#

looks like localization

summer shard
#

wdym??

gaunt ice
#

translate the text in your app to other languages

#

=>localize

#

btw c# enum must be integral type

summer shard
#

nah, i want to make an interaction system with different interaction texts but i don't want to manually set them with a string, and also so that other developers wouldn't make a mistake, so i want to make an enum holding string values, where devs can pick what type of interaction string they want to use for this object, use, pickup, etc

eternal needle
summer shard
gaunt ice
#

other developers use your enum, so they cant make mistakes on the enum name

summer shard
#

like this?

willow scroll
#

And I would suggest writing enum items' names in English.

summer shard
#

im making a polish game, that's why i tried doing the "dictionary" type of thing, if i change it to english it would display in english

willow scroll
eternal needle
summer shard
gaunt ice
#

so localization

willow scroll
summer shard
willow scroll
#

If you want to make your game available in multiple languages, it doesn't mean you will have to rewrite all your variables in other languages

gaunt ice
#

the language of your programming wont affect the language in your ui, you can use tab and space only to code and it still displaying english

willow scroll
summer shard
#

so i can't do a "dictionary" enum? and have to use polish names for enum items?

willow scroll
#

But it won't be serializable

eternal needle
summer shard
eternal needle
#

Im not entirely sure what you're asking. Some code would presumably know what string it wants then get the string

gaunt ice
#

name your enum be polish should work? as long as the compiler can compile it?
i think you want to display the enum name directly?

summer shard
# eternal needle Im not entirely sure what you're asking. Some code would presumably know what st...
void HandleInteraction() {
    RaycastHit hit;
    Ray ray = _camera.ScreenPointToRay(Input.mousePosition);
    if (Physics.Raycast(ray, out hit, interactionDistance)) {
        GameObject raycastObject = hit.transform.gameObject;
        Interactable interactable = raycastObject.GetComponent<Interactable>();
        if (interactable && Input.GetKeyDown(interactionKey)) interactable.interactEvent.Invoke();
        if (interactable) {
            interactionText.text = $"[{interactionKey.ToString()}] [{interactable.interactionText}]";
        }
    }
    else interactionText.text = "";
}
public class Interactable : MonoBehaviour {
    
    public enum Interactions {
        Użyj, Podnieś
    }
    
    public Interactions interactionText;
    public UnityEvent interactEvent;
}
summer shard
eternal needle
summer shard
eternal needle
#

Well either dictionary or just a method with switch statement.

eternal needle
gaunt ice
#

type the translation manually and use the enum in english to retrieve the text in polish

eternal needle
#

The answer saying with extension method

summer shard
#

ts too hard, as a begginer i think i'll just stick with polish names for the enum, don't want to make one thing take a day to do

eternal needle
#

If doing a switch is too hard, consider doing c# basics first

summer shard
eternal needle
vague tiger
#

why this doesnt work properly
once i press a button
the cube starts moving left
but once i stop holding a button
it wont stop moving

#

nvm

novel kettle
#

Trying to make a script where material shaders glitch out with the BPM, but i cant seem to get the bpm script right.

vague tiger
#

how to make make game run horizontally on mobile?

languid spire
fierce shuttle
# tidal basin HI, I am trying to use new input system for my fps game. But i cant find how can...

You can either poll the mouse input with Mouse.current, or you can create an action in your Input Action Asset with a path to the mouse delta or position (or whichever info your looking for), and then reference that with .ReadValue<T>(), where T would be the type of input, for example yourActionMap.yourActionWithMousePath.ReadValue<Vector2>() if you were reading delta or position
https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/HowDoI.html#find-the-gamepad-that-the-player-is-currently-using

tidal basin
fierce shuttle
strong wren
ripe oyster
#

i'm using tilemaps for the first time, however the colission is weird. i'm using 'TileMap Collider 2D' but the collider on slopes is off. there is a gap in which the player gets stuck. does someone know how to fix it?

static cedar
#

In the sprite editor you see this on top left.

ripe oyster
#

found the option

#

perfect, thanks

scenic saffron
#

Whats the difference between a Vector and a normalized Vector

timber tide
thorn holly
scenic saffron
scenic saffron
timber tide
#

(0, 0, 1) for z-forward

#

but now what does (0, 0, 2) mean for a directional vector

scenic saffron
#

twice as large in the z direction?

timber tide
#

for direction it means the same thing as (0, 0, 1)

#

however, if you're looking for distance along with direction, (0, 0, 2) gives you information such that we're looking in the z-forward direction and up to 2 units of length in that same direction

#

but if you're normalizing you're usually doing it on something for direction, so even if you had some vector greater than 1, it'll normalize it back into (0, 0, 1)

scenic saffron
#

Ok thx

#

I stole some code from ChatGPT and wanted to know why it normalized the Vectore

timber tide
#

general rule of thumb, if you're doing a calculation resulting in a direction, normalize it

scenic saffron
#

Ok thx

fringe plover
#

i need help.
I tried creating texture and saving in data folder:
File.WriteAllBytes(Application.dataPath + "/test.png", bytes);
But it says that access denied

thorn holly
scenic saffron
willow scroll
scenic saffron
#

And If it doesn't give me the results im looking forI just don't use it

thorn holly
scenic saffron
thorn holly
#

Which is why you shouldn’t use chat gpt code

#

You should know exactly what the code your using does

scenic saffron
#

If the code it gives me doesn't work I just don't use it

scenic saffron
thorn holly
#

Don’t turn to chat gpt

thorn holly
#

I suck at base jumping, but if I wanted to get good at it, I’d learn how to do it, not have somebody else do it for me

#

Kinda ruins the entire purpose, if that makes sense

wild veldt
#

hello, does a class that extent another class also inherit the base's execution order ?

wild veldt
#

in project settings

thorn holly
#

Oh sorry, I’m not sure

swift crag
#

and I don't think Unity is aware that script B has a class that derives from a class in script A

tidal warren
#

Hello friends, I am new to unity and i have a question. I messed around with unity's built in Character controller and using rigid body, and the movement always felt unsatisfying in a way. The thing i want in mind is a way for the movement to accelerate at a given rate, and also decelerate at a given different rate.

To further elaborate this and what I want, When the character moves forward, there should be a few seconds for example where the character is gaining speed until they reach their maximum speed, and when the user lets go of the forward button for example the character would stop moving but not instantly (which is the thing i am trying to fix). Further examples would be Cars, imagine car on neutral, gas peddle = accelerate, leave gas = decelerate.

I am using the old input system btw
I found a solution for the acceleration that works just fine (Image 1)
I just cant find one for the deceleration.

swift crag
#

you just need a different value when slowing down

wintry quarry
swift crag
#

acceleration * 3 would make you slow down three times faster than you speed up

wild veldt
timber tide
swift crag
tidal warren
timber tide
#

Usually properties help lessen the amount of information I needed before everything is loaded in. Just bind references then execute later.

wild veldt
swift crag
wild veldt
#

yes

#

it works sometimes

swift crag
#

I'd just make this explicit.

wild veldt
#

but it depends on the ordering

swift crag
#

Instead of using Start, add a "setup" method.

#

A will still use Start.

#

It calls B's Setup

timber tide
#

Start is pretty random and I try to avoid it

swift crag
#

Then B calls C's Setup

wild veldt
#

oh that's smart

swift crag
#

This is roughly how I do all of my UI setup

wild veldt
#

thank you

swift crag
#

my settings menu starts with a list of categories/settings

#

the list creates all of the buttons and settings entries, then creates new lists for the categories and tells them to setup

#

another useful thing: if you sometimes have A call B call C ..., and sometimes just have B or C by themselves (that don't need any setup), you can do something like this

timber tide
#

Another idea I've had is just make everything a prefab and instantiate at the start by iterating over the list but it's a pain then to work on the editor

swift crag
#
public class B : MonoBehaviour {
  private bool initialized = false;
  
  void Start() {
    if (!initialized) {
      Initialize();
    }
  }

  public void Initialize() {
    initialized = true;
  }

  public void InitializeWithData(int whatever) {
    // do something with that data
    Initialize();
  }
}
#

I used this for a component that was sometimes set up with code and was sometimes setup manually in the scene

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

public class Move : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        transform.Translate(Vector3.right * 3 * Time.deltaTime);

    }
}```

it is not really moving my object, anyone knows why?
deft grail
lost cypress
#

the object is intially in the air so when I play it, it goes down and that is it, it never goes forward

deft grail
swift crag
#

multiplying by deltaTime is correct here

#

otherwise, you will be moving at 3 meters per frame

#

rather than three meters per second

lost cypress
swift crag
swift crag
#

You need to use those to move

#

Don't directly change the position of the transform.

#

Which one are you using?

lost cypress
swift crag
#

If you're using a Rigidbody, then either use AddForce to push it or MovePosition to directly give it a new position

deft grail
#

or change its .velocity

lost cypress
#

what do I do agian, I am confused

#

Another problem now is that not the entire part of my train moves, i checked that all of the gameobjects have the script, why is one not moving?

deft grail
swift crag
#

It doesn't care about physics at all, because it's not doing anything with a Rigidbody

#

Now, the rigidbodies will still do something -- you're going to be fighting with them

lost cypress
willow scroll
deft grail
wintry quarry
#

use velocity or AddForce

wintry quarry
# lost cypress no

hoenstly sounds like it's working just moving too slow for you to notice

#

how big are these objects

swift crag
#

MovePosition attempts to actually move to the destination

wintry quarry
swift crag
#

although, confusingly, it does say

#

Moves the kinematic Rigidbody towards position.

wintry quarry
#

for kinematic bodies it moves them and collides with other things

swift crag
#

yet:

#

Teleporting a Rigidbody from one position to another uses Rigidbody.position instead of MovePosition.

willow scroll
wintry quarry
#

yes it's intended for kinematic bodies

swift crag
#

Ah, I see! So it hits things, but it is not hit by things.

wintry quarry
#

yeah. It's intended for teleporting kinematic bodies while maintaining interpolation and hitting things

swift crag
#

good to know...I was under the impression that it attempted an actual movement of a non-kinematic rigidbody

rich adder
#

good example is Moving platform

lost cypress
#

guys still lost

deft grail
lost cypress
#

how do i use addForce

deft grail
#

google Unity AddForce

swift crag
#

indeed -- that cube went straight through the wall

#

that's actually pretty annoying. there doesn't seem to be a way to neatly move a rigidbody to a new position in a way that respects colliders

#

interestingly, when the rigidbody is non-kinematic, it doesn't hit other non-kinematic rigidbodies along its path

#

i had to make it kinematic for that to happen

willow scroll
# lost cypress how do i use addForce

Your code with the MovePosition can be rewritten with the AddForce by removing the position from the 1st parameter, as the MovePosition takes the new position, and AddForce the direction

frail whale
#

have an interesting problem trying to first person camera controls with the new input system, trying to clamp camera rotation on the x-axis taking mouse delta as an input. any suggestions on how to appropriately clamp the main camera's rotation during update? issue im running into is that since delta is constantly refreshed, i never actually come close to approaching my clamp value per update unless i sling my mouse, so there's nothing actually limiting the global rotation of the camera

lost cypress
# deft grail look at the documentation for it
public class Example : MonoBehaviour
{
    public float thrust = 1.0f;
    public Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
        rb.AddForce(0, 0, thrust, ForceMode.Impulse);
    }
}```
#

still not moving

willow scroll
lost cypress
#

I used this code

#

from the documentation, obviously changed the class name

willow scroll
deft grail
#

also increase it a bit instead of 1

lost cypress
#

you mean like this?

deft grail
lost cypress
#

where in the insepctor is it? Can I not change it duing script? Isn't there another easier way?

lost cypress
#

My first code: ```cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Move : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
    transform.Translate(Vector3.right * 3 * Time.deltaTime);

}

}```

deft grail
willow scroll
#

The value you assign via code is the default value for the Inspector, when the script is first added

lost cypress
#

had worked before, but after I made huge changes in the scene, it doesn't anymore

deft grail
lost cypress
#

still not moving

deft grail
swift crag
#

show the code and the inspector for your component

lost cypress
#
using UnityEngine;

public class Move : MonoBehaviour
{
    private Rigidbody rb;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
        rb.AddForce(transform.right * 5, ForceMode.Impulse);
    }
}
deft grail
#

show the inspector of your train

lost cypress
deft grail
lost cypress
raw kindle
#

I am doing a flood check to check if all objects in a ship starting from the core are connected, I use the offsets from the core which are multiples of 1.28, for some reason here (-1.28,-1.28,0.00) does not equal (-1.28,-1.28,0.00) even though it does

swift crag
#

that object is veeeery far away from the world origin

lost cypress
#

I actually have 3 lol

swift crag
#

it's also colossal

#

an impulse of 5 means a 1 kilogram object will gain 5m/s of velocity

#

if the object is a kilometer across, that will barely be perceptible

deft grail
#

yeah 600 scale is insane

#

everything usually should be around 1

raw kindle
swift crag
#

I would suggest using Vector3.Distance to check if you're within a small margin

chrome tide
#

here i have this code, it's for a scanner that scans a selected area so it will show where are the nearby objects, and this IEnumerator spawns, and then destroyes the dots:

private IEnumerator ScanRender(Vector3[] points)
{
    List<GameObject> pointClones = new List<GameObject>();

    foreach (var p in points)
    {
        GameObject pointClone = Instantiate(point, p, point.transform.rotation);
        pointClone.transform.parent = pointsParent.transform;
        pointClones.Add(pointClone);
        yield return new WaitForSeconds(0.000000005f);
    }

    yield return new WaitForSeconds(dotLifetime);

    foreach (var pointClone in pointClones)
    {
        Destroy(pointClone);
        yield return new WaitForSeconds(0.000000005f);
    }
}```

I want this process to happen really fast, so it will look satisfying but won't be annoying for the player, and the problem is that no matter how much smaller the value in "WaitForSeconds()" is, it still seems like it waits the same amount of time. does it have a limit? if it does, then how do i bypass it?
swift crag
#

alternatively, work in grid cells instead with Vector3Int

swift crag
#

operator == for Vector3 has a slight fudge factor

swift crag
raw kindle
#

you mean scale them down to 1 instead of the odd value of 1.28

tidal parrot
#

yo, guys, im making a simple collision system for my game

I'm using Tilemap Collider 2D, Rigidbody 2D, Composite Collider 2D

is there any way to shrink down the collision hitbox more?

swift crag
#

When you use a Tilemap, you can ask it where in the world a specific cell is.

#

The resulting position depends on:

  • how big each tile is
  • where the Tilemap has been positioned
#

So, for a 3x3 grid placed at the world origin, the cell [1, 0, 0] has a world position of [3, 0, 0]

#

in your case, you have a 1.28x1.28 grid

#

It's easier to reason about which grid square the tile is in than where in the world the tile is

#

[1, 0, 0] is a neighbor of [0, 0, 0]

#

you don't care how big the tiles are or where the Tilemap is

raw kindle
#

In the game it more important where the objects are at in relation to the core which Obj.offset, but I will sure look into that when I try to optimise thanks for the suggestion

swift crag
#

so this object is 4 cells right and 3 cells up from the core

#

You can use the Grid component for this.

rocky canyon
swift crag
#

stick a grid on the core and use it to translate back and forth

raw kindle
#

also you were right I was just using wrong function to compare vectors

bitter crown
#

yo

#

im doing a unity course and its saying my code is wrong even tho i did exactly what the instructor did

#

can someone tell me what the problem is

languid spire
#

missing )

scenic saffron
#

you forgot a bracket at the end

swift crag
#

you did not do exactly what the instructor did (:

bitter crown
#

omg

swift crag
#

as a rule of thumb, you must match all ( ), { }, and [ ]

bitter crown
#

ill fix it

swift crag
#

Note that your code editor was indicating an error at the end

#

and in this case, it's informative!

bitter crown
#

i still dont see the issue

#

where is the missing bracket

scenic saffron
#

at the end

#

right before ;

swift crag
bitter crown
zenith cypress
scenic saffron
polar grail
bitter crown
#

OH

swift crag
#

; terminates a statement.

scenic saffron
#

; is almost always last

swift crag
#

it is unwise to put it in the middle of your statement

bitter crown
#

its fixed

#

excuse my lack of brain power

#

thank you all

scenic saffron
#

no problem

bitter crown
#

the fact i needed 23 minutes and outside help to fix that is astonishing

polar grail
scenic saffron
#

btw does anyone know how I can decide what layer my 2d character is on without changing the z coordinate?

languid spire
bitter crown
scenic saffron
polar grail
scenic saffron
#

the position of the object changes the position of a different object

scenic saffron
rich adder
scenic saffron
#

i think so

rich adder
#

or play with sorting Layers

scenic saffron
#

found it

#

works thx

summer stump
full wave
#

hello, im coming back to unity after a long pause, so i forgot most of the thing i knew.

i was watching a video from sebastian lague where he was simulating fluids.
but at abt 30 sec, he typed DrawCircle(Vector2.zero, 1, Colour.lightBlue); into update.
i never saw a function like that before, and when i went to try it out, it says both the method DrawCircle() and Colour dont exist. but it works fine in the video.
im confused. is there a similar function to that that works?
this is the video: https://www.youtube.com/watch?v=rSKMYc1CQHE

Let's try to convince a bunch of particles to behave (at least somewhat) like water.
Written in C# and HLSL, and running inside the Unity engine.

Source code:
https://github.com/SebLague/Fluid-Sim

If you'd like to support me in creating more videos like this, you can do so here:
https://www.patreon.com/SebastianLague
https://ko-fi.com/sebastia...

▶ Play video
swift crag
#

Both of these must be third-party code

#

unity's Color class (not Colour) doesn't have a lightBlue property

#

and there is indeed no DrawCircle

full wave
swift crag
#

LightBlue, not lightBlue

#

(and it's still not Colour)

full wave
rocky canyon
#

@stuck palm why the ninja edit/ delete?

#

thats exactly why it was easy.

stuck palm
tawdry depot
#

hi, how know this how can I fix
Game scripts or other custom code contains OnMouse_ event handlers. Presence of such handlers might impact performance on handheld devices.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

stuck palm
#

I was just patting my own back a bit lol

rocky canyon
#

ahh okay.. but yea, apparently ur system was pretty accurate to real life physics..

stuck palm
full wave
frigid sequoia
full wave
#

circles are cool

#

idk, they are the best representation of particles, and they are easiest to move and shi

rocky canyon
#

i agree

warped ginkgo
#

Im trying to make a camera in my game move like the unity camera, I already managed to do the movement because it was ez, but now its time for the hard stuff: rotating. Esentially, whenever i drag my mouse, the camera's rotation should follow it, just like it does in unity. How can I do this?

full wave
#

ill do it using prefabs i guess

frigid sequoia
#

Use that

full wave
#

by particles i mean like atoms

#

or molecules

#

not effects'

#

i forgot particles have 2 meanings

rich adder
#

not that much different than fps camera without the clamp

full wave
#

what `is the thing called, where i have an array, but each element has multiple variables

swift crag
#

that'd just be an array of objects

#

or structs

#
[System.Serializable]
public class MyData {
  public int florp;
  public string foo;
}

public List<MyData> items;
full wave
#

like

[
{v=10, x=4}
{v=4, x=5}
.
.
.
]```
warped ginkgo
full wave
#

oh

rich adder
west sonnet
#

I have a UI menu and a sprite as my cursor. I've used "Cursor.visible = false" to hide the cursor. I'm trying to find a way to create sprites that are clickable, like menu items. how can I do it?

rich adder
#

ayee

rocky canyon
#

i keep forgetting i have no clamp..

rocky canyon
rich adder
rich adder
#

dont forget to disable the Raycast target on it or its going to block other UI elements

rocky canyon
#

even 3d objects if u have a graphic raycaster component

#

^ yup, thast how i do my custom cursors.. tehy are image components that follow the mouse position after converting to screenspace

#

w/ raycast target disabled u can click thru to the element under

west sonnet
#

I have an image component as my cursor. Then my menu screen is another image and I've got a box collider on a specific part of it that should be clickable. Thing is, I click and nothing happens. What am I doing wrong?

rocky canyon
#

you dont need a box collider for an image component

west sonnet
#

How can I get it so that only part of the image component is clickable? As in, it will trigger something

rocky canyon
#

heres a video i made a while ago.. it covers different types of ways u can do it

west sonnet
#

Thanks!

rocky canyon
#

and disable the raycast target tick on that

#

thats the only way i can think of making just part of the image clickable

rocky canyon
#

ohh interesting

#

i didn't know it even worked like that..

#

i thought it was a bounds type of thing

rich adder
#

yup is really handy

#

the only weird thing is you can only set it via code

rocky canyon
#

but default it will click on a transparent pixel right?

#

b/c if not i need to redo some stuff 😄

rich adder
#

without it, uses the rect transform bounds

rocky canyon
#

ohh okay good good

west sonnet
rich adder
gleaming burrow
#

The skeleton is moved on the Y axis when he wait, can you help me ?

languid spire
#

Dont need to do that. Just use that link to set the threshold on your original image

west sonnet
rich adder
languid spire
#

That is the whole point, did you read the docs I linked?

gleaming burrow
#

when the coroutine is calleed

rocky canyon
#

oh okay

west sonnet
languid spire
#

you said you had an image, that is the sprite

rocky canyon
#

i doubt his image is based off of alpha..

west sonnet
#

The background image, yeah. But I've got another transparent image on top where I want it to be clickable

rocky canyon
#

you can put an event system on that image component

#

and have access to OnClick, etc

#

EventTrigger component is the easiest imo.. but theres other ways too.. like using the IPointer Handler stuff

languid spire
rocky canyon
#

i think he has 1 big image.. with multiple parts he wants to click on

#

like.. normally id recommend chopping it up into seperate sprites

#

w/ the sprite slicing tool thing

languid spire
#

well thats no problem.
Set the alpha of pixels of the image that can be clicked to 1
Set the alpha of the pixels that cannot be clicked to 0.9f
Set the alphahitThreshold to 0.95f

rocky canyon
#

@west sonnet can you share a screenshot of the image/s ur working with?

#

so we have some more contex

loud mango
languid spire
rocky canyon
#

but am i missing something? wouldn't setting the alpha make it sorta transparent where u cannot click..

languid spire
#

with an alpha of 0.9 you dont see the difference

rocky canyon
#

ahh, okay. 👍

languid spire
wintry quarry
#

and see which way the blue arrow is pointing

loud mango
#

it goes the opposite of the model is

wintry quarry
#

YOu need to fix your model

languid spire
#

So reimport your model with the correct transforms

loud mango
#

okei

molten dock
#

hi

#

how do i have random.range return a different number every time the if statement its in is called

#

right now it does the same number over and over

wintry quarry
#

if you're seeing the same number you're doing something wrong

#

shwo your code?

molten dock
#

oh oaky

#

if (distanceToPlayer <= meleeRange)
{
int randomAttack = Random.Range(1, 2);

wintry quarry
#

because the upper bound is excluded in the integer version

molten dock
#

i thought it would do one and two oops

molten dock
#

so 0,2 is correct

wintry quarry
molten dock
#

swag

#

thank you

icy junco
#

when is it best to go from capsule to real charchter, in the beginning of your game or more at the ebd

#

end

wintry quarry
#

depends on your game and what's important in your game

molten dock
#

i like having my game look nice from the start even tho its a bad idea

#

cause u will have new ideas which will require new art

rocky canyon
#

you can work faster w/o fancy graphics

rich adder
#

Its good to work on the art/making look nice when taking break from doing lots of the coding

molten dock
#

is it more or less code efficient to start variables mid script

molten dock
wintry quarry
#

local variables are a good idea

#

Generally a variable should have the minimum scope required to do its job

molten dock
#

that is in the middle of the script and usually my variables are b4 the start

rich adder
#

in the methods?

wintry quarry
molten dock
#

i understand

hollow dawn
#

in this line of code how can I change how high I can jump? using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerMovement : MonoBehaviour
{
public CharacterController controller;

public float speed = 12f;
public float gravity = -9.81f;
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
public float jumpHeight = 3f;

Vector3 velocity;
bool isGrounded;

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

    isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask); 

    if(isGrounded && velocity.y < 0)
    {
        velocity.y = -2f;
            
           
    }

    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");

    Vector3 move = transform.right * x + transform.forward * z;

    controller.Move(move * speed * Time.deltaTime);

    if(Input.GetButtonDown("Jump") && isGrounded)
    {
        velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
    }

    velocity.y += gravity * Time.deltaTime;

    controller.Move(velocity * Time.deltaTime);


}

}

west sonnet
#

This is what I've got going on

#

The hand is basically the cursor, and it should be able to click on the shotgun, but nothing happens