#💻┃code-beginner

1 messages · Page 205 of 1

rich adder
#

basically a moveTowards a target

#

should be fairly simple

thorn kiln
#

I always thought it was really cool but poorly implemented in the games

rich adder
#

get the nearest target or whichever way to determine the target

wind raptor
#

I understand. Not trying to obfuscate, and it may not be worth the effort to explain the wider context when I'm almost certainly overthinking any performance issues.

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

public class IndicatorScript : MonoBehaviour
{
    public Material indicatorOFF;
    public Material indicatorON;
    private bool isIndicatorOn = false;
    private MeshRenderer indicatorRenderer;
    private Coroutine indRoutine;
    // Start is called before the first frame update
    void Start()
    {
        indicatorRenderer = GetComponent<MeshRenderer>();
        if (indicatorRenderer == null)
        {
            Debug.LogError("MeshRenderer component not found on GameObject.");
        }
    }

    // Update is called once per frame
    void Update()
    
    {
        if(Input.GetButtonDown("RIndicator")&&isIndicatorOn==false)
        {
            isIndicatorOn = true;
            Debug.Log("Start");
            if(isIndicatorOn){
                indRoutine = StartCoroutine(IndicatorCoroutine());
            }
        }
    }

    private IEnumerator IndicatorCoroutine()
        {
            while (isIndicatorOn)
            {
                indicatorRenderer.material = indicatorON;
                yield return new WaitForSeconds(0.5f);
                indicatorRenderer.material = indicatorOFF;
                yield return new WaitForSeconds(0.5f);
                Debug.Log(isIndicatorOn);
                if(Input.GetButtonDown("RIndicator") && isIndicatorOn==true)
            {
                Debug.Log("indicatoroff");
                isIndicatorOn = false;
                indicatorRenderer.material = indicatorOFF;
                StopCoroutine(indRoutine); // Turn off the indicator immediately
            }
            }
        }
}

Here i want to turn on my vehicle's indicator light on when i press the RIndicator button and off when i press it again. However it never seems to enter the if condition in the while loop, i check using the Debug.Log, why does it not enter the if condition, my indicator does not turn off

summer stump
eternal needle
#

The actual dash would be easy, the hardest part is gonna be implementing this alongside your movement code. Likely would be easiest as a state machine

teal viper
supple needle
summer stump
#

Just remove the isIndicatorOn condition from update

#

And have it either start or stop the coroutine inside that condition depending on its current state

#

Coroutine routine = StartCoroutine()

#

You can store the instance to the currently running coroutine in order to stop it easily

teal viper
#

I'm not sure that's the problem.

supple needle
#

Ok, but i want it to stop when i press the key again right? So what if it just restarts the coroutine?

summer stump
#

And do a toggle like this isIndicatorOn = !isIndicatorOn

summer stump
teal viper
summer stump
#

Imo, the coroutine should only handle blinking

teal viper
#

Yeah, refactoring the coroutine might be a good idea.

rich adder
#

yeah you'd need some precise skill to call that button down there

supple needle
#

Is that like a one frame thing?

summer stump
#

Oh, for the coroutine to catch the update? Yeah

#

One frame every second

supple needle
#

I see, so i get rid of the condition to check for the button from the coroutine and throw it into the update condition

summer stump
supple needle
#

Just dont put it in the coroutine?

rich adder
summer stump
#
    // Update is called once per frame
    void Update()
    
    {
        if(Input.GetButtonDown("RIndicator"))
        {
            isIndicatorOn = !isIndicatorOn;
            Debug.Log("Start");
            if(isIndicatorOn){
                indRoutine = StartCoroutine(IndicatorCoroutine());
            }
             else StopCoroutind(indRoutine);
        }
    }

    private IEnumerator IndicatorCoroutine()
        {
            while (isIndicatorOn)
            {
                indicatorRenderer.material = indicatorON;
                yield return new WaitForSeconds(0.5f);
                indicatorRenderer.material = indicatorOFF;
                yield return new WaitForSeconds(0.5f);
                Debug.Log(isIndicatorOn);
            }
        }
}
#

Rough code cause I'm on my phone

#

The check inside update needs to have an internal if to turn on or off the coroutine

supple needle
summer stump
#

Phone coding just sucks haha

supple needle
frigid sequoia
#

Can I make a value show in the inspector but be inmodifiable? Cause I would assume is just tag it as [Read Only] but it is not letting me

rich adder
#

otherwise you can inspect private values with Debug mode in inspector

frigid sequoia
rich adder
supple needle
frigid sequoia
#

Thxs 😄

rich adder
frigid sequoia
#

Ok, so I have literally done anything today other than refactor code and references; probably I would still be missing some parts, tomorrow I will probably yet find several null reference exceptions aaaaand my internet just run out for the third time... But still I think today I learnt a lot more than other days where I did tangible stuff, so thank you for that guys 😄

rich adder
cobalt creek
#

so someone other day rec'd me to use cooldown, so i made this script

// Update is called once per frame
    void Update()
    {
        if(comp.cooldown > 0)
        {
            comp.cooldown--;
        }
        //Debug.Log(comp.cooldown);
    }
    
    public void refreshServerList()
    {
        //delay
        if(comp.cooldown == 0)
        {
            comp.cooldown = 1000;
        }
        else if(comp.cooldown > 0)
        {
            return;
        }
        //...

is this ok or is there better option?

rich adder
cobalt creek
#

ok

rich adder
#

has good example of doing a small timer/cooldown

#

You can use Coroutine too

gentle marsh
#

Anyone got a good tutorial of how to make vr boxing game?

rich adder
cobalt creek
#

thank

gentle marsh
#

do you know any way to get started

rich adder
#

doing boxing should be easy once you figure out how to even move hands, the rest is easy collider work

summer stump
#

But you just decrement a value every frame
Which means it will be faster and slower on different computers
DEFINITELY not how you want to do it

cobalt creek
summer stump
cobalt creek
#

int sorry

summer stump
#

Gotcha

rich adder
#

int for cooldown ?

summer stump
#

yeah, then a == comparison is fine
(Ignoring that doing a timer like this is bad)

rich adder
#

but yeah I assumed it was float lol

cobalt creek
#

i consider float tho, maybe use (a-b)< tolerance

#

instead of ==

rich adder
#

no need

cobalt creek
#

thank you

rich adder
#

but yeah you should use Time.deltaTime for something like that

summer stump
#
void Update()
{
    if(comp.cooldown > 0)
    {
        comp.cooldown -= Time.deltaTime;
    }
    //Debug.Log(comp.cooldown);
}

public void refreshServerList()
{
    //delay
    if(Mathf.Approximately(comp.cooldown, 0))
    {
        comp.cooldown = cooldownTime;
    }
    else if(comp.cooldown > 0)
    {
        return;
    }
    //...
#

just slight changes as discussed so you can see

cobalt creek
#

thank

summer stump
#

But I would have the timer setting in update, and just call refreshServerList one time when the timer goes off (without even referencing the timer at all in that method)

#

Nav put an example link above

#

Oh, that was to Time.time, which is another way to do it

foggy lark
#

How do i fix this ?

rich adder
eternal falconBOT
#
Visual Studio guide

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

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

quaint terrace
#

i just learned about 'static' and i dont quite understand it but from what i am reading i can remove:

    public ImageDatabase imageDatabase;
    public ItemStorage itemStorage;
    public JobManager jobManager;``` 
and just use JobManager.DoThis(); if the script in JobManager is static?
rich adder
#

ie non-gameobjects etc

#

but yes when you make the class static you are using the class directly

#

static is also very useful for making a specific instance static

#

or just a method, or extension methods

quaint terrace
#

thank you for helping, now i will read up on what a non-gameobject is and what an instance is

rich adder
#

MonoBehaviour basically

quaint terrace
#

oh i use MonoBehaviour. so if its a scriptable object it can be static?

rich adder
#

and it kinda works like a static anyway

summer stump
#

you probably don't want to make the class itself static most of the time. You'd want a static accessor (like the singleton pattern I linked above).

The cases where you DO want a static class are usually for "Extension Methods"
You don't want them to store state, you want to pass in data, let those extension methods transform it in some way, and return it. Like the c# Math class (not unity Mathf though, funny enough, which is a struct)

If you want to access state and variables, I would go with a singleton

#

but static class would be best like this:
public static class MyClass { }
It inherits from nothing

rich adder
#

or classes that just perform specific tasks

#

Debug.Log is a good example of static function but its not the class thats static

quaint terrace
summer stump
#

While yes, I feel like this would make more sense as a singleton, that way you can modify them in the inspector

rich adder
#

they would also need to be static

#

though you could make all those floats just a struct

#

and make that field itself static

#

ie you cannot use non-static with static

quaint terrace
#

ok, so i learned something i dont currently have a use for, but its good to use for other things.

summer stump
#

Hahaha, that is fair. It's always good to learn!

quaint terrace
#

yea its fine. I was just on Codewars and it wouldnt accept my code so i looked up the solutions and everyone was using static and i couldnt understand why. my game doesnt or cant use static so thats probably why i never ran into it.

foggy lark
rich adder
foggy lark
#

yessir

rich adder
#

nice!

foggy lark
#

fixed but is there a way for me to see them in different colors for each one of them?

#

like if is pink

rich adder
#

ur missing quite the colors

foggy lark
#

i mean it works on unity

rich adder
#

but are you getting code completion ?

#

screenshot your VS editor fully

foggy lark
rich adder
#

yea not configured

#

this should say Assembly-CSharp

foggy lark
#

how do i configure them

rich adder
summer stump
#

If you did all the steps in that guide, you may just need to click Regenerate Project Files in the External Tools menu

rich adder
#

click Regen Project Files. make sure vs is closed, reopen script from unity

foggy lark
#

still no colors

rich adder
#

screenshot the Solution Explorer in VS

#

even though regen project files should do , might need to manually right click the solution and do Reload with Dependenicies

#

or w/e is called

foggy lark
#

umm where is solution explorer

rich adder
#

under View

#

or ctrl alt L

summer stump
foggy lark
rich adder
#

yeah right click and rebuild

#

reload?

#

forgot which

foggy lark
rich adder
#

[ToolTip("HelloWorld")]
or you mean [Header("Hello World")]

rich adder
foggy lark
#

reload project

#

theres also install missing features

rich adder
foggy lark
rich adder
#

nope

#

you can either put it above or side by side with ,

rich adder
# foggy lark

yeah that usually happens when you dont have the Unity Workload

foggy lark
#

oh mb when i first downloaded VS i was learing coding and wasnt planning on downloading unity, etc

quaint terrace
foggy lark
#

so this is gonna fix everything ?

rich adder
quaint terrace
#

maybe on my next game I'll choose a "better" IDE.

foggy lark
#

thx @rich adder

quaint terrace
#

its beautiful

summer stump
#

Oh my god, it wasn't a horrific distasteful joke

rich adder
#

also thanks for burning my retinas

quaint terrace
# rich adder WHY

I never had a teacher, im self taught. well ChatGPT has been helping me learn for 1 year next week.

rich adder
#

gpt has taught you wrong

#

why do you have a forach loop outside a function

#

and if its inside a function , why do you have local functions..

summer stump
#

Are you trying to upset us?

quaint terrace
#

its in clearSave, my tabs are wrong

summer stump
#

GPT is the worst

rich adder
#

please use a real IDE

summer stump
polar acorn
rich adder
quaint terrace
cobalt creek
#

while i like np++ i use vscode more now

twin ibex
#

Hi ...

summer stump
twin ibex
#

i have a problem

cobalt creek
#

what u problem, just say directly the problem

quaint terrace
twin ibex
#

I codded a top down enemy chasing Ai
its working but the enemy is not going directly to the player

eternal falconBOT
twin ibex
# summer stump !code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AIchase : MonoBehaviour
{

    public GameObject Player;
    public float speed;

    private float distance;
                    
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        distance = Vector2.Distance(transform.position, Player.transform.position);
        Vector2 direction = Player.transform.position - transform.position;
        direction.Normalize();
        float angel = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
      
        
            transform.position = Vector2.MoveTowards(this.transform.position, Player.transform.position, speed * Time.deltaTime);
            transform.rotation = Quaternion.Euler(Vector3.forward * angel);
       
    }

}

#

Simple one

summer stump
#

Why use the Atan2?

dire tartan
#

hey if i want to check the velocity of an object is the only way to store it as a vector3?

#

or can i do it as a float

rich adder
twin ibex
summer stump
#

But you aren't moving towards the player.... sooooooo IS it like that?

twin ibex
#

what ??

summer stump
#

Yeah, I guess the issue is not the rotation is it

#

Can you explain the issue better please?

twin ibex
#

its not an error

#

see

summer stump
#

Who said error?

twin ibex
#

no 1

#

i scaled the y by 2 to check if its going directly to the player

#

but its not

summer stump
#

The player is the circle?

twin ibex
#

yes

summer stump
#

Thennn... looks like the rotation IS the issue, and I think it's because Atan2 is used incorrectly

#

Try just using RotateTowards, right?

#

To clarify, your issue is that the triangle is pointing the wrong way?

#

It COULD also be the pivot point

twin ibex
#

what should i do

summer stump
#

Try just using rotatetowards

twin ibex
#

instad of what

#

oh

crude matrix
tepid summit
#

dont use a screenshot

#

copy paste it

#

with 3 of these` on bioth ends

#

change update to fixedupdate

crude matrix
#

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

public class PlayerController : MonoBehaviour
{
public float speed = 5.0f;

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

// Update is called once per frame
void Update()
{
    // We'll move the vehicle forward
    transform.Translate(Vector3.forward * Time.deltaTime * speed);
}

}

tepid summit
#

change update to fixed update

#

!code

eternal falconBOT
crude matrix
#

okay

crude matrix
tepid summit
#

which is?

crude matrix
#

too many of them, I think I didn't do the right thing, i'm really new at this

tepid summit
#

what did you change

crude matrix
#

void Update to void Fixed Update

tepid summit
#

no space

#

fixedupdate

#

like that

crude matrix
#

perfect

tepid summit
#

wdym

crude matrix
#

Now it doesn't give me error

tepid summit
#

ok

crude matrix
#

And now, how can I fix the car movement?

cosmic mural
#

i followed a tutorial for this sokoban top down 2d game

#

what is the purpose of the sqr magnitude?

#

if its afte a normalise is it not always just 1

keen dew
#

If there's no input it's 0

golden obsidian
#

it's to check if there are any input

eternal needle
# cosmic mural if its afte a normalise is it not always just 1

it doesnt make a whole lot of sense. Most beginner tutorials really are not good, and you are seeing that here.
Checking for a square magnitude of 0.5 means they are checking for a magnitude of sqrt(0.5) which is like 0.7071. This part has no specific reasoning because the magnitude will be 1 if it has input.

#

Even if they did not normalize it, they are using GetAxisRaw so the magnitude would be 1 at minimum if there was input

sullen rock
#

Hey! One of the tasks in my project is to "paint" over an area, I have that logic figured out. My issue is with figuring out how to check if the task is complete - my colelague wrote a piece of code that creates a 2D array of bools with the size of the target texture and checks when he paints each pixel, but that feels... weird, could anyone suggest a better path to take?

night mural
sullen rock
#

it doesnt actually loop through them - it uses a counter and textureCoords

night mural
#

yeah i was just thinking that didn't actually make sense

#

the reason you'd do this 'as they paint' is becaue that way you never have to loop through them

#

if you wanted to do the shader thing it would make more sense to not track anything as they paint and just process the whole image in a shader to look for pixels that are the 'unpainted' color or whatever

#

which would probably save you some memory and might be worth it on large images?

#

but adds a lot of technical complexity to what's going on

night mural
#

but it's often nice to be able to have info about which pixels are unpainted, not just how many, both for debugging and so you can tell the player if you need to

turbid robin
#

I am making an AR app, is it possible to make a small menu that starts on the start of the app?

#

Menu with 4 button, each button take me to a different ar experience

#

Is it possible?

languid spire
long furnace
#

hello guys, i have an issue i will love it if u can help, i want to get a script with "FindObjectOfType" however its not very good for the performance so is it better to use "FindGameObjectWithTag" then use "GetComponent" to the refrenced GameObject or not? i hope u can help and thanks!

tepid summit
#

would that not do the same thing

languid spire
north kiln
#

@long furnace don't cross-post. I've removed your other questions

#

If you're wondering about their differences in performance, profile it.

long furnace
languid spire
long furnace
north kiln
long furnace
rare basin
#

what's the difference between doing,

public Action OnUnitDie;

and

public event Action OnUnitDie;

is it just for better IDE suggestions?

modest dust
#

An event can be only invoked from within the struct/class which declared/derived it

timber tide
#

event and delegates

rare basin
#

i can invoke that event in other classes just fine

modest dust
timber tide
#

action is just a predefined delegate with a void return

rare basin
#

okay yea i cannot

#

I have noticed that without event keyword i cannot do some kind of missclick, like I cannot do

 LoadingManager.Instance.OnSceneLoaded = null;
#

but when i remove the event keywoard from public Action OnSceneLoaded

#

then i can do that just fine

#

possibly missclick and write = instead of +=

#

so i guess it's better to add that event keyword for more security?

rich adder
#

yes you cannot assign it from outside class that declared it with event keyword

#

only += and -=

rare basin
#

okay that's cool then, imma use it for more security

#

thanks

timber tide
#

yeah, I don't really use delegates outside of events, unless I'm binding methods to some identifier like through a dictionary.

#

I guess I do pass around interfaces sometimes with method implementations to substitute some of that functionality instead.

rare basin
#

yea that makes sense

mortal bridge
#

I wonder if there is a way you can modify c# scripts in unity to act more like how python does no ; no {}

charred spoke
#

No

#

Well…you could with some codegen but that would be more work than just getting used to ; and {}

jovial sandal
#

!code

eternal falconBOT
mortal bridge
mortal bridge
#

Im already used to it but I dont like it

timber tide
#

python so ugly though, why would you want to make an actual project with its syntax

charred spoke
#

Hero you go, but you are simply going to make your workflow much harder for zero gain

timber tide
#

single scripts ok, but trying to figure out what I was doing with it usually requires me writing double the comments ;)

mortal bridge
teal viper
#

I can already imagine a lot of pitfalls if they're gonna codegen to add semicolons and braces...😂

charred spoke
#

Have fun 🤣

#

I mean I wouldn’t touch this problem with a twenty foot stick

teal viper
#

I mean, it's basically writing your own language or compiler. I always consider it a task for the smartests in this world.

gaunt ice
#

you can turn any language to given syntax (grammar) by rewrite the parser and tokenizer and ast......but it literally becomes other language....

teal viper
#

Maybe reconsider then

#

There are all kinds of programming languages, gotta accept that fact.

mortal bridge
#

no. My father said even if you are dumb if you are dedicated enough you can do anything

teal viper
#

Aight. Good luck then👍

mortal bridge
#

Thankz. I will share it here once Im done

#

maybe you guys wanna use

teal viper
#

If I'm gonna have to deal with python in C# I'm gonna shoot myself lol

timber tide
#

You can still use python in other ways like level gen and then parsing it in unity

#

I use it to quickly parse documents and export it over for some word game I was making

gaunt ice
#

btw you can use any languages you like if you know inter process communication
serialize everything to be byte stream then deserialize it

timber tide
#

yeah, python has a lot of libraries for AI and pathfinding which I can see being some utility for your project

mortal bridge
timber tide
#

I made pacman in pygame where I'd make the levels using wingdings in worddoc then importing it into my project

teal viper
teal viper
mortal bridge
# teal viper Thankfully C# is neither.

"if you shoot yourself in the leg c# default you will not face any problems because the bullet will be plastic, but if you modify it and try and write hello world your gonna have some serious problems because the bullet will be a nuke then." -albert einstein

#

am I funny?

teal viper
#

Not really

#

I just hope you know that braces and semicolons is not the only difference between C# and python

mortal bridge
#

I know. I used pyhton since I was 13 (Im 20 now)

teal viper
#

Did you use C# though?

mortal bridge
#

ehh mehh. not an expert

#

but I definietly used it. I have 6 completed projects in unity

#

as I said, i will share it here once Im done for free. something useful for community.

rare basin
#

yikes

mortal bridge
#

goodbye.

charred spoke
#

See ya in like 6 months to two years

languid spire
#

"fools rush in where angels fear to tread" - Alexander Pope

foggy lark
#

why i cant see Restart level on Events

#

why discord uploads only 1 photo

charred spoke
#

Because its private no one can see it

foggy lark
#

but the tutorial guy put it in private

charred spoke
#

The tutorial guy is wrong then

foggy lark
#

but it works on his video

earnest atlas
#

you cant call private function

#

outside of class

charred spoke
#

Then it probably got changed to public at some point

#

Watch the tutorial again

earnest atlas
#

The sneaky private switcheru

foggy lark
#

switched to public still cant see it

charred spoke
#

I think somewhere digiholic’s counter is going up by one

earnest atlas
#

Did u save the script?

foggy lark
#

class is also public btw

#

yea

earnest atlas
#

Where are you calling the function?

#

full screenshot

foggy lark
#

ahhh

#

start is private

earnest atlas
#

it doesnt matter

foggy lark
#

but its in the start

earnest atlas
#

what is in the start

foggy lark
#

restartlevel

earnest atlas
#

why the function is inside start?

foggy lark
#

again tutorial guy put it there

earnest atlas
#

its not in the start in your screenshot

foggy lark
#

oh its not yes

#

mb

#

forget that then

charred spoke
#

do you have compile errors ?

foggy lark
#

i do not

#

i found the problem

foggy lark
earnest atlas
#

I know it wasnt the start

foggy lark
#

umm still cant see it tho

earnest atlas
#

rip

foggy lark
#

ill just do other ways of restarting the level ig

earnest atlas
#

where are you trying to call restart function

foggy lark
#

in death animation

earnest atlas
#

I mean object

foggy lark
#

you mean where is the script in ?

earnest atlas
#

yteah

foggy lark
#

Player

queen adder
#

Hello

foggy lark
#

hi

earnest atlas
#

This thing

#

Post it

foggy lark
#

yea its in the player

earnest atlas
#

ENTIRE THING

foggy lark
#

THERES A LOT OF TABS

earnest atlas
#

I mean entire thing where script is seen

foggy lark
earnest atlas
#

where you trying to call restart level

foggy lark
#

in death animation i already told u

earnest atlas
#

Where is that death animation

foggy lark
earnest atlas
#

im pretty sure you cant call function from scripts in animator

foggy lark
#

the thing is other scripts shows up

hexed terrace
#

Is there actually an animation?

foggy lark
#

yes

hexed terrace
#

an odd way to do it tbh, but regardless. When following a tutorial, if it works for them and not you... you've done something wrong/ missed something, go back and rewatch

foggy lark
#

i can see other scripts

foggy lark
hexed terrace
foggy lark
#

yes

hexed terrace
#

re-read the list, closelierly

foggy lark
#

it should be RestartLevel there

hexed terrace
#

no it shoudlnt

languid spire
#

no

hexed terrace
#

RestartLevel is a method, not a script

rare basin
hexed terrace
#

RestartLevel is IN the PlayerLife class

earnest atlas
#

he was trying to call it completly outside

foggy lark
#

OH yes

hexed terrace
#

perhaps, it would be a good idea to learn the very basics of C# ... what a class is, method, the setup of them etc

foggy lark
#

video is 2 years ago older verison of unity maybe thats why?, cuz on video it instantly pops up

rare basin
#

it's hard to help you

#

since you dont understand the given help

foggy lark
hexed terrace
foggy lark
mortal bridge
#

tutorial guys suck at writing good codes

#

dont watch beginner tutorials learning c#

#

they suck

hexed terrace
mortal bridge
#

go to learn unity

rare basin
#

why everyone ask everything in code channels 🤔

hexed terrace
#

laziness, stupidity, lack of care

mortal bridge
worthy merlin
languid spire
mortal bridge
worthy merlin
#

Would a steo by step beginner tutorial be the same? Such as https://youtu.be/XtQMytORBmM?si=Uvo8tOQT5D9_qH8q

🔴 Get bonus content by supporting Game Maker’s Toolkit - https://gamemakerstoolkit.com/support/ 🔴

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

▶ Play video
mortal bridge
#

I hate them so much. they dont teach you fishng they give you fish butthat fish is only one specie. and you cant change the fish later when you try from svratch let alone being able to fish

rare basin
#

most of the unity "TUTORIALS" just teach you bad code

#

with bad architecture

#

that is non extensible

worthy merlin
#

Yeah cause I was like. This so for has helped me the best

rare basin
#

and hard to add new things

#

not-designer friendly

#

and just bad and non-dev friendly to work with with plenty of bad practices

#

does it work? it does, but is it good? most of them are terrible

mortal bridge
#

brain shouldnt be on autopilot

worthy merlin
#

True

mortal bridge
#

Gm is a great guy. since he studied the art of learning hence can make a great tutorial

worthy merlin
rare basin
#

based on many projects done

#

many trials and errors

#

many abandonded projects due to bad architecture

#

then you improve on next project etc

worthy merlin
#

Even going through gms course. I'd see little things like making a boolean return method == true in an if instead of just leaving the method in paraethesis. Shorter and also works

mortal bridge
#

i still do that

#

amd i dont use += *= etc...

#

preferences

worthy merlin
#

Will say C# is gonna teach me to use ; in javascript now

#

I always ignore it

mortal bridge
#

vs underlines it in red not hard to miss

worthy merlin
#

Exactly

mortal bridge
#

just hope that all you write doesnt change colours😂

buoyant knot
#

i used to hate ;
But then I realized using // to make multiline code is so much more obnoxious

#

i have embraced the semicolon

queen adder
#

Was the GameObject.SetActive is delayed for end of frame or immediate?

swift crag
#

It occurs immediately.

cosmic dagger
#

I thought it was at the end of the frame . . .

hazy ember
#

Hello, I’m doing a code where inputs are in update() and physics calculations are in fixedUpdate().
A cooldown mechanic is being added, should it count the elapsed time in update() or fixedUpdate()?

#

Like, should it go along with the inputs or in sync with the physics?

rare basin
#

it depends

swift crag
#

I would keep cooldown timers together with whatever they're a cooldown timer for.

hazy ember
rare basin
#

SetActive() is immediately

wintry quarry
hazy ember
#

Thank you, just realised it’s better that way too because of how inconsistent it’d be with the FPS 😅

swift crag
#

That is not a problem.

#

given that you're already handling user inputs in Update (as you ought to be)

#

I'd probably lean towards handling all cooldowns in Update just for consistency's sake -- especially if I also check the cooldown timer in Update

hazy ember
#

Yeah I am, when I put the CD calculations in update() it feels out of sync with the game’s physics at low fps though

cosmic dagger
rare basin
swift crag
#

i'll have to check now

rare basin
#

SetActive() is 100% immedtiately

#

Destroy() is next frame

languid spire
dense cypress
#

how can I get a variable from one game object and put it into another

languid spire
#

game objects dont have many variables, do you mean components on game objects?

dense cypress
#

yes

#

actually it's a variable in a component in a child

languid spire
#

gameobject1.GetComponent<A>().variable = gameObject2.GetComponent<B>().variable
gameobject1.GetComponent<A>().variable = gameObject2.transform.GetChild(x).GetComponent<B>().variable

mortal bridge
#

thats good

turbid robin
languid spire
eternal falconBOT
#

:teacher: Unity Learn ↗

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

turbid robin
#

i am followung the guide for ar there, but i dont like ti that much tbh

#

isnt ther another guide?

languid spire
#

yt is full of them, mostly crap

dense cypress
mortal bridge
#

thats pretty ez man

turbid robin
dense cypress
languid spire
turbid robin
languid spire
mortal bridge
#

stuck here for minutes

dense cypress
#

damn

mortal bridge
#

go scrrenshot

turbid robin
dense cypress
mortal bridge
turbid robin
mortal bridge
dense cypress
#

no

dense cypress
#

I tried to do it myself but some of the code was from videos

#

so I tried to understand what it does

mortal bridge
# turbid robin google find me youtube

hello i wanna make a game about ...x where you .... and i also wanna make enemies ..... and j wanna make them ...... too do you have guides on that? bro ifur gona make something special better make it yourself

turbid robin
#

make myself something i dont how to make because i dont have aguide

mortal bridge
#

omg

#

its the easiest part

#

i can fjnd many right now

turbid robin
#

you see something that isnt youtube?

rare basin
mortal bridge
#

@dense cypress ill take a look in a sec im not on pc those codes i cant read my phone is bugged cant zoom discord images

languid spire
rare basin
#

well, after the entire Update loop

#

can be interpreted in both ways

#

either end of current frame or start of the next noe

languid spire
#

but there is still a lot of the current frame left at that point

mortal bridge
#

@turbid robin 100 bucks. i do what you want

rare basin
#

okay yea fair enough

rare basin
#

if it's called in Update then it will indeed happen after the current Update loop

#

but if it's called somewhere else, let's say in OnTriggerEnter

#

then it will be destroyed after current frame

cosmic dagger
#

trigger events are processed during the physics loop which occurs before Update . . .

rare basin
#

not related

mortal bridge
#

so I see y rotation

#

but i only see y rotation

dense cypress
#

what

mortal bridge
#

its kind of a riddle. can you find it out

dense cypress
#

the playermovement only wants to rotate on y if that's what you mean

#

because I dont what it to fall over

mortal bridge
#

you need to change something in update

#

or add

dense cypress
#

which script

mortal bridge
#

playerm....

dense cypress
#

wait do I put ``` yRotation = camera.GetComponent<PlayerCamera>().yRotation;

#

yeah I did it works now thanks

mortal bridge
#

why did you put it

dense cypress
#

update

#

before the part where it rotates

mortal bridge
#

how did you know you had to use it 🧐

languid spire
dense cypress
#

It occured to me after you said to put something in update

#

what does yRotation=yRotation do

mortal bridge
#

I hope your not asking chatlgbt

dense cypress
#

I didn't I promise

#

Legit

#

fr

#

no 🧢

mortal bridge
#

thats too complicated for a beginner but anyawy 🤨

dense cypress
#

is it?

languid spire
#

but you are not really understanding any of this are you

dense cypress
#

I am sort of idk

#

but I actually didn't use chatgpt

mortal bridge
#

hmm good legit

dense cypress
#

chatgpt didn't deserve such slander

languid spire
#

you cannot slander a LLM, just the dumbasses who trained it

mortal bridge
#

I will be among first ones to die when AI takes over the world

teal viper
#

That's why ai decided to enslave humanity.

dense cypress
#

anyway now I actually have functional player controller I can actually make game

mortal bridge
#

very good

#

If you keep working like this for 10 years you will be rich dont forget

dense cypress
#

wait how do I increase the gravity on a rigidbody

mortal bridge
#

very ez

#

get pshyics

dense cypress
#

just as default

verbal dome
#

2d or 3d?

dense cypress
#

3d

verbal dome
#

One rigidbody or all?

mortal bridge
dense cypress
verbal dome
#

So search for how to change gravity

mortal bridge
verbal dome
#

If it was 2d you can change it per-rigidbody, but 3d uses a global value

mortal bridge
#

this is a hint

#

do the rest yourself

#

you can actually optimize by Physics.gravity *= changeGravity but thats not how I do it so

spiral narwhal
#

If I have a child of a UI object. How do I get its actual position in the world, not the one relative to its parent? Would that be anchoredPosition?

mortal bridge
#

no

spiral narwhal
#

Gonna elaborate?

spiral narwhal
#

And if it has a rectTransform, transform uses that rectTransform?

#

Because it's a UI item

mortal bridge
#

yea

teal viper
mortal bridge
#

I have a very good opinion. we add google to this server and make googling for 1 minute mandatory before asking quetsions

spiral narwhal
#

Just like not responding with Noto a How? question should be mandatory?

mortal bridge
#

I responded to Would that be anchoredPosition

spiral narwhal
#

Yes, very helpful indeed

mortal bridge
#

Idk man. maybe try copy pasting your question next time

mild mortar
#

Think I'm being stupid here.
I'm trying to have the health text animated so that if the character takes 5 damage, the text goes from say 100 - 99 - 98... 95

With my current code though, I am giving 5 damage to the player, but the damage received seems to be like 5.something as the health text ends up as 94.9672 or something like that.

Any ideas?

public void ReceiveDamage(float damage)
    {
        StartCoroutine(ReduceHealth(damage));
    }

    private void UpdateText()
    {
        healthText.text = currentHealth.ToString() + "%";
    }

    private IEnumerator ReduceHealth (float damage)
    {
        float damagePerSecond = damage / smoothDuration;
        float timeElapsed = 0f;

        while (timeElapsed < smoothDuration)
        {
            float currentDamage = damagePerSecond * Time.deltaTime;
            currentHealth -= currentDamage;          
            timeElapsed += Time.deltaTime;
        
            // Update health bar where max health is equal to 0.5 fill amount
            healthBar.fillAmount = (currentHealth / maxHealth) / 2;
            if (currentHealth / maxHealth * 100 <= 40)
            {
                healthBar.color = criticalColour;
            }

            UpdateText();

            if (currentHealth <= 0)
            {
                currentHealth = 0;
                UpdateText();
                // Die
            }
            yield return null;
        }
    }
mortal bridge
#

wohoho the great chinese wall

languid spire
#

you can, you need to create scope for each case

mortal bridge
languid spire
#

same as always { }

mortal bridge
#

@mild mortartry rounding some of them

#

I tried. works

rain heart
#

can someone help me with this?

rain heart
mortal bridge
#

hmm I wonder why

#

those lines seem familiar to me

mild mortar
teal viper
rain heart
mild mortar
teal viper
teal viper
#

Or you missed something in the tutorial 🤷‍♂️

mild mortar
mortal bridge
#

weird

#

5 to 3?

#

I may be being stupid too rn

mild mortar
mortal bridge
#

oh

#

you only rounded health?

#

I think I see now

#

do you want my vesrion of the code?

#

It work on my machine 😄

mild mortar
mortal bridge
#

pff my ctrl doesnt work

#

gotta write by hand

mild mortar
rain heart
# rain heart

so can someone help me with this please? i couldnt find anything

halcyon summit
#

Anyone have any experience with changing the colour of shared font materials in code? All my searching so far suggests I should use Material newFontMaterial = textMeshPro.fontSharedMaterial; but newFontMaterial.color = newColour doesn't seem to make any changes.

buoyant knot
#

in edit mode, when selecting the tilemap, the tilemap shows a grid

buoyant knot
#

so idk what the problem is. there is no problem

rain heart
mortal bridge
#

!code

eternal falconBOT
rain heart
#

im talking about game window

buoyant knot
#

and if you enter play mode

rain heart
#

the gap is still there

mortal bridge
buoyant knot
#

are your sprites set to point filter, and no compression

#

they look blurry

#

and are the sprites on a sprite atlas, because i assume they are not

#

and is the actual sprite brought in as 16x16

#

i assume the answer to all these questions is no

rain heart
buoyant knot
#

for reference, when using pixel art, you always need to set point filter, no compression

mortal bridge
#

@mild mortarwait did you fix it?

buoyant knot
#

otherwise your sharp pixels get blurry like a jpeg

mortal bridge
buoyant knot
#

and add the image file to a sprite atlas

mortal bridge
mild mortar
swift crag
#

if you get spam from someone in the server, let a mod know about it

#

otherwise, uh, idk just block

mortal bridge
#

its ez

#

Whats the outcome now?

mortal bridge
#

wait dont try my code

mild mortar
mortal bridge
#

god Im really stupit today

eager spindle
#

good evening
I am using unity 2022.3.8f1, am following a tutorial that uses IMGUI(for debugging purposes). the IMGUI buttons show up in the built version but not in the editor; is there something I need to enable for IMGUI buttons to show up in the editor?

mild mortar
# mortal bridge god Im really stupit today

Seems to be working fine there 🙂

The actually current health still seems to have that thing of being like 89.8216 etc
But the text displays it as 90%. Just gonna hope and assume it's minor enough that there isn't a problem caused from it

swift crag
#

Or are they completely missing?

eager spindle
#

they are completely missing

swift crag
#

Maybe an exception is being thrown

mortal bridge
swift crag
#

Check the player log file.

mortal bridge
#

im a bit high today

eager spindle
#

editor with gizmos on

swift crag
#

oh, I read that backwards!

#

in the built game, not in the editor

eager spindle
mortal bridge
#

oh yeah

#

I see

swift crag
#

note that you don't need Gizmos on to see IMGUI graphics

#

That's the problem.

#

Your game view is zoomed in.

eager spindle
#

ah

#

I didnt see it was zoomed in ty

swift crag
#

np!

swift crag
#

so I had to set the default gui style's fonts on startup

mild mortar
# mortal bridge how? I think I wrote roundtoInt

Yeah the text is rounded, I just meant the behind the scenes actual health isn't rounded, so hoping when calculations and stuff come in, that the player isn't really affected from a build up of those trailing digits

night sparrow
#

is there any way of checking if ray Hit the Object head inside the Player object like the Health component but detect if the Ray hits the Head object instead


    void Fire()
    {
        recoiling = true;
        recovering = false;

        Ray ray = new Ray(camera.transform.position, camera.transform.forward);
        RaycastHit hit;

        if (Physics.Raycast(ray.origin, ray.direction, out hit, 100f))
        {
            Health targetHealth = hit.transform.gameObject.GetComponent<Health>();
            bool isHeadShot = false;

            if (targetHealth != null)
            {

                Debug.Log(hit.transform.name);

                string vfxName = isHeadShot ? hitGoldVFX.name : hitRedVFX.name;
                PhotonNetwork.Instantiate(vfxName, hit.point, Quaternion.identity);

                int damageValue = isHeadShot ? headShotDamage : damage;
                Debug.Log("Damage to be done " + damageValue.ToString());
                hit.transform.gameObject.GetComponent<PhotonView>().RPC("TakeDamage", RpcTarget.All, damageValue);
            }
            else
            {
                PhotonNetwork.Instantiate(hitWhiteVFX.name, hit.point, Quaternion.identity);
            }
        }
    }```
swift crag
#

This tells you the exact collider that you hit.

#

transform can point at either the collider's Transform (if there is no parent Rigidbody) or at the Rigidbody's Transform (if there is one)

#

So, you can do something like this

#
if (hit.collider.TryGetComponent(out Hitbox hitbox)) {
  damage *= hitbox.damageMultiplier;
}
mild mortar
swift crag
#

create a Hitbox component that lives on the same object as the collider

mortal bridge
#

currentHealth = Mathf.Round(currentHealth * 100) / 100 (I think its is 100 yes? but I THought of this before but it may make it less smooth

#

so I didnt

swift crag
night sparrow
swift crag
#
$"{playerHealth:P0}"
#

This is string interpolation

mortal bridge
#

please help him

swift crag
#

$"{0.123:P0}" will produce "12%"

#

$"{0.123:P1}" will produce "12.3%"

#

etc.

#

the general form is {expression:formatinfo}

mild mortar
# mortal bridge please help him

Yeah, I followed along to a tutorial and just want the health to display correctly and also smoothly decrease on the text when damage is taken

swift crag
#

P0 means "percentage with 0 decimal places"

mortal bridge
swift crag
#

That'll display the health percentage properly.

mortal bridge
#

I m not very experienced in this stuff

#

it may accumlate without it

swift crag
#

To make it change smoothly, you'll want to track the displayed health separately from the actual health

#

Assuming these are both percentages already, this will change the displayed health by at most 20% per second:

#
displayedHealth = Mathf.MoveTowards(displayedHealth, health, Time.deltaTime * 0.2f);
#

You can then use string interpolation to turn displayedHealth into a nice percentage

mild mortar
#

I'll try that then quickly, thanks

swift crag
#
healthText.text = $"{displayedHealth:P0}";
#

I believe this will round to the nearest hundredth

#

rather than rounding up or rounding down

mortal bridge
#

damn yeah this makes sense

swift crag
#

so 0.3% health will become 0%

mortal bridge
#

If my mind was in its place I'd definietly recommendthis 100%%

covert glade
#

hello im tryna make a code that destroys the player when the player collides with a spike

#

but instead it destroys the parent and its childs

#

can i make it only destroy the parent?

swift crag
#

you could unparent the camera first

#

I would suggest just making the camera follow the player

mortal bridge
#

@swift cragyou seem experienced in this stuff. do you mind telling me why my code kinda works but not as smooth? I actually know why but I cant get to fix it

swift crag
#

Cinemachine would be ideal.

covert glade
mild mortar
# swift crag so 0.3% health will become 0%

So in the case of my code here, how would you say to implement this best?

public void ReceiveDamage(float damage)
    {
        StartCoroutine(ReduceHealth(damage));
    }

    private void UpdateText()
    {
        healthText.text = currentHealth.ToString() + "%";
    }

    private IEnumerator ReduceHealth (float damage)
    {
        float damagePerSecond = damage / smoothDuration;
        float timeElapsed = 0f;

        while (timeElapsed < smoothDuration)
        {
            float currentDamage = damagePerSecond * Time.deltaTime;
            currentHealth -= currentDamage;          
            timeElapsed += Time.deltaTime;
        
            // Update health bar where max health is equal to 0.5 fill amount
            healthBar.fillAmount = (currentHealth / maxHealth) / 2;
            if (currentHealth / maxHealth * 100 <= 40)
            {
                healthBar.color = criticalColour;
            }

            UpdateText();

            if (currentHealth <= 0)
            {
                currentHealth = 0;
                UpdateText();
                // Die
            }
            yield return null;
        }
    }
swift crag
#

If you don't want to jump into that immediately, you could also just use a Parent Constraint on the camera

#

the Parent Constraint makes an object act like it's parented -- it moves and rotates as its parent moves and rotates

covert glade
#

oh

#

u said it already

mortal bridge
swift crag
#

it's a component!

covert glade
#

didnt see it

swift crag
#

Add a constraint source, drag the player into it, position the camera how you want it, and hit Activate

mild mortar
swift crag
#

imagine this says "Player" :p

swift crag
swift crag
#

Mostly dead is slightly alive!

mild mortar
#

Oh my bad I wrote that poorly

#

I meant in terms of the health text

#

Wouldnt want it to say 0 but still be alive I meant

swift crag
#

Ah, actually, it looks like it just truncates the number.

#

So 0.9% becomes 0%

burnt vapor
#

Then use ceil and use that result

#

Rather than regular rounding

swift crag
#

oh, no, I was right all along (:

#

When precision specifier controls the number of fractional digits in the result string, the result string reflects a number that is rounded to a representable result nearest to the infinitely precise result. If there are two equally near representable results:

burnt vapor
swift crag
#

You'll still need to adjust the number, then

buoyant knot
#

it generally makes more sense for HP to be an int, not a float

swift crag
#

this is a percentage

burnt vapor
#

(use ceil and cast to integer)

buoyant knot
#

it is easier to deal with discrete rounding errors than to deal with float nonsense

swift crag
#
float correctedHealthPercentage = Mathf.Ceil(healthPercentage * 100) / 100;
healthText.text = $"{correctedHealthPercentage:P0}";
buoyant knot
#

then cast the int to a float for display purposes, but the underlying actual value is an int

swift crag
#

like so

verbal dome
#

At a time

mortal bridge
buoyant knot
verbal dome
#

It might fit fot some games tho

burnt vapor
#

Yes, because how is that related

swift crag
#

Using a float means that your minimum damage amount is now...wishy-washy

#

integers have a pleasant concreteness to them

#

you know it'll always behave properly

buoyant knot
#

yeah, you need the very fixed nature lf ints to avoid float weirdness

burnt vapor
#

I can't remember the last time I saw a game handle health as a floating point number

swift crag
#

of course, continuous damage is a lot more annoying to do with ints

#

you have to chunk it up

mild mortar
covert glade
#

how to reference a gameobject like the player in code?

swift crag
#

and slight differences suddenly get really important

buoyant knot
#

i would rather use a big int for resolution, than use a float

verbal dome
burnt vapor
buoyant knot
#

if 100 HP is not enough, try 10,000,000 HP. And use properties to display sensical numbers

mortal bridge
#

guys what about clamp so we may get rid of accumulation problems??

buoyant knot
#

if numbers can get big, you should use a long for HP

burnt vapor
swift crag
mortal bridge
burnt vapor
#

I doubt it

mortal bridge
buoyant knot
#

pokemon gets into issues all the time because they used SHORTS for HP. One of the dumbfuckiest programming mistakes to make in 2022

long furnace
mortal bridge
#

If health goes below 0 due to small value it may accumulate

buoyant knot
#

it can overflow

#

it can underflow

#

don’t use shorts for HP

swift crag
#

Floats fail much more gradually than ints

#

they behave similarly for small numbers and for large numbers, which is a nice property

burnt vapor
#

You just shoot yourself in the foot with it

buoyant knot
#

idfk. there is literally no reason to actively choose to make this small number a short vs long

#

or even a regular int

swift crag
mortal bridge
#

thats right

#

not my point tho

buoyant knot
#

pokemon has a lot of performance issues, but using shorts vs longs for HP is not doing shit, capn

buoyant knot
burnt vapor
buoyant knot
#

where you are storing values actually on the order of 10^200

swift crag
#

floats are great when everything scales up together

#

multiplying 1 by 0.1 is roughly the same as multiplying 1e20 by 1e19

#

but adding 1 and 0.1 is nothing like adding 1e20 and 0.1, and that's where floats are horrible

#

integers have consistent precision when adding a fixed value

mortal bridge
swift crag
#

i would just not allowe currentHealth to ever go negative

shell sorrel
#

its common to clamp it, but why would you round

#

if you want whole numbers use ints

swift crag
#

by not letting your actual health go negative

#

i think the idea is that this is being displayed as as percentage

shell sorrel
#

i keep how things are displayed and how its in data seperated

swift crag
#

but you should just be doing healthPercentage = ((float) health) / maxHealth and then going from there

swift crag
shell sorrel
#

and always found health as int is always better

#

no ambiguous situations

#

but you can show it to the user anyway you want

timber tide
#

I use floats usually just to keep them contained in a single dictionary

mortal bridge
timber tide
#

as far as grouping stats goes

mortal bridge
#

no accumulation problems

buoyant knot
swift crag
#

yes, it's reasonable to clamp your actual health value

verbal dome
#

That doesnt solve accumulation problems

swift crag
#

but this rounded value shouldn't even be remembered

tough lagoon
swift crag
tough lagoon
#

Could use a decimal or something else sure, but in practicality it isn't much if a problem

buoyant knot
#

your HP should be an int, and have a custom setter that automatically makes sure it can’t be negative

tough lagoon
#

Not necessarily, there are lots of times where you may want incremental damage over time that isn't an absolute 1 or 0 though.

buoyant knot
#

my HP is a ClampedReactiveValue<int>, where this is a proxy that automatically clamps an incoming value, and invokes a method when it changes

buoyant knot
#

with property to get a simpler display value

tough lagoon
#

No, I think it's just inventing work tbh

buoyant knot
#

it is not

#

using a float for HP invents work in tracking down bugs from float imprecision

#

don’t deal with any of that shit. use an int backing field

tough lagoon
#

No, that's not a problem in 99.9% of games in practicality

buoyant knot
#

a property takes extremely little effort to make. it is a core part of C#

#

there is no excuse to not use properties

#

and store a robust value that won’t cause headaches

tough lagoon
#

That has nothing to do with using an int vs float

buoyant knot
#

your point was that making a property invents work

tough lagoon
#

That's just a process to it

buoyant knot
#

it does not invent work. it is a part of using the language. the only situation where you want to store HP as a float is cookie clicker/hero clicker, where HP goes between 1 and 10^200

tough lagoon
#

Well, I support you doing what you want. But this to me sounds like trying to solve an edge case you won't see by inventing work to avoid a problem that isn't going to happen in practice.

buoyant knot
#

there is a reason every JRPG in the world uses discrete integer HP

#

because they do not want to deal with float nonsense

#

if you do not see the value, then do whatever. you have been warned

tough lagoon
#

Yes, I don't. 🙂

buoyant knot
#

btw float HP struggles to be 0% and 100%. because floats suck at ==

tough lagoon
#

There are of course times where you need to change to meet an objective. But worrying about the edges of a float on a health bar for a game is (in my opinion not a problem in practice) but it is your call or whomever is making whichever

#

Using an int is fine, using a float is fine, using properties to pretend an int isn't an int, use it if you need it.

buoyant knot
#

you only need to turn an int to a float for display bars or displaying percentages

tough lagoon
#

I'm just back scrolling to make sure a question wasn't overlooked from folks

buoyant knot
#

with int HP, all game logic should use integer HP and integer dmg

tough lagoon
clear laurel
#

Hi #archived-code-general are in an argument and not looking at my message so thought I'd try here before asking in advanced

I'm working on a custom package for my essential starter tools, the sorts that I can use in every project, my problem is that one of these tools needs to be customized per project and that's not easy if it's sitting in the packages directory, is there a way I can have the package place a folder with these specific assets into the assets directory? Similar to installing an exported package maybe?

mortal bridge
#

actually

#

you can take a look at one question

#

if you want to

#

i can reference

tough lagoon
#

But you can write some tooling for the package that you can right click to generate a thing that uses the package ?

mortal bridge
#

@mild mortarhey buddy did you solve the issue?

tough lagoon
#

Without knowing more an interface sounds like a good approach as well

mild mortar
clear laurel
mortal bridge
mortal bridge
mild mortar
# mortal bridge this one

I haven't tried that yet, I'm just caught up on an appointment phonecall atm, so will be looking to try that soon

opaque fox
#

Would anyone know how to get an AI to move in a straight line once it spots the player without changing direction? Right now I have it set to chasing the player normally, any ideas on how to get it to only charge in a straight line?

#

I'm trying to use bools to get it to target the first known position, but I can't get it to work

polar acorn
opaque fox
#

gotcha gotcha

noble summit
#

what is the different between velocity and force

swift crag
#

velocity is the direction you are moving and how fast you're moving

#

force is the direction you are pushing and how hard you're pushing

#

Force, applied over time, steadily increases your velocity

#

Gravity is a common source of force.

verbal dome
#

AddForce really just adds to the velocity

swift crag
#

A force of 10 newtons accelerates a 1kg object by 10m/s per second

#

or 10 m/s^2 !

swift crag
#

Gravity's force is proportional to your mass

#

So you can just express gravity as an acceleration, directly

#

if you double your mass you double the force, and it's a wash

#
rigidbody.AddForce(-9.8f * Vector3.down, ForceMode.Acceleration);
brazen canyon
#

Guys help
How to uniformly scale a GO ??

polar acorn
gaunt ice
#

by scaling it with same values across three different axes

brazen canyon
#

I'm having this trouble

#

My gun looks so weird

swift crag
#

I presume it's parented to something that is not uniformly scaled.

#

If a parent is non-uniformly scaled, then children will get skewed as they rotate

brazen canyon
swift crag
#

In this case, I would suggest rearranging your player slightly

#
  • Player
    • Visual <-- non-uniformly scaled; has the mesh renderer
    • Camera
    • Gun Holder
      • Gun
#

(or just parent the gun to the camera)

#

This way, the weapon is not parented to a non-uniformly scaled object, and everything's happy

swift crag
frigid sequoia
#

Have you tried changing the camera fov?

swift crag
#

that thing looks scrungled

#

to use the technical term

polar acorn
swift crag
#

A super-wide FOV would definitely cause its own distortion

#

And without that scene view, I'd be tempted to say it is just because the FOV is wide and the gun is close

frigid sequoia
#

I mean, it seems that it looks fine in the editor isn't it?

swift crag
#

pistols aren't supposed to be melted

polar acorn
frigid sequoia
#

How does the model of the gun looks normally?

brazen canyon
swift crag
#

Each item in that list is a game object

#

So the hierarchy should be:

#

Player: Has the "player" component on it

#

It has two children

#

Visual: Has the MeshRenderer. Can be scaled however you want.

#

Camera: Is the camera. Has the gun as a child.

#

Only "Visual" is non-uniformly scaled

#

Everything else should just be [1, 1, 1]

#

(which is both uniformly scaled and the default scale)

polar acorn
earnest atlas
#

is there a way to make a gun look at something?

Lookat rotates entire object I want to make sure its base is connected.

polar acorn
earnest atlas
#

So same look at

verbal dome
#

Could calculate a direction from the desired pivot point to the look position, the put that into Quaternion.LookRotation

swift crag
#

I want to make sure its base is connected.

As in, you want to make sure it still appears to be held?

#

then yeah, just fix its pivot point

verbal dome
#

I was thinking like keeping the stock shouldered. But maybe im overthinking it

earnest atlas
#

What is pivot point 😄

swift crag
#

Make sure that your scene view is set to "Pivot", not "Center", in the top left

#

The pivot point is then wherever the gizmos appear.

#

If the pivot point is not where the weapon should pivot around, then parent the weapon to an empty object and reposition it

earnest atlas
#

oh

#

I think I understand

midnight sinew
#

How to learn code

earnest atlas
#

with eyes

frigid sequoia
# midnight sinew How to learn code

You choose something simple that you want to do and try to do it, whenever you don't know how to continue, you search online or ask other people

#

And repeat with something a bit more complex each time

summer stump
eternal falconBOT
#

:teacher: Unity Learn ↗

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