#💻┃code-beginner

1 messages · Page 359 of 1

swift crag
#

SV_NORMAL is not defined by Unity's code

#

It's a semantic

#

Semantics can affect how the shader program deals with that input or output

#

a lot of them are more-or-less labels

#

the Learn site has a lot of information about HLSL in general

#

(ShaderLab is the language you use to write Unity shaders)

#

you embed HLSL code into it

stuck palm
#

if i take a vectors magnitude, normalize it, and then multiply the magnitude by the normalized vector, will it result in the original vector?

slender nymph
#

yeah it should, barring any floating point inaccuracies

stuck palm
#

awesome, thanks

stuck palm
vestal adder
#

hi my top down movement script seems to be making me move upwards constantly and i dont know why

#

!code

eternal falconBOT
vestal adder
slender nymph
#

just FYI, line 27 is unnecessary and may cause some weird issues. you've already normalized your input and multiplied it by speed, now you're increasing it by that much (multiplied by deltaTime) which makes no sense

#

i'd also recommend printing your input to make sure that you aren't getting some vertical input from some unexpected source (like a controller of some sort plugged in)

vestal adder
#

that is a really good point cause i plugged in a controller to play animal well earlier

#

i diddnt know it would just automatically work on unity

#

will check

#

yeah its not that

wintry quarry
vestal adder
#

it is commented out but it still moves me up

slender nymph
#

have you printed your input to see whether unity is detecting some input from a source you are not expecting?

vestal adder
#

i did do print moveInput but im thinking you mean something else maybe

slender nymph
#

and what does it print?

#

and also where did you put that log

vestal adder
#

Coordinates

wintry quarry
#

Which ones

vestal adder
#

at the end of update

wintry quarry
#

We want to see the data

vestal adder
#

incase its my rigibody thats wrong

#

ok ill show dat

wintry quarry
#

Ok my guess is you put a Rigidbody on your camera and your player isn't actually going up. Rather your camera is falling down

vestal adder
#

i took the cam off and it still happens

#

this seems too hard to solve in discord mb lol

wintry quarry
#

Wdym you "took the cam off it"

vestal adder
#

took the camera off of the player

#

also no rigibody on it

wintry quarry
#

What makes you think that the player is going up

vestal adder
#

i can see it go up and off the tilemap

wintry quarry
#

Maybe the tilemap is falling down?

#

Does that have a Rigidbody?

wintry quarry
slender nymph
#

change your Update method to this and show what it prints:

public void Update()
{
    moveInput = new Vector2(Input.GetAxisRaw(Horizontal), Input.GetAxisRaw(Vertical));
    var transformedInput = transform.TransformDirection(moveInput.normalized) * speed;
    Debug.Log($"Input: {moveInput}, Transformed: {transformedInput}. Player will move up: {transformedInput.y > 0}. Current Velocity: {rb.velocity}");

    moveInput = transformedInput;
}
vestal adder
#

postion confirms

#

okay

wintry quarry
#

Any other scripts or components attached to the player?

vestal adder
#

no its just that rn

wintry quarry
slender nymph
#

that's not even the log i gave you so idk what you went and changed

vestal adder
#

idk i thought i copypasted

wintry quarry
#

Well you're not inputting anything it seems

#

Or speed is zero

slender nymph
#

the input without the speed multiplication is printed too and it shows 0 so that means no input

vestal adder
#

i did try wasd

wintry quarry
#

Did you focus the game window

keen vine
#

Hi, does anyone happen to know why in the video the sword continues to stay on the right when the mouse is on the left?

slender nymph
#

use mp4 to embed in discord. but also line 69 ... = Quaternion.Euler(0, 360, 0);
think about that for a second

keen vine
slender nymph
#

then the point that it rotates around is not centered on the player

mighty brook
#

Following an old video, it shows Canvas->Text, in my current Unity is shows the Text with (Legacy), is this because its an outdated practice or?

rocky canyon
#

Text Mesh Pro replaces Legacy

mighty brook
#

Okay, that's what I was thinking from how this was set up. Thanks for clarifying :) (Also sorry if this was wrong place to post, I was lurking and didnt pay attention)

rocky canyon
#

and you'll need the using TMPro; using statement in the head

mighty brook
#

That's really helpful, thanks for the heads up, was just about start googling :)

rocky canyon
#

if u hold Control you can snap regardless of local/global

radiant frigate
rocky canyon
#

they make u use global transform.. b/c if it were rotated at a weird angle.. it wont snap diagonally for example

#

i just use ctrl hotkey tho, easier and universal

rocky canyon
#

make sure to test w/ ur scales set to 1 that way it displays properly

radiant frigate
#

okay

rocky canyon
#

not sure why they look that much different hto

rocky canyon
# radiant frigate it isnt the case

ya, i said thats probably not the reason.. but its a good thing to keep in mind.. having it set to 1x will show things truely how they'll look in the build

radiant frigate
#

and also now it looks zoomed in (which makes sense) but what i mean is if its really that bad to have a 0.5x scale?

rocky canyon
#

well its not gonna look that way when u build it

#

it'll be 1x (full size)

radiant frigate
#

if it has 1x then the camera is a bit off to the left

#

even if the script tells it to copy the player pos

rocky canyon
#

then u need to readjust it to work w/ 1x

radiant frigate
#

and how did it change? i didnt touch anything related to scale i think

#

does changing the camera size affect it?

rocky canyon
#

check in the Render settings of the particle

#

not sure what you'd be looking for but someone in the Unity forums mentioned to check out the settings there if the particle looks differently like htat

rocky canyon
radiant frigate
#

im going to just keep it like that to be safe

rocky canyon
#

i keep mine set to 16:9 and scaled to 1

radiant frigate
#

whenever a rocket launches, for example

#

oh wait i overlooked the ´d in you´d and thought you were asking me what i was looking for as in which effect

#

lol

#

mb

rocky canyon
#

any particle can do that..

#

just make sure to use World Spaces

#

and you can also use the Rate over Distance.. in the Emission section.. so that it only spawns particles when its moving

radiant frigate
radiant frigate
radiant frigate
#

ty!

#

i dont know why but not it resizes and gets more "centered"

rocky canyon
#

ur canvas isn't set correctly

radiant frigate
rocky canyon
#

make sure its set to Scale with Screen Size.. and the reference resolution matches ur monitors resolution

radiant frigate
#

okay thats an additional component right?

#

not a base one

rocky canyon
#

you can see here how my cog gets off when i resize... thats b/c its anchored to the center of the screen...
once i anchored it to the bottom-left.. it stayed there no matter how i resized the window

rocky canyon
radiant frigate
#

it wasnt but i added it manually and went on to config to check my resolution

#

again ty for the help i dont know what i will do without you lol, it would have stressed me out a lot

#

thats what i love and hate about unity, everything has a premade system already

rocky canyon
#

lol, no worries.. User Interface work can get complicated for new comers

radiant frigate
#

for what i´ve heard ui is the worst aspect and the one who people dislikes the most

rocky canyon
#

its easy to make crappy UI

#

people dislike it.. b/c its hard (takes some work) to make UI that looks and feels good

radiant frigate
#

as seen in previous examples of non related matters, my UI is crappy as much as it can be lol

rocky canyon
#

once you get familiar with the tools tho its not too bad

radiant frigate
#

but i dont want to bother over it to much now

rocky canyon
#

i been working on this UI for a while now.. finally got it looking/feeling pretty good

radiant frigate
#

and has nice colors and size

rocky canyon
#

good good

#

wanted pastel colors.. but not like easter colors

radiant frigate
#

im really bad at colors, i dont know what pastel colors are

#

a friend tried to explain it to me like 4 days ago but i cant get my head around it

rocky canyon
#

these are pastels

radiant frigate
#

those seem like normal colors to me to be honest

#

maybe they are a bit more "sad-like"

rocky canyon
#

heres a website i use pretty often to get good color schemes

#

you can just play around with it.. and it outputs complementary colors automatically..

#

(you'll always get colors that work well together)

radiant frigate
#

i use that one

rocky canyon
#

ya, thats a good one too

#

i like that one b/c i think you can upload a picture or image

#

and it'll spit out a color pallete for it

radiant frigate
#

yes

#

that feature is amazing

#

and even more if its for a small game like mine and i want to take heavy inspiration on other games

rocky canyon
#

nothing wrong with that 👍

radiant frigate
#

the game im doing is a copy of the game from a friend and im very proud of how its turning out

rocky canyon
radiant frigate
#

oh

rocky canyon
#

but yea pretty much, gentle, subtle, soothing, etc

cosmic dagger
#

pastel is like faded colors . . .

radiant frigate
#

yeah like mixed with water

#

i think

#

but in a weird way

rocky canyon
#

sorta yea! lol.. but we've gotten off on a tangent.. any more coding problems u having?

#

did ur particles start working after using world space?

radiant frigate
radiant frigate
#

i even adjusted a bit so they look better

rocky canyon
#

i started thinkin about it.. and i didnt realize before but the example u showd.. the particles that were working right.. were stationary..

radiant frigate
#

do you want to see?

rocky canyon
#

the reason the other ones didn't loook the same b/c they were moving

radiant frigate
rocky canyon
#

lol.. ya, u were moving them upwards in their local space

#

and the clouds were moving upwards as well.. so they were just getting stacked on top of each other i htink

radiant frigate
#

yes

#

i thought about that but i dont remember what conclusion i made for the fact that it wasnt the problem

#

which prolly was wrong lol

#

and now is confirmed to be wrong

rocky canyon
#

im interested.. why did u say thats why u like / hate unity.. b/c of there being a preset system for everything..

#

how is that a bad thing?

radiant frigate
#

because if you dont know it exist it just makes your live a living hell

rocky canyon
#

ahh okay

radiant frigate
#

for example friction and all that in the material for rigidbodys or colliders

rocky canyon
#

oh yea, one thing u should do.. when ur not working on ur project.. is to just open a new project and just spend a few hours clicking thru the menus

radiant frigate
#

i wanted to make something bounce and was doing formulas and like 7 hours later a friend comes by to my house and i wanted to show him, and he said there was a system for that

rocky canyon
#

i did that my first few weeks. and took notes of everything i saw..

radiant frigate
#

and my reaction to that was not very pleasing

rocky canyon
#

it helped for sure when i wanted to look up something

#

i had in the back of my mind certain things that I had seen.. (i may not have understood what they did when i seen them) but when i started looking up how to do certain things.. it would help to have them in the back of my mind

rocky canyon
#

going on 3 years and im still seeing new things i havent seen before 😅

radiant frigate
#

you seem pretty advanced for 3 years imo

rocky canyon
#

lol.. i come from an artist background..

#

i make things look prettier than they actually are 😄

radiant frigate
#

i can see that

rocky canyon
#

the code that runs the stuff is less flashy

radiant frigate
#

the game looks very pleasing

rocky canyon
#

thanks! i been stuck on AI for a while now

radiant frigate
rocky canyon
#

now thats hard to do..

#

to make enemy AI that seem smart and fun to play against

radiant frigate
#

i want to learn procedural generation but thats for maybe 1 year from now on

radiant frigate
rocky canyon
#

nah, u can learn about that stuff pretty early on..

rocky canyon
#

and then i learned about state-machines..

radiant frigate
#

but yeah its a pain in the ***

rocky canyon
#

and im still learning about them

radiant frigate
rocky canyon
#

well some of the logic uses switch statements

radiant frigate
#

i learned about that and holy that was revolutionary

rocky canyon
#

but what i mean is a state machine..

radiant frigate
#

oh

#

seems scary

#

but i should look into that

rocky canyon
#

something like this.. is what im working on now

#

going in and out of states..

radiant frigate
#

whenever im finished with this im starting to develop systems instead of full games, seems better to learn

rocky canyon
#

and when they're allowed to.. and how and so on

rocky canyon
radiant frigate
rocky canyon
#

b/c once u know how things normally work in games.. it helps you code it a certain way that makes sense..

radiant frigate
#

im a statement map nerd lol

rocky canyon
#

instead of writing code for say a week straight.. and then once u realize u need a certain system.. the code u wrote doesnt make any sense

#

so u have to go back and re-write it

radiant frigate
#

saw a gamedev explaining it and thought it was kinda smart

rocky canyon
#

theres (2) choices most people use.. either a Finite State Machine.. or a Behaviour Tree

#

which the Behaviour tree is still outside my skillset

radiant frigate
#

anyway im going to sleep its 4:50 am

rocky canyon
#

see ya 👋

radiant frigate
#

ty for everything!

rocky canyon
#

no problem 🍀

radiant frigate
#

and good luck with your game

rocky canyon
#

u2

radiant frigate
#

visuals look 10/10

misty coral
#

How do I do transform.Rotate(endRotation);

#

equivalent

#

but with Slerp

#

Should I be using Quaternion or Vector3?

rich adder
#

RotateTowards maybe?

#

or Quaternion.Slerp

misty coral
#

I should be using EulerAngles right?

#

Like I dont understand which to use

#

to make the equivalent effect

rich adder
#

" the equivalent effect" of what?

summer stump
rich adder
#

you want smooth , not smooth

misty coral
#

When I use Rotate

rich adder
#

rotate can be done in dozens of ways

misty coral
#

it rotates to a certain position

#

when I use Rotate Towards

#

it doesn't go to that target position, it over or under shoots

#

does Rotate use EulerAngles?

#

I have the mouth open like that

#

but I want that same effect

#

but it to look smooth

misty coral
rich adder
summer stump
misty coral
#

Woops

#

Mb

magic panther
#

Both locking the mouse cursor and exiting the application aren't working. I don't know why

https://hastebin.com/share/ofakepiqak.csharp

rich adder
#

unity needs you to do that

#

also no such thing as exiting application in editor

magic panther
#

by exiting I mean an error log

magic panther
#

alr everything works, my bad

#

thanks

#

wait, no

#

the cursor is locked, I need it to move around but not stop at screen edges

#

how do I do that

magic panther
#

I see, but confined also doesn't work

#

gpt is saying something but half of it aint working

summer stump
#

Standard for gpt notlikethis

magic panther
#

how do I lock the cursor but be able to keep track of it's movement

#

I need to look around in-game

summer stump
magic panther
summer stump
magic panther
#
    private void HandleMouseInput() {
        Vector3 mouseDelta = new Vector3(GetAxis("Mouse X"), 0f, GetAxis("Mouse Y")) - lastMousePosition;
        yTurn = (yTurn + mouseDelta.x * mouseSensitivity) % 360f;
        xTurn = Mathf.Clamp(xTurn - mouseDelta.y * mouseSensitivity, -35f, 35f);
        lastMousePosition = Input.mousePosition;
    }
summer stump
#

new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));

#

Oh yeah, or v3

magic panther
#

input, ok. Which value is 0f?

summer stump
#

Z should be 0. A mouse exists in screenspace which is x and y of course

#

You have y as 0

#

Get rid of lastMousePosition entirely. GetAxis is a delta already

magic panther
#

something's happening, might work

#

alright, it works very nicely

#

thanks a lot mate

#

now to add physics

ember tangle
#

Out of nowhere my project broke and I'm getting an 'unloading broken assembly' error 🤔

ebon bloom
#

!code

eternal falconBOT
misty coral
#

How do I tell from the objects perspective it is hit by a raycast

summer stump
misty coral
#

"get a reference"?

#

how

#

Sorry I should rephrase the question

summer stump
#

GetComponent
Or TryGetComponent

misty coral
summer stump
rich adder
misty coral
summer stump
#

A script

rich adder
#

shouldnt we be the ones asking you that

misty coral
#

huh

rich adder
#

which component do you want

summer stump
#

Exactly what nav said. I don't really even understand the question

misty coral
#

Sry I meant like, if i wanna access methods of the child, what component do I pull out of the raycast hit to access those method

rich adder
#

GetComponentInChildren on the hit collider?

summer stump
#

You should look at the docs for the RaycastHit struct

#

See what properties it has

ember tangle
#

So you want to access methods of the child of the object that the hit collided with?

rich adder
#

if child has no collider then yes you need GetComponentInChildren

misty coral
#

it has a collider

#

but they all share the same "Enemy"

#

tag

rich adder
#

so you access that directly

#

don't use Tags, look for specific script

#

aka component

misty coral
#

but I need them to react differently

summer stump
#
public class ScriptA : MonoBehaviour
{
  public void Update() {
    if (raycast(out RaycastHit hit)
    {
      if (hit.collider.TryGetComponent(out ScriptB b)) {
          b.GotHit();
      }
    }
  }
}
public class ScriptB : MonoBehaviour
{
  public void GotHit() {
    //do whatever
  }
}
#

some pseudo-ish code

rich adder
misty coral
#

Each part

#

of the neck

#

has a script

#

telling it to follow the one infront

#

I want it so

#

when I shoot it

summer stump
rich adder
#

there is no need to like vertical spam each like word

misty coral
#

I want to be able to control each part of the neck when I shoot it, to make it react to being shot

#

so from the gun's raycast

misty coral
#

I am confused on how to individually identify each part of the neck because they have so many similarities

summer stump
misty coral
rich adder
#

you look by component

#

gameobjects are component based

summer stump
rich adder
#

why would it even be necessary to "identify" them as you say

misty coral
rich adder
#

are you dong something different based on bone ?

summer stump
#

Yeah, it is unclear what the identification would do. Do different thing happen depending on which bone is hit

summer stump
misty coral
summer stump
rich adder
misty coral
#

I have never used getComponent in my life, nor formated an if statement in any way like this

misty coral
summer stump
rich adder
# misty coral wym

say you put a script called Bone now you have a component called bone on each , gameobject bone

summer stump
eternal falconBOT
#

:teacher: Unity Learn ↗

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

rich adder
#

yes you need to start from basics

#

Debug.Log , Referencing and GetComponent are the most essential parts you need in unity

misty coral
#

mmmm I have definitly used any of those

misty coral
#

If so I didnt know such things were possible

misty coral
#

Wow

ebon bloom
#

!code

eternal falconBOT
mighty marsh
#

So I have a game with a speedrun timer and I want to make it so that when the level is beat and the timer stops, the time that it stopped at is recorded in a different scene (like a high score scene). I dont even really know where to start though.

gentle stratus
#
 if (target && target.CompareTag("Enemy")) {
     foundTarget = true;
     Vector3 distance = (target.transform.GetChild(0).position - transform.position);
     multiplier = 1.5f;
     rb.AddForce((transform.forward + distance) / 2 * (speed * multiplier));
 }
 else {
     foundTarget = false;
     multiplier = 5;
     rb.AddForce(transform.forward * (speed * multiplier));
 }```
getting this weird bug where if i change the speed from 50 to 100 to 1000, the speed doesnt seem to change, but changing the multiplier does cause a change, why does that happen
eternal needle
gentle stratus
#

okay

gentle stratus
#

well it gets close to 50 but never gets to it

eternal needle
gentle stratus
#

ok

astral falcon
#

Just to test, did you change the rb mass to very low and also maybe use a physics material to avoid drag, so you see if the vector increases?

misty coral
#

idk where to ask this but how do I find my unity project in my files/ how do I export it in a zip

ivory bobcat
west sonnet
#

Hey everyone. How can I make text appear on my screen? This isn't working

astral falcon
languid spire
astral falcon
#

Ah, good point. And enabled is only for the component. Gameobject needs to be used SetActive();

west sonnet
#

Thanks

upper forge
#

im watching a tutorial on an older verrsion of unity which has a 2D vector composite, how would i do this in the 2022.3 version of unity

#

nevermind i got it

chilly dock
uncut shoal
#

I am creating a mesh at runtime, and I want to apply multiple materials to it, how do I do that

eager spindle
#

mesh renderer add material

#

the mesh renderer materials is an array of materials

uncut shoal
#

Yes but how do I set the areas each material is applied to

eager spindle
#

depends on how you setup your model

#

smth about submeshes

#

I'm not sure how you obtained your 3d model so not much I can help you here

uncut shoal
#

I didn't obtain it.

#

I'm generating it at runtime.

eager spindle
#

I'm not sure what your mesh looks like

uncut shoal
#

its a square

#

its basically a grid of vertices.

eager spindle
#

unless you seperate the parts you want to apply materials to into different submeshes, applying different materials don't work

uncut shoal
#

And how do I do that?

sonic dome
#

how do i use vfx as attacks like if i have a vfx for raining arrows how do i make it so that when i click a button it uses that attack where im looking at

eager spindle
uncut shoal
#

I would like it more if I was able to simply draw the entire thing with a single draw call if its possible because its basically a chunk in 2D terrain

#

and there'll be, like, a lot of chunks visible on the screen at all times.

eager spindle
#

you can change the base map of the material applied to the mesh

#

to change the colour etc

#

applying a new material is another issue since that needs a new mesh

#

it's not possible to apply multiple materials to a single mesh that doesn't have submeshes

eager spindle
sonic dome
eager spindle
#

the goal is to instantiate the raining arrows prefab at the place that you click

sonic dome
# eager spindle do you have the raining arrows effect in unity already?
using UnityEngine;

public class RaycastShoot : MonoBehaviour
{
    // Reference to the VFX prefab
    public GameObject vfxPrefab;
    // LayerMask to specify which layers the raycast should hit
    public LayerMask groundLayer;

    void Update()
    {
        // Check if the left mouse button is pressed
        if (Input.GetMouseButtonDown(0))
        {
            ShootRaycast();
        }
    }

    void ShootRaycast()
    {
        // Get the camera's position and forward direction
        Vector3 rayOrigin = Camera.main.transform.position;
        Vector3 rayDirection = Camera.main.transform.forward;

        // Perform the raycast
        RaycastHit hit;
        if (Physics.Raycast(rayOrigin, rayDirection, out hit, Mathf.Infinity, groundLayer))
        {
            // Check if the raycast hit the ground
            if (hit.collider != null)
            {
                // Instantiate the VFX at the hit point
                Instantiate(vfxPrefab, hit.point, Quaternion.identity);
            }
        }
    }
}

this is the apporach just want it to spawn where the raycast hits

uncut shoal
#

use a program to put all the textures in an atlas and set the UVs of each vertice based on the atlas

eager spindle
sonic dome
eager spindle
#

Or what you mean by setting the UVs

uncut shoal
#

Eg dirt

#

grass

eager spindle
#

my guess is that you're making a terrain system of sorts?

uncut shoal
#

yes

eager spindle
#

how unity does it is the plane has all the textures laid on top of each other, and depending on the bitmap the texture of that area will show

uncut shoal
#

I dont understand your explanation?

eager spindle
#

In your case you may need to write a shader that takes in multiple textures that does that

sonic dome
#
    void ShootRaycast()
    {
        // Get the camera's position and forward direction
        Vector3 rayOrigin = Camera.main.transform.position;
        Vector3 rayDirection = Camera.main.transform.forward;

        // Perform the raycast
        RaycastHit hit;
        if (Physics.Raycast(rayOrigin, rayDirection, out hit, Mathf.Infinity, groundLayer))
        {
            // Check if the raycast hit the ground
            if (hit.collider != null)
            {
                // Instantiate the VFX at the hit point
                GameObject obj = Instantiate(vfxPrefab, hit.point, Quaternion.identity);
                Invoke(Remove(obj),5f);
            }
        }
    }

    void Remove(GameObject item){
        Destroy(item);
    }

cant i pass objects in invoke?

eager spindle
#

Nope

#

You can't remove the same gameobject multiple times either

eager spindle
#

What you're trying to do needs a shader and a good amount of work

#

This tutorial walks through creating a terrain shader in Blender and then creating a similar shader Godot that can use the assets you've just created in Blender. In addition to just creating the shaders, there is a focus on creating a bridge from your art assets to your game engine so that you can easily transfer your data from one stage of you...

▶ Play video
#

This is a study on creating terrain shaders in other engines

#

The overall process is that you have terrain layers associated with a terrain. Each terrain layer has a texture.
Your terrain data is a bitmap containing which terrain should be shown at that spot.

sonic dome
#
    [SerializeField]
    private float damage;
    private void OnTriggerStay(Collider other)
    {
        if (other.TryGetComponent<Health>(out Health health))
        {
            StartCoroutine(Pain(health));
        }
    }

    void OnTriggerExit(Collider other){
        StopAllCoroutines();
    }

    IEnumerator Pain(Health health){
        while(true){
            health.DamageTake(damage);
            yield return new WaitForSeconds(1f);
        }
    }

what should be my apporach right now multiple coroutines are starting

eager spindle
#

you can make a Boolean, which becomes true once the ontriggerstay is triggered

#

and it will not start a new coroutine if the Boolean is true

sonic dome
#

let me try

#

yea worked thanks

burnt vapor
sonic dome
#

why m i unable to add it here

#

public Camera cam;

eager spindle
#

type mismatch

#

what is Cam

sonic dome
#

Camera object

eager spindle
#

ok one sec

#

I wanna see what the Camera object has

#

also what are you using it for

sonic dome
#
using UnityEngine;

public class Attack : MonoBehaviour
{
    // Reference to the VFX prefab
    public GameObject vfxPrefab;
    // LayerMask to specify which layers the raycast should hit
    public LayerMask groundLayer;

    public Camera cam;

    void Update()
    {
        // Check if the left mouse button is pressed
        if (Input.GetMouseButtonDown(0))
        {
            ShootRaycast();
        }
    }

    void ShootRaycast()
    {
        // Get the camera's position and forward direction
        Vector3 rayOrigin = cam.transform.position;
        Vector3 rayDirection = cam.transform.forward;

        // Perform the raycast
        RaycastHit hit;
        if (Physics.Raycast(rayOrigin, rayDirection, out hit, Mathf.Infinity, groundLayer))
        {
            // Check if the raycast hit the ground
            if (hit.collider != null)
            {
                // Instantiate the VFX at the hit point
                Instantiate(vfxPrefab, hit.point, Quaternion.identity);
            }
        }
    }
}
eager spindle
#

ok fun tip

#

if you only have one camera on the scene you can use Camera.main

sonic dome
#

yea thats not working

#

i tried that

#

like i set the camera tag to main camera

#

then used Camera.main

eager spindle
#

is Camera.main null?

#

what's wrong with camera main

sonic dome
#

i delted it then made another camera

#

anyways i dont think i want to do it that way cuz i might add multiple cameras for different perspectives

languid spire
#

<@&502884371011731486>

fickle plume
#

!ban 431671627101503498 bot

eternal falconBOT
#

dynoSuccess .zixio was banned.

languid spire
fickle plume
#

Softban is just a kick with purge. Actually turned this one into softban, they had previous activity.

languid spire
#

interesting, thanks for the info

onyx tusk
#

y this code doesn't writing something in the file?c# public StreamWriter writter; public Logger(string name) { writter = File.CreateText(path); } public void log(string text) { writter.WriteLine(text); }
file is creating but it's empty

burnt vapor
#

So creating a new camera also does this

#

Best thing is to just use Camera.Main and avoid fiddling with setting components. If you have multiple camera's you should consider creating a camera manager that returns the current active camera instead

languid spire
sonic dome
burnt vapor
sonic dome
burnt vapor
#

Or use version control and properly track changes 🎉

burnt vapor
sonic dome
sonic dome
burnt vapor
#

Then just remake the camera 🤷‍♂️

languid spire
burnt vapor
#

Or undo, copy the component, redo everything, and paste it

#

But I have no idea how well Unity does redoing content

sonic dome
#

how do i make it again?

#

isnt it as simple as just adding a camera?

#

i mean it would be dumb if we cant get it back if we delete it once

tiny plaza
stuck palm
#

I'm writing my movement code manually, with setting velocities and adding velocities. Problem with adding velocities is that there is no speed cap. How can I add a soft or hard cap to that speed? Problem with this is that I do want the player to go faster than the cap at certain points

fossil drum
tiny plaza
sonic dome
onyx tusk
sonic dome
fossil drum
burnt vapor
languid spire
fossil drum
sonic dome
#

i cant check if it has the tag when the game starts cuz of the error

burnt vapor
sonic dome
#

no i mean

#

it says main does not exist

tiny plaza
sonic dome
#

in the script

sonic dome
fossil drum
# tiny plaza <@138576222572642304> it's in the video

I have seen that, that's not what I mean.
You made code that makes the right of the triangle look at the direction of your cursor.
right is the red arrow in your scene view when you have the triangle selected.
I want to see where that points.

burnt vapor
languid spire
sonic dome
#

notlikethis it did fix it

burnt vapor
#

Right then you do indeed have your own Camera class

#

Don't name stuff the same way unless you use namespaces

sonic dome
#

my bad

fossil drum
tiny plaza
eager spindle
#

do a raycast to the ground; this is where the arrow points to. set transform.forward to position - raycast position

fossil drum
eager spindle
#

if its 2d the more efficient way is to get the vector2 difference between your player and mouse position, and calculate the angle from there

#

transform.forward has saved me many times though

rich adder
#

transform.up = (target-startPos).normalized

errant pilot
#

Guys isnt this how to change a sprites color to 255,255,255,255
color is initialised properly
color = new Color(1, 1, 1, 1);

rich adder
slender nymph
#

also note that changing a sprite renderer's color just changes the tint applied to the sprite

rich adder
#

btw there is a const with Color.white

errant pilot
slender nymph
#

and a perfectly white tint just makes the sprite appear as its own regular color

rich adder
neon marten
#

could someone tell me why the raycast only detects the ground when my height is times 2 the real player height (1.8)

burnt vapor
eternal falconBOT
rich adder
#

you aint gonna see much putting tint to white if it has a sprite

neon marten
#

!code

eternal falconBOT
slender nymph
errant pilot
slender nymph
# errant pilot

at no point are you assigning the sprite renderer's color in any of this code

errant pilot
#

my bad 😭

burnt vapor
#

Could be wrong though.

slender nymph
#

start can be private

rich adder
#

doesnt have to be

slender nymph
#

they likely have more than one

rich adder
#

i keep all my MB method as protected

burnt vapor
#

Ahh, that's the error then

rich adder
neon marten
rich adder
#

you have to print what the ray is hitting , and check if the ground has the correct layer

swift crag
neon marten
#

okay how do i get what the ray hits

rich adder
swift crag
neon marten
#

now i change it to 1.8 it says false

#

dont understand why

rich adder
#

and this tells me what exactly?

neon marten
#

idk man u asked me to do it

rich adder
rich adder
#

and write your Debug.DrawRay correct

#

if it doesnt match the same exact settings as your ray its pointless

neon marten
#

like this?

rich adder
#

also why playerHeight * 0.5f + 0.2f, these magic numbers instead of using actual variable

neon marten
#

in my logic

#

if player height changes

#

its should be half the height + 0.2 for safety

#

cause i can crouch then height changes

rich adder
#

*0.5 is not half the height

neon marten
#

what is it

#

if not half

#

how but for example 1 * 0.5 = 0.5

rich adder
#

yes I know but that is only if its 1.

#

anyway, just draw the ray correct with the same height

neon marten
#

so what u tell me is the when i do playerheight * 0.5 its not half of the player height?

#

okay ill try

rich adder
#

brain aint mathin this mornin

neon marten
#

how does it work again?

rich adder
#

no no

#

to give length in Ray we multiply dir by length

neon marten
#

ok

rich adder
#
Debug.DrawRay(transform.position, Vector3.down * length, Color.red);```
neon marten
#

aight ill run it

rich adder
#

hilarious how you didnt use length inside the raycast itself but whatever lol

neon marten
#

just created that rn

#

its how it looks with playerheight = 1.8

rich adder
#

ok so you see the problem ?

neon marten
#

yeah

#

its not hitting the ground

#

but why

rich adder
#

right

#

because it aint long enough

neon marten
#

it doesnt make sens

#

my player scale is 1.8

#

ray starts from middle

#

1.8 * 0.5 +0.2

#

should be touching the ground

rich adder
#

according to your Collider its hieght its 2

neon marten
#

where did u see

rich adder
#

on the collider?

#

seems your playerHeight doesn't match your collider

neon marten
rich adder
#

var length = capsuleColl.height * 0.5f +2f

neon marten
#

okay ill try

rich adder
#

with scale

neon marten
rich adder
#

cause now your collider will be 2*1.8 factor

rich adder
#

never touch scale of root object

neon marten
#

okay so which scale can i change

#

the child?

#

cause i wanna change height

rich adder
#

I know that

#

i was saying if its not needed to visually see capsule shrink

#

just resize collider size

#

if you need to see capsule shrink for some reason, you would make the graphics only as child and resize that too. Collider should stay on root and resized through component itself not transform

neon marten
#

okay so if i got u right you dont change the parent size only the children

#

yeah i need the capsule to shrink

rich adder
#

its hidden

neon marten
#

cause the raycast was hidden iinside the mesh

rich adder
#

ok but if you shift it as child you should only keep graphics on it, no collider

neon marten
#

made it 0 , 0 , 0

#

at the collider i changed the scale

#

still doesnt detect the ground

#

again it only works when the playerheight at my script is 2 times the scale height

rich adder
#

and show how the ray is drawing now

neon marten
#

wait its confusing

#

ill make it again

rich adder
#

what is even goin on here

neon marten
#

hard to show

#

this is the collider

rich adder
#

your setup should be

-Player + Collider +RB
-- Mesh

neon marten
#

the player obj

rich adder
#

why is collider on child

neon marten
#

followed a video

rich adder
#

the video is wrong

#

put the collider on the player root

neon marten
#

okay

rich adder
#

then do this
if(grounded) Debug.Log(raycasthit.collider.name)

neon marten
#

i moved it

#

now can i change the scale and position?

#

or not

rich adder
#

I want to see something

neon marten
#

how

#

literally first 30 minutes on unity i dont know where everything is

rich adder
#

thats on you for not doing the unity path's essential lol

#

it shows where eeverything is

neon marten
rich adder
#

you still didnt switch it pivot

neon marten
rich adder
#

ok good just pull it out the ground, hit play and show where is the ray in playmode

neon marten
#

okay

magic jungle
#

Hi i created a loading screen but i wanted to know how can i preload every videos of my project to avoid freeze on this loading screen.

neon marten
rich adder
#

you should assign it from collider size

neon marten
#

Thanks u, i didnt notice it there

#

collider height was the problem

rich adder
#

indeed

neon marten
#

i thought the script take the scale not the collider height

rich adder
#

the scaling was making extra big than 2

neon marten
#

yeahhh

#

thank u bro

rich adder
#

np UnityChanThumbsUp

#

if you want to make it more dynamic assign it when it changes, or just use height directly
playerHeight = capsuleColl.height

magic jungle
rich adder
queen adder
#

should be fine, you probably better not put it ina start tho

magic jungle
#

yeah but how can i preload the videos in the streaming assets folder ?

rich adder
#

that I don' know as streaming assets is new to me sorry

magic jungle
sand swift
#

`private void Method_YawTurning(float inputValue)
{
// Convert Deg to Rad -------------------------------------------------------------|
float yawTurnSpeedInRad = yawTorqueSpeed * Mathf.Deg2Rad;

// Account for AngularDrag --------------------------------------------------------|
float dragTorque = sRigidbody.angularDrag * sRigidbody.angularVelocity.y;

// Account for Angular Turning "speed" --------------------------------------------|
float requiredTorqueForce = sRigidbody.inertiaTensor.y * yawTurnSpeedInRad;

// Calculate net torque (desired - drag) ------------------------------------------|
float netTorque = requiredTorqueForce - dragTorque;

// Aplly Torque only if the input is not equal to zero
if (inputValue != 0f)
{
    // Change the vehicle rigidbody ( I do this because I like to personalize where the "rotation takes place" ) so I can create different behaviours to create variety.
    sRigidbody.automaticCenterOfMass = false;
    sRigidbody.centerOfMass = yawCenterOfMassOffset.localPosition;

    // Check if players prefer to play with inverted steering controls
    if(invertSteering == true) { inputValue *= -1f; }
    //else { inputValue *= 1f; }

    // Aplly Torque
    // DESCOBRI UM ERRO : o torque esta em relação ao eixo do mundo e não dele mesmo,
    // SE usar .right ao inves do .up pelo menos...
    sRigidbody.AddRelativeTorque(gameObject.transform.up * netTorque * inputValue, ForceMode.Force);
}
else sRigidbody.automaticCenterOfMass = true;

}`

why does my rigidbody / vehicle seems to be rotating (yaw) relative to world axis?

eternal falconBOT
rich adder
magic jungle
lethal bolt
#

And i found out the problem

#

The "i" in The animator's name WAS NOT CAPITAL

queen adder
#

18 hours debugging is UnityChanOops

queen adder
eternal falconBOT
queen adder
#

oh, animator

rich adder
lethal bolt
#

Ye smlt

#

it works

#

somehow

#

So im not going to touch it no more

rich adder
#

woot

sand swift
slender nymph
#

don't crosspost. and when adding relative torque use Vector3.up not transform.up

#

the torque applied will already be relative to the direction of the body, so by using transform.up in AddRelative torque you're basically converting that to relative to the world

sand swift
#

what really? ok so just write Vector.up. I thought that is what it makes to be always be a world axis

slender nymph
#

you would use transform.up when using AddTorque because that does not convert it to be relative to the body's rotation. AddRelativeTorque does. so by passing transform.up which is the direction of the body relative to the world, you convert that from local space to world space which ends up being on the world's up axis

orchid oyster
#

Hi guys can anyone help me ok so there are two scripts troubleshooting....first one has a method to enable the Hud on screen it And levels are generated here I'm taking index of levels in this script and passing it on to another method in 2nd script that takes a index of level and toggle on the certain panel i have debugged it the value is being transferred successfully .....problem is 2nd script has in on enable method that always runs before code so it always displays 0 value index how can I fix that

orchid oyster
languid spire
orchid oyster
#

I cannot pass the value to on enable but I want the initial value of my variable that is inside the on enable to be equal to index from first script

languid spire
#

indeed, which is why you need to ensure that the Execution Order of your Scripts is the way you expect

orchid oyster
sand swift
#

wonder how the Gemini AI didn't spot that issue

languid spire
keen jackal
sand swift
languid spire
sand swift
languid spire
#

so i didn't say 'Simple Ai's' . I said 'Simple, Ai's'. See the difference?

rich adder
wide wing
languid spire
wide wing
#

100 of ai apps are absolutely free sir

languid spire
#

and they are all of no use to a beginner whatsoever

wide wing
#

We are not living in old age anymore

rich adder
#

most people are dummies anyway so if you base your metric on the majority go for it

languid spire
rich adder
wide wing
languid spire
rich adder
#

is this like the person or do people seriously always use that as their argument

#

"you just dont know how to use it"
"if you knew the correct prompt you'd know how valuable it is"
and more nonsense

wide wing
rich adder
wide wing
languid spire
rich adder
#

that fucking hilarious

#

more novelties to make people feel important

radiant frigate
#

navaroneee!

languid spire
#

as @rich adder said, the crucial point here is 'critical thinking', you do not appear to be doing much of it

radiant frigate
#

hii so much time no see

wide wing
rich adder
#

you changed your pfp 😛

polar acorn
radiant frigate
#

is there any channel for particles or something related to that?

wide wing
radiant frigate
#

ty!

#

hope everything is going great for you

#

you also changed your pfp!

spiral parrot
#

anyone had issues with sprites being transparent for seemingly no reason?

rich adder
#

might do it again lol

#

My ocd itchin

radiant frigate
#

real

polar acorn
languid spire
spiral parrot
#

Alpha source is None, Alpha is Transparency is also unchecked

wide wing
spiral parrot
#

I've set it to RGBA 32bit for true color according to stackover flow but no hope atm

polar acorn
polar acorn
lethal bolt
#

Why does it still want the sign after even tho i have it?

wide wing
rich adder
lethal bolt
#

I just closed and open

#

and it worked

#

thats why i deleted it

rich adder
#

its leaking, like a fishtank

languid spire
polar acorn
rich adder
# lethal bolt

agent.transform.eulerAngles.yagent.transform.rotation
As far as the computer cares, this is how its reading it

#

the line never ended

polar acorn
# lethal bolt

C# doesn't know a line ends until it sees a semicolon. Combined with the fact that multi-line instructions are treated as being on their last line, you end up with the compiler thinking that line 47 is actually

var yRotation = agent.transform.eulerAngles.y agent.transform.rotation = Quaternion.Euler(0, yRotation, 0);
rich adder
#

yeah this ^
the new lines are purely visual on IDE

#

the compiler knows nothing about spacing, indents or any of that

#

just looks for specific characters

wide wing
spiral parrot
polar acorn
polar acorn
spiral parrot
#

Yes sir

polar acorn
# spiral parrot

There you go. The tiny white bar at the bottom is opacity. It's set to half.

spiral parrot
#

You're joking hahahaha

#

Thank you very much man

#

I would never have got that

polar acorn
#

It's hard to notice when the color is white or black, which just so happen to be what the Color field on a panel is set to roughly 99% of the time, but that bar is much more prominent on other colors if you want to see what to look for in the future.

spiral parrot
wide wing
#

Why do I owe explanation to u

#

Who are u

polar acorn
# wide wing Slang for please

Oh good you do know how to spell the word. Probably a good idea to do so in the future. Then maybe you can work on "you" next. You'll get it eventually I'm sure

polar acorn
polar acorn
polar acorn
wide wing
#

I wanna hear how dirty u can get

frosty hound
#

This channel is for beginner coding questions related to Unity

wide wing
#

I haven't said a word to u

frosty hound
#

We don't need to keep this going

wide wing
#

I'm going bye

frosty hound
wide wing
frosty hound
#

You too, see ya.

orchid oyster
#

!code

eternal falconBOT
pseudo ermine
#

Hey there! I know Unity may be slightly overkill for a text written adventure however its the engine I know and would love to create a text written adventure, how could I start this, to allow texts to be displayed and actions to be inputted.

rich adder
#

You could use the InputField I suppose and add a text to a Scrollbar or Layoutgroup

stuck palm
#

I'm writing my movement code manually, with setting velocities and adding velocities. Problem with adding velocities is that there is no speed cap. How can I add a soft or hard cap to that speed? Problem with this is that I do want the player to go faster than the cap at certain points

pseudo ermine
rich adder
#

definitely take a look what Nomnom sent

pseudo ermine
rich adder
#

second link is what you want I believe

pseudo ermine
#

yeah it is, thanks Navarone!

#

also thanks NomNom!

rich adder
#

goodluck 🫡

orchid oyster
#

Hi guys im changing the value of the currentLevelForHUD through another script then this value goes to on enable missions.transform.GetChild(currentLevelForHUD).gameObject.SetActive(isActive); problem is currentLevelForHUD remains zero i have debugged the code the value is successfully being changed but in on enable its just remains zero

formal escarp
#

Hey guys, how can i make enemies walk around the scenario and shoot TOWARDS the player? I know i have to instantiate the bullets and i kinda know how but i dont know how to make it so they do itTOWARDS the player.

#

and i dont know how to make it so the movement makes sense.

tidal basin
#

Am i need the "using System.Numerics;" line? I wasnt using this and it just created by unity.

spark flint
cosmic dagger
formal escarp
tidal basin
cosmic dagger
random cave
#

The lazy way

cosmic dagger
random cave
#

Oh he said 2d?

cosmic dagger
#

Dunno, just smth to address, in case . . .

random cave
#

im sure theres a 2x .lookat

tidal basin
#

Did you recommend using a single script or multiple scripts for a character? Can i passtrough the values between scripts?

lethal bolt
#

Why cant i see the Gizmos+

tidal basin
#

In the video she shows she is using playerInput component but i didnt put it in awake (Because in the docs it was just shows like this and i trust docs more than a youtuber). My code is like this. Is it true?

{
    InputAction moveAction;
    
    void Start()
    {
        moveAction = InputSystem.actions.FindAction("Move");
    }

    void Update()
    {
        Vector2 input = moveAction.ReadValue<Vector2>();
    }
}```
wintry quarry
tall oracle
#

how to make a 3D sphere follow my cursor in game?

wintry quarry
#

So I'm not sure what you're asking

#

or what you mean by "Is it true"?

wintry quarry
tall oracle
wintry quarry
tall oracle
#

yeah but how?

#

idk how to script i am new

wintry quarry
wintry quarry
tidal basin
wintry quarry
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

tall oracle
tall oracle
wintry quarry
tidal basin
wintry quarry
#

there are many ways to use the input system

#

use whichever way you are comfortable with

#

there is no "should"

tidal basin
#

Oh okay I understand, thanks for you help!

outer coral
#

Is there an easy way to get a persistent ID for objects to save data that stays the same between runtimes/quits or would I have to make the class myself?

wintry quarry
#

A typical approach is generating and serializing a GUID

outer coral
tall oracle
wintry quarry
#

That's why I said you need to start with the basics

tall oracle
#

what's the basics?

wintry quarry
tall oracle
#

ty

outer coral
wintry quarry
outer coral
#

ah ok gotcha

eager spindle
#

doesn't guid change every editor startup?

wintry quarry
#

serialized fields do not change on editor startup

tough trench
#

I am trying to change the speed of the Instantiated bullet and the spawnInterval but both if them are not changing does anyone know why. The bullet speed changes in the prefab but not the game objects.

wintry quarry
#

leave the prefab alone

#

and why do you have two different variables called bulletSpeed? That's just going to lead to confusion

tough trench
wintry quarry
#

Pictured

outer coral
#
[Serializable]
public class GlobalIdentifier : MonoBehaviour
{
    private Guid _id;
    public Guid ID { get => _id; set => _id = value; }

    private void Awake()
    {
        if(ID == null)
            ID = Guid.NewGuid();
    }
}

would something like this work?

wintry quarry
tough trench
# wintry quarry

its the same variable from the same script I just tried to call it a diffrent way

wintry quarry
#

or maybe not

#

it's impossible to tell from the code alone

#

anyway it doesn't make sense

#

you should not be changing the value on the prefab

#

You would want to change it on the spawned instances

#

Alternatively if they are all supposed to have the same speed, the bullet itself should not be keeping track of the speed variable, it should live in a central location somewhere that you can change in one place.

#

Good use for a Singleton

tough trench
#

the speed isnt changing at all when I manually change it\

wintry quarry
#

You're omitting so much detail about how all this works that it's really not possible to help much at the moment.

#

how does bulletSpeed even get used, for example?

#

And what exactly are you trying to accomplish? Changing the speed of existing bullets? Changing the speed of new bullets?

tough trench
#

This is the script

wintry quarry
neon fox
#

Hey Guys, Im Making My Own VR Game And Im Not Sure What Template to use. Can someone help?

wintry quarry
#

You would need to change it in the inspector for it to stick

tough trench
#

in the asset

wintry quarry
#

And delete this

#

because this is setting it to 25 always

wintry quarry
#

It's not a spawned instance in the scene

tough trench
#

so how would I change it in the heirarchy

wintry quarry
#

You're asking such vague questions.
If you mean at runtime, using code.
If you mean at edit time, in the inspector

tough trench
#

ok im going to try to figure it out thanks for helping

spiral parrot
#

Is it possible to create buttons that are different shapes?

#

like this:

#

Would you design it in photoshop, then import the entire bar into unity?

#

How do people usually design this kinda stuff?

rich adder
#

for some weird reason there is no inspector option

slender nymph
spiral parrot
#

Thank you

random cave
#

How do I lerp rb.velocity so its not instanty zero if I set it to vector3.zero

slender nymph
#

Use Vector3.lerp to get the velocity and assign the return value from that instead of immediately assigning Vector3.zero

warm condor
#

Hi guys, is there a way I can modify the pionts on the graphs that the AnimationCurves generate? For example the initial position of the graph is set to a diffrent place in the code if something happend (don't worry about the condition)

wintry quarry
#

Use Lerp the same way you would with anything else

random cave
#

Oh also

#

Anybody knows a way for my lerp functions to FINISH because like it like instantly stops

if (Input.GetKeyUp(KeyCode.W))
        {Mathf.Lerp(forward_backward_angle, 0, Time.deltaTime * 10f);
        }```
^ Like here it wont fully lerp back to zero
slender nymph
random cave
#

I understand how lerp works

#

But I want a way to work around my issue yknow

wintry quarry
random cave
#

I dunno where to put it then

#

Do I make a bool and put it in update?

wintry quarry
#

It needs to happen over multiple frames

#

So a Coroutine or Update

random cave
#

Coroutine works?

wintry quarry
#

Why wouldn't it

random cave
#

I dunno I thought they only ran once

wintry quarry
#

All code only runs once

#

Unless you use a loop or something

summer stump
random cave
summer stump