#💻┃code-beginner

1 messages · Page 148 of 1

spring skiff
#

What do you mean?
I just tried to reuse the code for my mouse movement as an alternative for Input.MousePosition.

polar acorn
#

Did you try looking up how to get mouse position in the new input system

willow radish
#

so im making a flappy bird ish game to learn unity because i just started today. and my UI works for getting points when you go through the pipes. but after 9 it goes to 1 instead of 10. and after 10 it goes to 2 instead of 20. how can i fix it so it shows the whole number?

polar acorn
willow radish
#

ohh okay let me try

#

thanks it worked!

spring skiff
polar acorn
willow radish
#

i also have another problem where it adds a point to the score even after the game over if it goes through the objects

spring skiff
# polar acorn Neither of those are mouse position

If I use:

var ray = _camera.ScreenPointToRay(Input.mousePosition);

I get this Error:

UnityEngine.Input.get_mousePosition () (at <7b7960ce51044497a5379ae0d5d70e62>:0)
SoulShardsCollecting.Update () (at Assets/Game/Scripts/SoulShards/SoulShardsCollecting.cs:
wintry quarry
polar acorn
spring skiff
wintry quarry
spring skiff
wintry quarry
#

that first person just forgot to write ReadValue() is all

polar acorn
icy junco
#

anyone knows anything from mirror i am trying to implement some networking in my game but it gives me an error

#
    void CmdPlayerShot (string _playerID, int _damage)
    {
        Debug.Log(_playerID + " has been shot");

        Player _player = GameManager.GetPlayer (_playerID);
        _player.RpcTakeDamage(_damage);
    }
spring skiff
icy junco
#

Assets\Scripts\PlayerShoot.cs(115,17): error CS1061: 'Player' does not contain a definition for 'RpcTakeDamage' and no accessible extension method 'RpcTakeDamage' accepting a first argument of type 'Player' could be found (are you missing a using directive or an assembly reference?)

wintry quarry
#

On line 115 of PlayerShoot.cs

icy junco
#

yeah but when i call a script with namespace do i need to call a script that is attached to it also with namespace or how does this work

wintry quarry
#

completely irrelevant to your error

#

you're just calling a function that doesn't exist/you never defined

icy junco
#

because i added namespace and now it is fixed but i get other error

#

Assets\Scripts\PlayerShoot.cs(115,30): error CS0029: Cannot implicitly convert type 'Mirror.Examples.Basic.Player' to 'MirrorBasics.Player'

wintry quarry
icy junco
#

Cannot implicitly convert type 'Mirror.Examples.Basic.Player' to 'MirrorBasics.Player'CS0029

wintry quarry
#

PlayerShoot is using Mirror.Examples.Basic.Player and the Player class is using MirrorBasics.Player

#

make sure you use the same one in both places

icy junco
#

is there a way i can easly change this

wintry quarry
#

yes

#

fix your using directives

icy junco
#

they are in both scripts the same

wintry quarry
#

doesn't sound like it

#

sounds like you have using Mirror.Examples.Basic; in PlayerShoot and using MirrorBasics; in Player

#

but I'm really just guessing here based on the errors since you haven't shared your scripts.

icy junco
#
        void CmdPlayerShot (string _playerID, int _damage)
        {
            Debug.Log(_playerID + " has been shot");

            Player _player = GameManager.GetPlayer (_playerID);
            _player.RpcTakeDamage(_damage);
        }````
#

this is the one giving error

wintry quarry
#

As I said, the using directives are the problem

#

also your GameManager is also likely involved here

#

it's returning the wrong type of Player

#

you really need to decide which Player class you want to use, and consistently use that across all your scripts

icy junco
#
using System.Collections.Generic;
using Mirror;
using Unity.Mathematics;
using UnityEngine;
using Mirror.Examples.Basic;

namespace MirrorBasics {
wintry quarry
#

Exactly as I said: using Mirror.Examples.Basic;

icy junco
#
using System.Collections.Generic;
using System.Numerics;
using Mirror;
using Mirror.Examples.Basic;
using UnityEngine;````
wintry quarry
#

is there a reason you're putting your classes into random other namespaces?

spring skiff
#

Is there a way to limit the Raycast without a if statement?

Something like a preset you make and then the ray knows its only 2 meter long instead of checking if a infinity long ray was shorter than 2 meter by hitting the gameobject.

solemn summit
icy junco
#

can i just deletete it in these scripts

spring skiff
wintry quarry
#

but again you need to decide which of the two Player classes you want to actually use

spring skiff
rich bluff
#

you want to avoid using an if statement, but the if statement is not used to limit the distance, it is used to query the raycast for the hit

#

you can just Raycast() but then you will need to check if the hit has anything in it, with an if statement

#
if (Physics.Raycast(ray, out hit, 100))
            Debug.DrawLine(ray.origin, hit.point);

becomes

Physics.Raycast(ray, out hit, 100);
if(hit.collider)
  Debug.DrawLine(ray.origin, hit.point);
solemn summit
#

Raycasts and Ifs are 🤞

spring skiff
# polar acorn Yes it's _on the page_

How you find this always so fast?
Because I'm reading this page for the 5th time and I'm stil dont see a "maxDistance" somewhere in the code.
I always find this if statement with Physics.Raycast...

solemn summit
#

In the example, the maxDistance is set to infinity

polar acorn
spring skiff
polar acorn
#

by setting that parameter

#

and not the others

spring skiff
polar acorn
spring skiff
#

the example I see is:

public static bool Raycast(Vector3 origin, Vector3 direction, out RaycastHit hitInfo, float maxDistance, int layerMask, QueryTriggerInteraction queryTriggerInteraction); 

    public static bool Raycast(float 1f); //is the smaller alternative```
gaunt ice
polar acorn
rich bluff
spring skiff
polar acorn
#

you have to give it all required parameters

#

if you don't need any other optional parameters, don't include them

rich bluff
polar acorn
rocky canyon
#

can scroll thru and find the overload that fits ur needs

rich bluff
rocky canyon
#

heres a basic one, u got a position, a direction, and a distance

#

no more, no less

spring skiff
rich bluff
#

@spring skiff there is an alternative way of finding the overloads you need, click on Raycast method name in visual studio and press F12

#

it will show you all the defined overloads (variants) of the Raycast method

#

you can find the one that suits your needs

polar acorn
gaunt ice
#

you need to provide all arguments for the methods unless they are optional parameters
also read the links i sent if you dont familiar with c# oop

rich bluff
#

i would like an answer, do you know what overload is?

stuck palm
#

im getting the console logs but im not getting the particle system playing until much later

#

and i dont know why

polar acorn
rich bluff
stuck palm
rich bluff
stuck palm
spring skiff
# polar acorn Don't pass values for the ones you don't need

how should this work?
How should Raycast know that I mean the MaxDistance?
The first one in the () is Vector 3 origin, the second is the direction and the 4th one would be the macDistance. What do I paste in all the others I dont need?
is it "none" is it "null"

#

if I only write the MaxDistance as only, so how should it know that its the raycast?
I think its marked as 4th area inside of the ()

rich bluff
polar acorn
#

You give it all the required ones

#

then give it a distance

rare crater
#

Is there a way to store scriptable objects within scriptable objects?

Or is there a code structure someone can recommend that would be a good workaround?

I basically have a list that holds skills. Both the list and skills are scriptable objects as I want all enemies and players to work off this same system.

rich bluff
#

but you are limited to one level and they are not very convenient to work with

rare crater
#

One level meaning?

rich bluff
#

you have any sprites in the project? look at how its structured

#

texture asset has sprite subasset

#

you cant have a subasset of a subasset, its only one level

rocky canyon
#

one level.. like.. u asked within

#

so 1 level.. would just mean.. the bottom floor..

#

(1) story

rare crater
#

I see

rocky canyon
#

lol. multiple levels .. would be 2 stories.. or (a scriptable object within a scriptable object)

#

3 levels would be scriptable object within a scriptable object within a scriptable object..

#

4 levels.. would be.

#

lol j/k

rich bluff
#

its limited this way because the subasset has a local GUID, so the full sub asset reference path is parent GUID + local

#

allowing unlimited nesting would probably kill deserialization and reference resolution performance

rocky canyon
#

recursive scriptable objects!

rich bluff
#

alternative is to serialize data in the scriptable with SerializeReference attribute or with Odin

#

with that you can have unlimited graphs

rare crater
#

😵‍💫

rich bluff
#

but you wont be able to reference serialized objects externally

stuck palm
rare crater
#

Ill look into it. But i just thought of... Maybe ill just have a nested script class to store my levels then just have the scripts reference their respective scriptable objects for data

rocky canyon
#

? i wonder why.. prewarm just means its ready to go when u press play.. it shouldnt do anything differently than what it does when its not

willow radish
#

when i start my flappy bird clone (haha) it starts immediately, can i make it so that it only starts after the user presses space?

rocky canyon
# stuck palm

ahh, i see probably has something to do with the way they're spawned.

#

or.. teh simulation space? idk tbh never seen that happen

stuck palm
#

particle systems seem to be a real pain for me

rocky canyon
#

ya, they're just something u get better at the more u tinker with them..

#

VFX graph is even more powerful than the built in Particle System and is complex too..

#

but with VFX graph you have more fine-control over your particle systems

icy junco
#

i have a student plan so i saw that i can use the multiplayer of unity for free is there any tutorial on how to set it up?

rich bluff
#

or if you want to make it all in one scene, you can start with Time.timeScale = 0, and set it to 1 on space

#

last is dirty and may lead to problems

stuck palm
#

cclicking on the player seems to fix it

rocky canyon
#

🤔 ill do a bit of googling on the side but i have no idea

stuck palm
rocky canyon
#

i was going to work with my particle systems today anyway.. so may work out

stuck palm
#

it is fate

rocky canyon
#

i usually just use pre-made visual effects

#

but for something like a dash, i'd probably make my own.. b/c for something like that i'd probably use the distance stuff.. like after moving so far u spawn a puff.. etc

#

Rate over distance thats the one

stuck palm
rocky canyon
#

lol no worries.. i saw ur art style.. figured those might be useful to u

#

i love stylized vfx

stuck palm
#

thank you

#

i wanted to do a cartoon style with like flat colors and stuff but

rocky canyon
#

which particle pack did you use for the dash?

#

i might experiment with it myself

stuck palm
#

it was a bit too hard to get everything consistent so i didnt bother

stuck palm
#

or

rocky canyon
#

the cloud puffs the one ur having issues with

stuck palm
#

oh i made them myself

rocky canyon
#

ohhh okay okay, nvm then

#

and they just spawn continuously like during a boolean being true?

stuck palm
#

i can give you a package if u want

rocky canyon
#

and this is the only code controlling it?

stuck palm
rocky canyon
#

no worries.. i can make something myself real quick with just some circle sprites

stuck palm
#

i was having issue with other particle systems in my game where it wouldnt start and start super late or whatever

#

i guess just the particle system control was the hardest part

rocky canyon
#

i'll remember ur issue as i work on my particles.. if i find a solution or think of something ill let ya know with a ping or something

stuck palm
willow radish
vast vessel
#

hey guys. im trying to set up assembly defenitions for my project but ive encountered an issue.
i cant refrance the c# class generated by the input system for my input action maps(its called Player_InputActionMap)

in the input action map as you can see i set the namespace to UnityEngine.InputSystem, and all the scripts that have a refrance to Player_InputActionMap also have a directive to UnityEngine.InputSystem which is also included in my asmdef. but for some reason i still get this error. how can i fix this? am i doing something wrong?

wintry quarry
wintry quarry
#

it depends where the code lives and where the code that is trying to reference it lives

#

e.g. which assembly definitions they are inside, if any

#

Where is the code that wants to use this class? What asmdef is it in?
Where is this class defined? What asmdef is it in?

vast vessel
#

this also dosnt work

wintry quarry
#

again namespaces have nothing to do with assemblies. They are simply part of the name of the class

wintry quarry
#

which are not relevant to the assembly issue

vast vessel
#

so if my input action class is in the folder that my asmdef is in it should be fixed?

rich adder
#

^^ You have to add the reference to the DLL in the asemdef file

wintry quarry
#

if you put them in the same assembly, sure then it will work with no additional steps

vast vessel
#

so if i put them both in the same folder it should work?

wintry quarry
#

if they are in different assemblies, then the one that uses the other must reference the one it is using

vast vessel
#

thanks

wintry quarry
#

They do not

#

asmdefs make an assembly that contains all the files in their folder and subfolders.

#

to reference any scripts outside the assembly, the other code must also be in an assembly and the first assembly must reference the other assembly. Namespaces don't come into play at all.

#

Of course namespaces still matter in the code but they are just prefixes to the name of the class

#

e.g. you may either write the full name of the class like UnityEngine.GameObject; or write just GameObject for short if you have using UnityEngine; in your file

cosmic quail
#

arent assemblies mostly useless since a game is gonna have lots of singletons that get referenced from basically everywhere so you cant really have different assemblies?

wintry quarry
#

assemblies are for grouping code into reusable bundles/packages and for speeding up compile times

cosmic quail
wintry quarry
cosmic quail
vast vessel
#

@wintry quarry hey soo uhh that did not fix it...

#

its placed with all my other scripts

#

and i still get the error

#

ohh shi

#

nvm nvm

#

sorry for the ping

cosmic quail
wintry quarry
#

No - the idea is that when you make a change in one assembly, only that assembly must be recompiled and not the entire project.

#

although I guess it might also recompile assemblies that depend on the one in which the changes happened.

cosmic quail
wintry quarry
sage mirage
#

Hey, guys! I have a question. How to set my current screen resolution when I am entering the game? So, whenever the player enters the game I want their screen resolution to be default?

wintry quarry
#

Why would every script you have be referencing lots of singletons?

#

Seems like bad code design in the first place.

cosmic quail
#

is there a better way to, for example, tell your AchievementManager singleton that you want a specific achievement to be unlocked?

#

cause lots of different things can give achievements and they could be in any script

bright kindle
#

Hi! I have an issue with the moving platform. I applied this code but the player stutters when on platform and eventually falls off.

wintry quarry
#

also parenting is not going to keep your player on the platform if it has a dynamic Rigidbody

bright kindle
#

I put Kinematic

wintry quarry
#

for what

bright kindle
#

the rigidbody for platform

wintry quarry
#

right so

bright kindle
#

I understand but I don't know how to make a code out of it

cosmic quail
bright kindle
wintry quarry
#

turn on interpolation on both objects to reduce stuttering.
And again - parenting is not a good idea

bright kindle
#

what do I replace it with?

#

instead of using parenting

#

the entire script you sent earlier?

stuck palm
#

why am i getting this error in my build?

wintry quarry
#

see if friction will do it on its own

#

also try with a custom physic material 2d with higher friction

stuck palm
#

doesnt happen in my playtest

bright kindle
cosmic quail
# bright kindle what do I replace it with?

you can either 1. get the platform's velocity and add it to the player,
or 2. you can just see if the player is standing on the same thing as last frame and if yes,
add its position difference to the player's position
(in both cases u raycast down from the player each frame to get the platform by the way)

im not sure which option is better though. what do you think @wintry quarry ?

wintry quarry
#

If your player movement code is overwriting velocity for example. it's going to break all of this

bright kindle
#

yeah thats possibly happening

wintry quarry
#

If you only move via AddForce for example it will behave naturally

warm condor
#

Hey guys, I was thinking of implementing a jump slide mechanic, which means if the player tries to slide before landing after a jump, the sliding value would increase. My question is how do I detect if a player has just touched the ground and at the same time wants to slide?

wintry quarry
warm condor
#

ah I see, is OnCollisinEneter a function?

wintry quarry
#

It sure is

#

google or ask your friendly neighborhood AI "How to detect collision in Unity3D"

warm condor
#

alr thanks

stuck palm
#

had to enable read/write

#

now its chill

green island
#

how do i ignore collsision between two gamobject i cant use layers because its a multiplayer game and i dont want a gamobject to collide with the player that spawned it but i want to collide with other players

green island
#

thank you

robust condor
#

I'm trying to draw sphere gizmo on each face of a cube, it works when I use a cube created in Unity, but not on a custom cube mesh. The gizmo will spawn inside the middle of my mesh cube. What is going on? ```Vector3 spherePosition = transform.position + transform.right * transform.lossyScale.y / 2f;

Gizmos.color = Color.yellow;
Gizmos.DrawSphere(spherePosition, 1);```

#

The bounds center is also off for some reason

ancient scarab
#

Hello! Im having some issues with a statement. Im getting this error

#
using System.Collections.Generic;
using UnityEngine;

public class DialogManager : MonoBehaviour
{
    [SerializeField] GameObject dialogBox;
    [SerializeField] Text dialogText;
    
    [SerializeField] int lettersPerSecond;

    public static DialogManager Instance { get; private set; }

    private void Awake() {
        Instance = this;
    }

    public void ShowDialog(Dialog dialog) {
        dialogBox.SetActive(true);
        StartCoroutine(TypeDialog(dialog.Lines[0]));
    }

    public IEnumerator TypeDialog(string line) {
        dialogText.text = "";
        foreach (var letter in line.ToCharArray()) {
            dialogText.text += letter;
            yield return new WaitForSeconds(1f / lettersPerSecond);
        }
    }
}
#

This is the code

robust condor
#

@ancient scarabUse textmeshpro instead

ancient scarab
#

How do i use that?

robust condor
#

TMP_Text

#

using TMPro;

ancient scarab
#

i dont have to change anything else?

#

just those 2?

robust condor
#

Well adjust accordingly if there are any warnings

ancient scarab
#

tyy

robust condor
#

And import the textmeshpro package

ancient scarab
#

Is there no other way to fix the existing problem btw?

short hazel
#

The existing problem is that you were using Text, which is old and has been replaced by TextMeshPro TMP_Text

#

Sure, you can still use it (it's not marked as obsolete), but it's better to use the latest tools. For the original error, you were missing a using UnityEngine.UI directive at the top.

keen crescent
#

In my game, whenever my bullet object hits a wall I'm instantiating a new prefab object with a particle system component to create particle effects. (The object is destroyed after playback) Would it be any better for performance/etc. if I had the particle system component on the bullet object itself? Can't decide between the two approaches

polar acorn
swift crag
#

I would not expect making it part of the bullet to matter at all

#

(other than making your design more complicated)

keen crescent
#

thank you

swift crag
#

the answer might also be "it doesn't matter"

polar acorn
#

It's not very difficult at all, especially since Unity actually officially added pooling support

swift crag
#

with ObjectPool<T> ?

polar acorn
#

Yeah, much easier that rolling up your own

swift crag
#

i need to try using that

#

at least, once i start spamming prefabs

ancient scarab
#

Same issue but this time its Action..

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

public class DialogManager : MonoBehaviour
{
    [SerializeField] GameObject dialogBox;
    [SerializeField] Text dialogText;   
    [SerializeField] int lettersPerSecond;

    public event Action OnShowDialog;
    public event Action OnHideDialog;

    public static DialogManager Instance { get; private set; }

    private void Awake() {
        Instance = this;
    }

    Dialog dialog;
    int currentLine = 0;
    bool isTyping;

    public IEnumerator ShowDialog(Dialog dialog) {
        yield return new WaitForEndOfFrame();
        OnShowDialog?.Invoke();
        this.dialog = dialog;
        dialogBox.SetActive(true);
        StartCoroutine(TypeDialog(dialog.Lines[0]));
    }

    private void HandleUpdate() {
        if (Input.GetKeyDown(KeyCode.Z) && !isTyping) {
            ++currentLine;
            if (currentLine < dialog.Lines.Count) {
                StartCoroutine(TypeDialog(dialog.Lines[currentLine]));
            } else {
                dialogBox.SetActive(false);
                OnHideDialog?.Invoke();
            }
        }
    }

    public IEnumerator TypeDialog(string line) {
        isTyping = true;
        dialogText.text = "";
        foreach (var letter in line.ToCharArray()) {
            dialogText.text += letter;
            yield return new WaitForSeconds(1f / lettersPerSecond);
        }
        isTyping = false;
    }
}
short hazel
#

It'll give you suggestions to fix it

ancient scarab
#

I dont see errors

#

thats also the problem

#

any idea how to get those?

short hazel
#

Then you need to configure it

#

!ide

eternal falconBOT
barren violet
#

Action is in the System namespace

elder osprey
#

This is my first time using the "new" input system and this is what I have for input in my movement script: https://pastebin.com/BSihe8J1. I am making a separate script for controlling the camera, how can I move the input management to a separate script to avoid getting multiple references to the PlayerInputActions?

polar acorn
#

There's no problem with getting multiple references to the map

elder osprey
#

I know, I just wanted to know so I could make my inspector look nicer.

dapper forge
#

`` [Command]
public void ChangeLanguage(string localeName)
{
var targetLocale = LocalizationSettings.AvailableLocales.Locales.Find(x => x.LocaleName == localeName);

    if (targetLocale != null)
    {
        LocalizationSettings.SelectedLocale = targetLocale;
    }
}`` Whats wrong here ?
short hazel
#

You tell us

ancient scarab
short hazel
#

There are two steps to the guide:

  1. Install the workload for Visual Studio
  2. Tell Unity that VS is the code editor it needs to use
#

Make sure you followed the guide entirely

ancient scarab
#

OkOk

rich egret
#

hi, i need some help to add a code for enemy damage

rich egret
vast vessel
#

how do i get a random vector 3 direction within a cone with a certain angle? i want to do this for bullet spread

ancient scarab
short hazel
ancient scarab
#

Like this?

wintry quarry
vast vessel
#

i dont think you can multiply vector3s with quaternions but ill try

wintry quarry
short hazel
# ancient scarab

Ah, VS Code. I don't use that for C# so I can't say. It's definitely not configured as some types like MonoBehaviour are not recognized (not colored properly)

ancient scarab
#

u use VS?

short hazel
#

Yes, 2022

vast vessel
#

big L

#

what now?

short hazel
#

Reverse, it works only on one side

#

Quaternion first, then the vector

summer stump
#

as praetor had it

vast vessel
#

r u joking?

languid spire
#

no he aint

wintry quarry
#

follow my example

polar acorn
summer stump
#

Bigga big L

polar acorn
#

Multiplication is not commutative in four dimensions

vast vessel
#

weird

#

thanks

ancient scarab
#

And found the error

#

😛

short hazel
#

That reply wasn't for you, but glad you fixed it

ancient scarab
#

No i know just wanted to let u know i fixed it 😄

rich egret
slender nymph
#

you just have a random RaycastHit variable that you never assign to anywhere and seem to expect it to magically detect when some other object collides with anything?

wintry quarry
#

Pick one

rich egret
#

and yes

slender nymph
#

if you're trying to use a raycast, it usually helps to actually have some raycast in your code

wintry quarry
#

and i don't understand what the projectile you're spawning is for

vast vessel
#

the result dosnt come out in a circular pattern. whats wrong?

polar acorn
stuck palm
#

why am i getting t his error? i didnt write "internal". it just says abstract in the script file

slender nymph
#

Station is likely either internal or private

stuck palm
#

do i have to write public abstract explicitly?

polar acorn
stuck palm
#

oh right

#

i didnt realise it had to be public to be able to use it

#

thanks

short hazel
#

Implicit means internal for types

#

No access modifier => internal

vast vessel
slender nymph
polar acorn
vast vessel
#

noooo, the reason the end of the cone looks like an ellipse in the picture is beacuse its supposed to represent a 3d cone viewed at an angle

rich egret
#

like this?

vast vessel
#

heres another example, i want the raycasts to go in a direction that they would end up hitting somewhere within that blue circle, the base of the cone

polar acorn
vast vessel
#

but the bullets keep landing like this

polar acorn
twilit pilot
#

you'd need to randomise on the plane perpendicular to the ray

vast vessel
#

hmm youre right, beacuse it works in some directions and dosnt in some others

vast vessel
twilit pilot
#

say your ray is R, pick an arbitrary vector A, (I don't think it matters as long as it's not R)
compute a vector U = R cross A
then vector V = R cross U
you then have vectors U,V that are perpendicular to each other and R, i.e they define the plane perpendicular to R

#

seems like I joined in this conversation late though and may have missed some context

willow radish
#

So i want my character (Turtle) to have an animation when you click space (so when it goes up) the video i have found recommends to use blend tree. but im not sure if i need to use float, int, bool or trigger for my animation when i press space

trail fox
#

I usually do bool

willow radish
#

what does bool do that the other dont/cant? or what do they all mean/do?

queen adder
#

Hi im new to coding c sharp and im struggling with this code since when I start the game my vehicle moves to the right infinitely. Can someone assist me pls thanks

polar acorn
trail fox
#

But I'm pretty new to coding

willow radish
#

ahh okay okay just a lot to take in for the first day hahaha

polar acorn
#

If you're moving in Update, you probably don't want to lerp

#

Just add to the position directly when you get input

vast vessel
polar acorn
#

Take a look at your transform gizmo, it's three perpendicular vectors

queen adder
vast vessel
# polar acorn Because 3D

so like.... which... wha.... i dont understand any of this. can some one just tell me, when i have this U and V, what do i do with them to make this... work?

#

sorry if im being too much of an annoyance, cant help it.

twilit pilot
#

they are the vectors you would perturb or sample along

#

a little rotation on the u axis and a little on the v axis to create a cone

fwiw, you could probably keep this more intuitive if you're not familiar with linear algebra by creating the perturbation in a simple frame of reference and then rotate the whole thing

polar acorn
vast vessel
#

nevermind

flat slate
#

can someone help me making a tree spawn script

queen adder
polar acorn
deft siren
#

the key is not being picked up :(

#

the GUI appears but other then that

polar acorn
deft siren
#

wdym

polar acorn
#

You're checking if the E key is currently held when you enter the trigger

deft siren
#

oh

polar acorn
#

are you holding E while entering the trigger

amber spruce
#

how do i set fullscreen to windowed fullscreen

willow radish
#

bc my character only moves up and down can i just use 1D blend type?

deft siren
#

if i put a colliderStay it will work?

carmine ivy
#

hello

polar acorn
deft siren
#

ok

#

thanks!!

carmine ivy
#

well i have some simple questions i would like it if anyone can talk to me in dms XD

carmine ivy
#

XD

#

well im a beginner and i havent worked on unity in a while

#

does inventory and breaking and collecting system take long to make?

#

like breaking trees collecting wood and crafting axes

subtle yacht
#

Hi ! I have an issue in my movement script. I wanted to do a air control system but when I jump and move, It looks like the player is hovering.
If I don't move while jumping, gravity is normal and it descends correctly, but if I move I glide and descend to the ground very slowly.
https://gdl.space/ipaqapunan.cs
There's my script, can someone explain me why it's so laggy, thanks !

summer stump
carmine ivy
#

depends on what if i just focus on that would it be possible to finish it in a short while?

polar acorn
#

¯_(ツ)_/¯

carmine ivy
#

any tips that might help me start in a good path

subtle yacht
carmine ivy
#

oh cool thanks

summer stump
carmine ivy
summer stump
#

!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

carmine ivy
carmine ivy
#

so if i have a chance for it i will do it but im unlucky so yk i would rather make sure i can before i start XD

polar acorn
carmine ivy
#

i am rn but im asking on the side haha

#

well ig tht is a yes thanks for helpp

ancient island
#

AudioSources aren't affected by Time.timeScale, how can I deal with pausing an audio source when setting Time.timeScale to 0?

ancient island
#

well, multiple audiosources

polar acorn
#

You'll have to call pause manually

ancient island
#

😫

#

ok thanks

buoyant knot
polar acorn
buoyant knot
#

as in for stereo?

#

my main concern is managing multiple audio sources to avoid 69 of the same SFX playing at one time, with slightly different phases

eternal needle
#

You can pool the audio sources so you only really have a few, but you just place them around as you play sounds

summer stump
buoyant knot
#

is pooling the audio sources the smartest way?

#

my project of 6 months is still totally silent lol

#

i’m mostly asking for “what is the best sort of strategy to avoid dumb audio that is hard to manage?”

eternal needle
timber tide
#

was reading stuff you don't want unused clips hanging in mem so dynamically loading

#

but I'd assume this is more about longer musical tracks

buoyant knot
#

i’m considering pooling from a singleton, having a giant enum tied to each SFX, singleton has a pool for each value of the enum, and then classes that want sound request it from singleton using the enum as an argument

#

BGM would probably need to be fully loaded/unloaded dynamically

timber tide
#

singleton does seem like the idea, but I thought each unit that wants to play the audio in a proximity must have an asset of themselves.

#

so you need the reference to the asset

#

oh yeah so singleton dictionary then

buoyant knot
#

singleton can be requested to play audio at one given position, so it knows which type of SFX, and then put one of a few gameobjects at that position with the right SFX, and tells it to start playing now

#

assuming i’m cool with the SFX not following something, which I can live with

#

main question: is this smart or dumb?

timber tide
#

so what about footsteps which each independent unit would probably want one of thier own

buoyant knot
#

why the hell is “uhhh” a blocked message on this server lmao

#

it was a complete response with all the context needed

#

censorship aside, idk

timber tide
#

so you'd probably need to pool many objects per asset if that's how it works, but again I've not really touched much on audio either

#

would make sense if it's just a reference call but unity

buoyant knot
#

but pooling is good for one off SFX, the way I described, right?

#

maybe even make an SFX object prefab so it can have all the volume settings set up?

scarlet hull
#

Can someone help me with this

polar acorn
#
scarlet hull
#

cant rn

#

if the original works and goes fine why cant its clones do the same

willow radish
#

I really dont know how to animate it when i press space ive looked at a ton of videos but they all use transitions from idle, run to jump and stuff like that but I only have jump and i really dont know what to do notlikethis

polar acorn
summer stump
eternal needle
scarlet hull
#

Could you possibly slide this one?

#

I would be much grateful

summer stump
scarlet hull
#

Ah I see

#

Alr imma figure something out

willow radish
rocky canyon
#

is there a better way to do this? at first i tried to nest a GetKeyUp within a GetKey thinking it was clever, then realized theres no way that would work

thorny hamlet
#

how to fix this guy pls help

slender nymph
thorny hamlet
rocky canyon
slender nymph
#

otherwise you would need some variable to track what it is currently set to and only call the method and change the visible property when the variable changes

eternal needle
queen adder
polar acorn
light radish
#
    public AttackRange CheckRangeOfAttack(){
        // Example: Check if the bounds of two colliders overlap
        Collider rangeCollider = shortRange.GetComponent<Collider>();
        Collider otherCollider = battleManager.target.gameObject.GetComponent<Collider>();

        if (rangeCollider.bounds.Intersects(otherCollider.bounds))
        {
            return AttackRange.Short;
        }
        rangeCollider = mediumRange.GetComponent<Collider>();
        if (rangeCollider.bounds.Intersects(otherCollider.bounds))
        {
            return AttackRange.Medium;
        }
        rangeCollider = longRange.GetComponent<Collider>();
        if (rangeCollider.bounds.Intersects(otherCollider.bounds))
        {
            return AttackRange.Long;
        }
        return null;
    }

Hey guys, having a function that returns a value based on certain critiria here, however it returns a value of a enum. Which means null cant be send back yet something has to be send back when all the other if statements fails (even though that should be happening ofcourse). What is the good practice in this scenario?

polar acorn
light radish
#

It are always the simplere solutions aren;t they

#

Thanks

hollow vessel
#

why is my flipStrength default value is different than what it is on unity,whileas my moveSpeed default value is the same than what it is on unity

timber tide
#

it's been serialized to another value

polar acorn
timber tide
#

the value you've set in the script is the default value if you were to reset it

hollow vessel
#

ohh right, i thought value what's on script and what's on unity will synchroniniize with each other lol. how do i reset the value on unity so then it'll follow the default value on script then?

hollow vessel
polar acorn
rocky canyon
# eternal needle The code is fine already, you arent setting it every frame. If you used the new ...

true, im making a top down point click prototype.. and the selection system is going to end up being a bit complex,

  • being a single click and release both starting and stopping on the target counts as 1 interaction
  • a click and release can either do 1 interaction in one scenario or another interaction in another
  • a click and drag (clicking on an object and releasing while off of said target) is another interaction
  • lastly a click and hold (doing different things according to which scenario
#

soo.. the new input system may be a real solid fit

hollow vessel
carmine ivy
wary saffron
#

i dotn knwo how to get my character to basically have a mesh model and the limbs to actually animate to the actual character

#

hence carrying over movement from bean to a actual player model

polar acorn
# wary saffron i dotn knwo how to get my character to basically have a mesh model and the limbs...

Learn the fundamentals of animations in Unity3D! From the basics of moving a cube to customizing a character animation!

This beginner-friendly tutorial is a thorough break down of Animations in Unity 3D! You will learn how to use to use the animation tab, how to record and modify animations, what animation curves are and how to use them and how...

▶ Play video
wary saffron
#

thanks

#

imma watch it

polar acorn
rocky canyon
#

look into the unity rigging package too, later on.. to combine different animations
you can have the torso doing one thing, and the bottom animating different, generic animations

#

animation rigging*

polar acorn
#

!collab

eternal falconBOT
wary saffron
#

how do i assign my blog

polar acorn
#

what

wary saffron
#

never mind i just needed to sign in silly me sorryy

#

my bad i acted stupid

eternal falconBOT
carmine ivy
timber tide
hollow vessel
#

you

#

you're right 😮 i could just mess with the value through editor to test out stuff instead of in script since yk itll cause more effort and yeah

covert wyvern
#

I'm receiving the error in red. When I launch the game and click anywhere to move it throws that. I don't understand because if I were to create a new project the code works fine.

polar acorn
covert wyvern
#

AHHHH

#

You were right.

#

I completely forgot to change it back

#

Thank you digholic!!!!

slender nymph
covert wyvern
#

Oh? I'll review that. Currently following this tutorial: https://www.youtube.com/watch?v=zZDiC0aOXDY&ab_channel=samyam

In this video I'll show you how to use the new Input System to move your player to where your mouse has clicked in 3d space.

ᐅGet the full Source Code Bundle to my Unity Tutorials 🤓
https://sam-yam.itch.io/samyam-full-source-code-to-all-videos

📥 Get the Source Code 📥
https://www.patreon.com/posts/60737375

🤝 Support Me 🤝
Patreon: https://www....

▶ Play video
stuck palm
#

why is overlapnonalloc more efficient?

slender nymph
#

it doesn't need to allocate a new array every single time you call it. it just populates the array you pass to it

wintry quarry
# stuck palm why is overlapnonalloc more efficient?

allocating objects (such as an array) and cleaning them up (aka garbage collection) takes some time. By reusing the same array you skip doing this, paying only an up-front cost to allocate an array which you reuse

stuck palm
slender nymph
#

have you bothered reading the documentation for the method?

stuck palm
#

naw

grand badger
#

Friggin docs are out for our jobs!!

#

They’re op I have them open in a tab constantly lol

stuck palm
#

how can i draw a cube gizmo with a rotation? the docs only show position and center

#

im trying to debug an overlap box but i cant see what its scanning cus im using a rotation

soft steppe
#

soo rn im trying to get a perfect bounce using a 2d physic material but i cant get the object to go to the same place it dropped it seems to go higher

soft steppe
#

my bad wrong channel

slender nymph
brave compass
runic prawn
#

I am making a chess program and have OnMouseDown, OnMouseDrag, and OnMouseUp logic attached to a controller script on every prefabricated piece. I haven't been following any guides, so right now I'm just doing things that work, but I have a gut feeling that this isn't good practice. Anyone have any suggestions, or is this alright? https://gdl.space/butoquhepi.cs

shrewd basalt
abstract finch
#

How would I be able to get the direction of which my transform needs to turn in order to look at another object/position? I.e. turn right or left.

shrewd basalt
#

use transform.left/transform.right

abstract finch
#

how would I make it find out which side to turn?

shrewd basalt
#

also Vector3.RotateTowards works better for this kind of thing

abstract finch
#

right but I need to find out which direction in order to determine which animation to play

#

theres turn right and turn left

runic prawn
abstract finch
#

I have an angle calculation formula but it only gives a float based on how far they are from the front

timber tide
#

you can probably figure it out from rotatetowards

#

just work out last rotation vs newest

north kiln
abstract finch
runic prawn
north kiln
shrewd basalt
north kiln
#

Keep track of your own set of angles which you use to update the transform instead of reading from .eulerAngles

timber tide
#

says in the unity talk that doesnt work

#

oh wait wrong one

#

can't find the video but there's a little snippet about disabling

#

feeling like the video is hidden cause I cant find it now haha

#

Mark and Ian from Unity's Enterprise Support team run through performance best practices drawn from real-world problems. Learn the underlying architecture of Unity's core systems to better understand how to push Unity to its absolute limits.

For more information on Unite Europe and future Unite events visit this page. https://unite.unity.com/

...

▶ Play video
#

25 minute mark

ivory bobcat
#

Relative to what in particular?

#

What I mean is that usually it'd be relative to position, assortment or some other type of data

nimble apex
#

like all of them as possible

abstract finch
#

Whats the difference between Vector3.MoveTowards vs Quaternion.LookRotation? The result is the same right?

nimble apex
#

it really depends tho

nimble apex
summer stump
ivory bobcat
abstract finch
#

What i meant was that the use case seems similar, to rotate an object towards a position

summer stump
nimble apex
#

quarternion controls ur looking(rotation mainly), like when u walk over the street, you looked at a restaurant, thats lookrotation

movetowards feels like someone pushing you right into the restaurant

ivory bobcat
abstract finch
#

ahhh sorry Vector.RotateTowards is what I meant

ivory bobcat
#

I'm not sure where the confusion is.

north kiln
#

LookRotation constructs a rotation, RotateTowards moves a direction

abstract finch
#

it seems like both Vector3.RotateTowards and Quaternion.LookRotation use cases are the same

north kiln
#

Now the only relation is that they both relate vaguely to directions and rotations. There's really no similarity

summer stump
ivory bobcat
#

If what was wanted was miniscule, they may look to operate the same but they're quite different.

abstract finch
ivory bobcat
#

Different tools.

north kiln
#

Quaternion.LookRotation gives you a rotation from direction(s)

#

RotateTowards rotates a direction towards another one

#

they are not related

abstract finch
#

what would be a use case for the Quaternion.LookRotation over RotateTowards and vice versa?

north kiln
#

Why

ivory bobcat
#

They're used for different purposes.

#

It's not one over the other - they aren't subsets of each other (do not overlap)

summer stump
#

You're essentially asking why use AddForce instead of setting the mass
There is a thread of a connection, but they can't be used to do the same things at all

teal viper
abstract finch
abstract finch
#
    {
        TurnDirection turnDirection;
        Vector3 delta = (_target.position - transform.position).normalized;
        Vector3 cross = Vector3.Cross(delta, transform.forward);
        Debug.Log(cross);

        if (cross == Vector3.zero)
        {
            turnDirection = TurnDirection.Back180;
            // Target is straight ahead
        }
        else if (cross.y > 0)
        {
            turnDirection = TurnDirection.Right90;

            // Target is to the right
        }
        else
        {
            turnDirection = TurnDirection.Left90;
            // Target is to the left
        }
        Debug.Log(turnDirection);
    }```
Im getting a return value that the target(cube) is to the right of the zombie here which doesn't make sense. The value is (0,1,0) even though the cube is clearly to the left.
sudden glacier
#

You considered turning it on and off again?

abstract finch
#

yea i tried that haha

sudden glacier
#

shi idk then, I usually just punch my screen

#

that fixes my anger issues at least.

timber tide
#

wouldnt cross here be depth

#

rather a direction towards the camera

slender nymph
#

yeah i don't think cross product would be the correct operation to use here

wintry quarry
#

This is overcomplicated

#

Just use Vector3 localPos = transform.InverseTransformPoint(_target.position);

#

that local position will tell you everything you need to know with the sign of its x component

abstract finch
#

alright ill try it out thanks

wintry quarry
#

Negative is left, positive is right

#

Likewise for the z coordinate for front and back

abstract finch
#

yea this is much better thank you

molten pulsar
#

hi i have a problem

#

when i import a model

#

and is that the bones appear to be missing in animator editor

slender nymph
#

this is a code channel

molten pulsar
#

oh sorry im new in the server

#

theres a help chanel or?

charred spoke
#

Random how ? This code will move the object in the world up direction

slender nymph
molten pulsar
#

okey

#

thank you

#

excuse me for my error

charred spoke
#

Then again using Translate like this probably will not result in the desired jump behaviour

pearl lodge
#

What does this do? I'm confused because nothing has been assigned to it yet. and im not familiar with this syntax (=>)

I thought maybe its been assigned in Unity editor but no option comes up to insert a 'SceneName'

#

oh. yeah I am following a tutorial so this is not my code.

teal viper
#

Same as a method that returns the value on the right side.

pearl lodge
teal viper
#

Yeah, that's a different way to write a property.

pearl lodge
#

I did not know about this documentation guide. Will definitely bookmark this. 👍

#

What about this one. Looks like they subsribe to 'onLoadComplete' event that is called when a scene is loaded.

I'm looking at the function and was wondering how they get the values for the parameters since no arguments are being passed in. the function is just "called" from what I can see.

slender nymph
charred spoke
#

Well I would suggest to find a tutorial that at least uses a character controller. Simply translating like this will ignore physics collisions and lead to a whole mess of other problems

eternal falconBOT
odd mason
#

hey so im trying to use animator for my doors, and im getting this what am i doing wrong?

fossil drum
# odd mason

Is it DoorOpen or doorOpen? Because you made a string with capitals, and then put a string without it in play.

odd mason
#

thats so if i want multiple doors not sure if i need that for multiple doors though, jsut adapting some code from a tutorial, and the error still happens with or without the private strings

fossil drum
#

What is your animation state called? Its saying it can't find the not capitalized ones as far as I understand.

#

If the state is the DoorOpen you should play that.

odd mason
#

ill shwo you

#

it should be the right one so idk wahts happeneing

#

this right?

fossil drum
#

Sure, but it's capitalized here... Which was my whole point. What if you actually play the correct name?

odd mason
#

huh i see

fossil drum
#

You are aware you are not using the private strings you defined at the top right?

odd mason
#

yeah i realized that after

#

will i even need those to have multiple instances? or will they all open and close seperately without it?

fossil drum
odd mason
#

i jsut mean having multiple objects with this script

#

when i interact with one of them will all of them open or just hte one im interacting with

fossil drum
#

Currently you are telling your Animator myDoor component to play OpenDoor. So only that Animator will open his door.

odd mason
#

ah makes sense

#

i completeley understand.

#

yeah works like a charm thanks

#

would you happen to know why my door is only closing? im like super unsure, thought this would work

#

the initate works but once it opens and i close it after the close frame it just goes back to the last frame of open

languid spire
#

your logic is flawed. Look at your code and what happens if Close is true

odd mason
#

oh goddamnit i see it now, huh i looked at it like 4 times LOL thanks!

languid spire
#

you dont need both Open and Close, just use one of them

static bay
#

Ya you don’t need 2 booleans to track the same state.

#

If a door isn’t opened then it’s obviously closed.

#

Unless it’s a 4 dimensional door 🤔

stuck jay
#

Random.Range doesn't work now

#

"int randomXAxis = Random.range(0, 1);"

timber tide
#

rip random method

stuck jay
#

Seen it

#

Doesn't mention my issue

timber tide
#

there's a secret tidbit in there

north kiln
#

Yes it does

gaunt ice
#

a simple trick, you can hover on the method to see what overloads you are calling

timber tide
#

why does float get the privilege of being max inclusive

stuck jay
#

Apparently I need to specify UnityEngine.Random? But the example didn't, and I used to just write Random.Range

slender nymph
#

if you have the System using directive that is going to happen, just like the docs page says

north kiln
#

Define doesn't work, because it would be a compiler error if you had it that way

stuck jay
#

As in it sent me a compiler error

gaunt ice
north kiln
#

Please specify next time so people don't presume your issue is something else

stuck jay
# gaunt ice

I'm aware of that, I just don't understand why Random.Range worked before and now it needs to be UnityEngine.Random.Range

timber tide
#

because you used some System method and it injected itself into your script

north kiln
#

Without the compiler error I don't think anyone should help

stuck jay
#

'Random' is an ambiguous reference between 'Unity.Mathematics.Random' and 'UnityEngine.Random'

timber tide
#

oh that one

#

may just clarify it inline then

north kiln
#

Great, there you go. You are using the mathematics library, and so it's ambiguous what random you are talking about when you try to use it

timber tide
#

otherwise you can do like an alias was it called?

stuck jay
north kiln
#

You have caused the conflict with your using statement, using both libraries

stuck jay
#

I didn't add the library though

north kiln
#

You added the using.

timber tide
#

If you use a method from the library without using then it'll do it automatically

#

but if you are using the math library too you can do something like this I believe

using UnityMathsRandom = Unity.Mathematics.Random;
using UnityRandom = UnityEngine.Random;

Or to whatever you prefer to remove any ambiguity

north kiln
#

My site mentions both of those things 👍

timber tide
#

oh specific to the random library too haha

blazing prairie
#

is it ok to overuse C# actions and funcs ?

static bay
#

define "overuse"?

topaz mortar
#

I have my items as Scriptable Objects in my game client.
But to prevent cheating (multiplayer) I need them to be server side.
I want to manage the items in the unity editor though, what's a good way to make sure my server always has the correct & latest version of the items?
Knowing we cannot trust information sent from the clients.

#

Would it be possible to keep the "main source" in a spreadsheet and change values there
then import that spreadsheet to both my database and Scriptable Objects?

timber tide
#

seems like research

teal viper
topaz mortar
#

server is not unity 😛

#

well it's on unity game services

#

but looks like the spreadsheet thing should work

kindred halo
#

do you guys know how do I detect if my characterController is colliding with another box collider?

hushed jasper
kindred halo
#

raycast is useful but I can't see the distance properly as it stays invisible

hushed jasper
#

that way boundaries that you want to see will appear in scene view

buoyant knot
#

for PlayerInput, many things in game might want to reference that one component, so it’s better to not have it really tied to any one thing that really uses it

#

yes

#

still yes

tulip jolt
#

Does anyone know how to fix camera moving by itself? I have used a free first person controller asset by the unity store, and for some reason the character keeps moving in front with a little bit of left.

i had that issue by another code that i tried in another unity project, where the camera just floats in the sky.

might be an issue from my unity but yeah help

buoyant knot
#

like if you later decide to have multiple character objects, and swapping the character or enabling/disabling it, then you can run into trouble because your playerinput is on it

hasty spire
#

https://paste.ofcode.org/wfqBmihKe2mc643dx5cL66 im trying to add knockback to my players attack so i thought i would implement it where my enemy takes damage but i am getting a null reference exception error when hitting my enemy and i dont know why

timber tide
#

have you debugged it and made sure you're grabbing the collider of an enemy

hasty spire
timber tide
#

show code at 60

hasty spire
timber tide
#

right, along with the Trigger method

hasty spire
timber tide
#

oh, so the rb is on the script itself, but not what you're colliding with eh

#

rather what you're applying force to.

hasty spire
#

the rb is on the enemy im applying force to yhough

timber tide
#

but your rb isn't instantiated, so make sure the component is set in start or in the editor there

#

half asleep, but if that's the line, then yeah go log that rb is set

timber tide
# hasty spire ah right

if you're meaning to grab the rb from the collision target, then you need to GetComponent from that instead

#

inside of the trigger method

hasty spire
#

i got it working thanks

timber tide
#

ah kk

hasty spire
#

i forgot to do GetComponent in start

hasty spire
#

im just not getting a null reference exception

timber tide
#

could be related to how your rb is set up

#

may be disabling physics on it

hasty spire
#

might be the constraints?

dense cargo
#

Ye, uncheck those for sure. It won't move in any direction with all those marked.

hasty spire
#

because my enemy isnt walking on ground

kindred halo
#

how can I make my object move in another objects z axis?
Like I'm making a simple wall run and when my detector object touches the wall I want my player to move forward in the walls z axis.

tacit estuary
hasty spire
#

thanks

tacit estuary
tacit estuary
hasty spire
kindred halo
#

I mean using key input

tacit estuary
shrewd swift
#

im curious, can you retreive the "tag" of a gameobject from a collider by doing collider.tag

#

i cant go check in unity so i am askign here
im pretty sure you can't

shrewd swift
#

oh ty

#

i only checked collider

#

from Collision

tacit estuary
# kindred halo character controller

You can get the z axis of your wall by finding the cross between the wall’s normal, and the world’s up position. Raycast on either side of the player, and then run Vector3.Cross(hit.normal, transform.up)

shrewd swift
#

so I wanted to do a build test and I am getting some "this namespace couldnt be found"
but when I check by opening the line in VS, i get no errors

example:

#

what can cause this issue when building ?

kindred halo
#

I'm using a rigidbody detector

#

If it's true then I want it to follow the walls cross

#

I doing like this

keen dew
shrewd swift
#

ah yes i forgot

#

ty

#

the thing is, how I prevent from trying to compile ?
I am using this lib in some of my scripts, it helps me for the inspector and for serializing stuff, so i need a part of it for the build

prisma silo
#
        if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, playerLookRange))
        {
            if (hit.transform.CompareTag("NPC"))
            {
                pressEToDoThing.SetActive(true);
            }
            else
            {
                pressEToDoThing.SetActive(false);
            }
        }
#

im trying to show a ui whenever i look at an npc it works but when i look at the sky (or something which is not a game object) the ui stays on

rare basin
#

beucase it doesnt hit anything

#

so it doesnt go inside the if

prisma silo
#

ohhh ok

wintry quarry
prisma silo
#

thanks

ivory bobcat
prisma silo
#

thank you everyone

tacit estuary
shrewd swift
#

is OnTrigger[...] called on the GO where the collider is set to trigger or on both colliders

dim halo
#

I want to move the number one, but I cant, can someone help me out

shrewd swift
#

or at least not precised well enough because I wouldn't be here

ivory bobcat
icy sluice
#

you want to move it with code or just move it within editor

rare basin
summer stump
lusty halo
#

I don't know why but when commiting Changes on Visual Studio Code it is loading with no progress...

fervent abyss
#

Hello! Can anybody explain me how can I make the rotation more smooth? I think I can use the Quartenion.Slerp but im struggling with the start and end points (what to put in there)

#

This is how I rotate the kart:

void RaycastGroundCheck(){

        RaycastHit hit;

        isGrounded = Physics.Raycast(transform.position, -transform.up, out hit, 1, groundLayer);

        transform.rotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;

    }

(Its in Update)

tall delta
# fervent abyss This is how I rotate the kart: ```cs void RaycastGroundCheck(){ Raycast...

the quick and dirty way to do it is just:

void RaycastGroundCheck()
{
    RaycastHit hit;
    isGrounded = Physics.Raycast(transform.position, -transform.up, out hit, 1, groundLayer);
    var targetRotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation;
    transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation , Time.deltaTime * 10); // or some other magic number
}

the problem here is just that slerp (or lerp) is not really intended to be used like that, but it does work

fervent abyss
#

Why is it "dirty" tho?

tall delta
# fervent abyss Why is it "dirty" tho?

it's a matter of preference I suppose. but for me the problems are that slerp here won't follow it's graphed value because the target and interpolation factor constantly change (but it will be smooth) and that tickles my tism the wrong way 😄 as for the dirty part we're not tracking target rotation and rotation(model) smoothing as two different concepts, we're just doing it all in the same go.

as for why it's not working, that's a bit of a mystery to me, are you calling RaycastGroundCheck every frame? maybe try a different number than 10 here? Time.deltaTime * 10

#

so maybe something more like this

public class GroundAlignmentScriptThingy : MonoBehaviour {
    public LayerMask groundLayer;
    public float smoothingSpeed = 10f;

    private Quaternion targetRotation;
    private bool isGrounded;

    void Update()
    {
        RaycastGroundCheck(); // calculate the 'real' rotation
        SmoothRotation(); // update the visuals
    }

    void RaycastGroundCheck() {
        isGrounded = Physics.Raycast(transform.position, -transform.up, out var hit, 1, groundLayer);
        if (isGrounded) {
            targetRotation = Quaternion.FromToRotation(transform.up, hit.normal) * transform.rotation; //align with ground
        } else {
            targetRotation = Quaternion.identity; // if we're not on the ground, maybe just point upright? I don't know
        }
    }

    void SmoothRotation() {
        transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * smoothingSpeed);
    }
}
rocky canyon
#

should be able to smooth it out some

#

but yea, guys correct about the slerp being incorrect

rare basin
#

or just use DOTween and save yourself all the issues with quaternions

rocky canyon
#

u shouldnt pass in the variable ur actually rotating as that first parameter

#

u need to cache the starting position first and use that instead.. so ur lerp isnt using itself to calculat

#

i have this same setup. and yea the key is to:

  • fix the slerp and make it proper
  • use good models for ur ramps and stuff.. the more faces it has the more smoother ur rotation will be..
fresh lintel
#

Hello devs, who knows? code simplified .

rocky canyon
#

u can wrap the bottom else stuff into a function..

#

call that function from the top else and the bottom else

tall delta
#

||I've unironically used goto in cases like this||

fresh lintel
rocky canyon
#

it could.. i suck at those

#

lol

#

always have to look up what each of those do.

rare basin
#

imagine you want to add a new feature into the already nested if/else statements

tall delta
#

but I'm not joking, nested elseif chains are the only place where 'goto' can be used.

polar acorn
rocky canyon
rare basin
rocky canyon
#

but it could be broken into specific pieces if u want

fresh lintel
#

so no break or return can help here ? code itself very cumbersome so even i cant find begining and end

rare basin
tall delta
rich adder
#

that formatting really is off-putting

rare basin
rocky canyon
fresh lintel
#

ok thx. will try something

polar acorn
#

Formalize your rules for what you want to happen and when

#

And then you can simplify

#

Start by identifying which outcomes you want. List them all out, and then what conditions have to be true for that specific outcome to occur

#

Once you do, you should see some repeated and shared conditions, which will inform the order and structure of your conditionals

tall delta
#

afai can tell, this is the problem you have:

void ExampleMethod()
{
    if (condition1)
    {
        // Some code
        if (condition2)
        {
            // Some code
            goto End;
        }
        else
        {
            // Some code
        }
    }
    else
    {
        // Some code
    }

End:
    // Code to execute after the goto statement
}

now given that, if you don't want to use goto, the only solution is to nest methods so you can use return. or rewrite the logic without the nested problem, or duplicate code.

void ExampleMethod()
{
    if (condition1)
    {
        HandleCondition1();
    }
    else
    {
        // Some code for else part
    }

    // Code to execute after the conditions
}

void HandleCondition1()
{
    if (condition2)
    {
        // Some code for condition2
        return;
    }
    
    // Some code for else part of condition2
}

rare basin
#

don't use goto please

rocky canyon
rare basin
#

just refactor your architecture, it is wrong

polar acorn
rare basin
polar acorn
#

In a modern C# program, without the bounds of needing to fit a program into a register or dealing with the file size of a punch card, you will never use gotos. All goto situations can be made easier to write, cleaner, and notably easier to maintain by just properly formalizing your rules beforehand and a few function calls

queen adder
#

what's the reason why unity cent display props in the editor by default again?

rare basin
#

I have never used goto in my entire unity journey

rocky canyon
#

same other than making memes

rich adder
polar acorn
# queen adder what's the reason why unity cent display props in the editor by default again?

Because a property isn't a variable, it's a pair of functions. If you're using an auto-property, there is a variable, but it's hidden. The default state of a variable is private and non-serialized. Since you can't actually put a public or a [SerializeField] on something that doesn't exist in your code, Unity provides a way to access that anonymous inner field with [field: SerializeField] on an auto-property.

scarlet skiff
#

how do i make it know that i mean if the player collides with the ground? i added the public game object and draggen the player there

rich adder
polar acorn
scarlet skiff
#

uh oh..

polar acorn
rare basin
queen adder
rare basin
#

never worked with assembly, but i can imagine it would be kinda impossible to work with it without goto

polar acorn
#

branch statements are a lot bigger than gotos

rich adder
#

goto is a must

rare basin
queen adder
#

what if we have a /huhhow collision that auto links to vertx's specific page

scarlet skiff
#

i took the code from a tut

#

though it has one difference

polar acorn
polar acorn
scarlet skiff
scarlet skiff
#

oopsie

rocky canyon
#

yea, they put it within the collsion detection

wraith mango
#

How do I access data from a scriptable object

rich adder
#

same way you access everything else

wraith mango
#

ArgumentException: GetComponent requires that the requested component 'NPC' derives from MonoBehaviour or Component or is an interface.

#

whoops

#

meant to send this

wraith mango
rich adder
polar acorn
wraith mango
#

oh

#

uh no

rich adder
#

You have to access whatever holds the SO

polar acorn
#

GetComponent gets components (shocking, I know)

wraith mango
#

i feel stupid now 😭

polar acorn
#

You'll want to get whatever component holds the NPC value

wraith mango
#

alr

scarlet skiff
#

if i understood it correctly, this returns a value based on what direction the player is moving, if its right, its 1, if its left, its -1 and up and down are 0?

rocky canyon
#

that doesnt seem right lol

#

is the ramp on the ground layer.. or w/e layer ur raycasting down towards to get the normal?

fervent abyss
rocky canyon
#

looks like the cars trying to stay str8 (like the plane) even when its going up the ramp

#

is ur raycast hitting it?

#

debug the raycast that gets the normal and see if its the ramp

#

or if its hitting the car's own collider or something

#

heres the project i was using.. its all set up. could maybe use it to reference and compare..

fervent abyss
#

I made so the the kart rotation equals rigidbody rotation but except the X axis (its the forward/backward rotation axis), now it works

#

Thanks!

icy junco
#

i am working on playerMovement animations
and i want to implement sliding but when i press c while running nothing happens

        {
            if (Input.GetKeyDown(KeyCode.C))
            {
                rn_speed += sl_speed;  
                playerAnim.SetTrigger("Sliding");
                playerAnim.ResetTrigger("Running");
            }

            if (Input.GetKeyUp(KeyCode.C))
            {
                rn_speed -= sl_speed;  
                playerAnim.ResetTrigger("Sliding");
                playerAnim.SetTrigger("Running");
            }
        }```
icy junco
polar acorn
icy junco
#

yes its just a part of the code

polar acorn
#

So what function is this in

icy junco
#

update function

polar acorn
#

Okay good. And when is Running set to true

#

actually maybe just post the full !code so I don't have to play 20 questions

eternal falconBOT
icy junco
#
    {
        if(Input.GetKeyDown(KeyCode.W))
        {
            playerAnim.SetTrigger("Walking");
            playerAnim.ResetTrigger("Idle");
            walking = true;
        }

        if(Input.GetKeyUp(KeyCode.W))
        {
            playerAnim.ResetTrigger("Walking");
            playerAnim.SetTrigger("Idle");
            walking = false;
        }

        if(Input.GetKeyDown(KeyCode.S))
        {
            playerAnim.SetTrigger("BackwardsWalk");
            playerAnim.ResetTrigger("Idle");
        }

        if(Input.GetKey(KeyCode.A))
        {
            playerTrans.Rotate(0, -ro_speed * Time.fixedDeltaTime, 0);
        }

        if(Input.GetKey(KeyCode.D))
        {
            playerTrans.Rotate(0, ro_speed * Time.fixedDeltaTime, 0);
        }

        if(walking == true)
        {
            if(Input.GetKeyDown(KeyCode.LeftShift))
            {
                w_speed = w_speed + rn_speed;
                playerAnim.SetTrigger("Running");
                playerAnim.ResetTrigger("Walking");
            }
            if(Input.GetKeyUp(KeyCode.LeftShift))
            {
                w_speed = olw_speed;
                playerAnim.ResetTrigger("Running");
                playerAnim.SetTrigger("Walking");
            }
        }

        if (running == true)
        {
            if (Input.GetKeyDown(KeyCode.C))
            {
                rn_speed += sl_speed;  
                playerAnim.SetTrigger("Sliding");
                playerAnim.ResetTrigger("Running");
            }

            if (Input.GetKeyUp(KeyCode.C))
            {
                rn_speed -= sl_speed;  
                playerAnim.ResetTrigger("Sliding");
                playerAnim.SetTrigger("Running");
            }
        }```
rich adder
#

lord..

polar acorn
eternal falconBOT
icy junco
polar acorn
icy junco
icy junco
polar acorn
#

it's never true

icy junco
#

what do you mean?

polar acorn
icy junco
#

its true when i am walking and then press left shift?

polar acorn
rocky canyon
icy junco
stuck palm
#

Why is the table not getting highlighted? probably something to do with collision idk but heres the code, maybe the gizmo and overlap box are not the same?

#

code attached here

ancient island
#

Hey guys, how can I change a toggle's value without triggering its event?

ancient island
#

nice, thanks

icy junco
#

when i am standing in idle mod or not moving my player glides over the floor anyone knows why this happens

rocky canyon
stuck palm