#💻┃code-beginner

1 messages · Page 555 of 1

static cedar
#

Impulse should be a separate method imo.

#

But yeah.

cosmic dagger
#

it moves a little every frame until it reaches the amount of jump after 1 second . . .

#

you want it to reach the amount of jump during that one frame, hence, using Impulse ForceMode . . .

naive pawn
#

force is time dependant (F = ma = mv/t), impulse, aka momentum, is not (P = mv)

nova kite
#

playerRB.AddForce(Vector3.up, ForceMode mode = ForceMode.Impulse * jump);

#

it says i cant multiply it now

#

so how do i add the jump

teal viper
static cedar
#

You can make your own enum flag.

[Flags]
public enum F {
   FlagOne = 1 << 0
   FlagTwo = 1 << 1
   FlagOneAndTwo = FlagOne | FlagTwo
}

1 << n basically means shift this bit to the left.
0b000000000000000000000000000001 also works to explicitly lay out the bits but that's wonky.
Enums inherit int by default, which has 32 bits.

rich adder
#

when passing a value you don't use = in the signature

nova kite
#

oh my god🤣

#

see no idea how to read the documentation

#

i thought you are creating a local variable just for that

rich adder
#

thats just c# basics nothing to do with docs

wispy coral
nova kite
#

or an object of ForceMode

nova kite
#

that's what i saw and copied

gentle bone
#

no you didnt... do you see the comma in between

nova kite
#

i did put a comma

naive pawn
#

separate things

rich adder
#

its important you learn these c# basics

nova kite
#

i know how to pass arguments haha it's the same in cpp

naive pawn
#

the declaration tells you how to call it, it doesn't show how to call it

static cedar
naive pawn
rich adder
nova kite
#

i thought it's different here idk😭

static cedar
#

The parameter arguments when used are in the same order as usual.

naive pawn
nova kite
rich adder
#

Unity is just showing you how the method was declared in their codebase

naive pawn
#

ah

nova kite
#

how do you see what you need to write

#

if the doc is not showing you that

rich adder
#

are we going in circles here

gentle bone
#

do you drive a car without looking once in the manual... thats how you use unity without using the docs...

nova kite
#

but the doc is not telling you how to write the thing

gentle bone
#

yes it is... just scrolling down

naive pawn
#

public void AddForce(Vector3 force, ForceMode mode = ForceMode.Force)
there's a parameter list that specifies Vector3 force and ForceMode mode, and mode has a default (=) of ForceMode.Force
when you want to set a mode yourself, ignore the default
so you pass a Vector3 and a ForceMode

rich adder
naive pawn
gentle bone
static cedar
#

You can use paramName = ... to specify which argument you meant.
AddForce(Vector.Up * jump, ForceMode = ForceMode.Impulse);
This is valid code.
This feature exists when you want to leave the other default arguments as is.

gentle bone
#

you even have an example in the docs..

naive pawn
static cedar
#

But otherwise, you can omit and pass the arguments in order.

naive pawn
#

ForceMode is the type, not the parameter name

gentle bone
naive pawn
#

(also up is in camelCase)

nova kite
#

the example in the doc showed me Input.GetButton and then i clicked it and it said not to use that

static cedar
nova kite
#

and then i got lost haha

static cedar
#

Oh it's mode.

static cedar
#

I thought the param is ForceMode.

rich adder
nova kite
#

Note: This API is part of the legacy Input class, and not recommended for new projects. The documentation is provided here to support legacy projects that use the old Input Manager and Input class. For new projects you should use the newer and Input System Package. (read more).

static cedar
#

You can use paramName = ... to specify which argument you meant.
AddForce(Vector.up * jump, mode = ForceMode.Impulse);
This is valid code.
This feature exists when you want to leave the other default arguments as is.
Ok fixed.

naive pawn
rich adder
teal viper
rich adder
#

you can still use it

nova kite
#

idk i just saw not recommended and was like alright then

naive pawn
#

c#, c++, and many others are part of the c family, they share a lot of basic syntax features

#

including method calls and declarations

rich adder
#

iss tru

nova kite
#

but it's more than that it's the names

naive pawn
#

it isn't

nova kite
#

Impulse for exapmple is not part of the c# language

gentle bone
#

theres even a 2nd example with what you would have needed..

naive pawn
#

it's just a value you pass of some given type

teal viper
#

The syntax doesn't change

rich adder
#

all it changes are the types declared

static cedar
#

I think the only thing I can say is.

#

Get used to it.

naive pawn
#

the basic syntax for method declarations and method calls is identical in c, c++, c#, java, and probably some others

rich adder
#

learn how to seperate Unity API with just normal C#

#

Unity is just an API

nova kite
#

OH!

naive pawn
#

there's some differences with modifiers, generics/templates, defaults, and named params, but the core of it really is just the same

nova kite
#

WAIT

rich adder
#

doesnt change anything how C# works

nova kite
#

i think i got it

rich adder
#

specific unity things are anything inheriting UnityEngine usually like Monobehaviour

nova kite
#

ForceMode mode = ForceMode.Force
basically means that the second part of that code after the comma you need to write the mode you want from ForceMode but with a dot

static cedar
naive pawn
static cedar
#

To a degree that I think it would be cool if C# have it.

nova kite
#

ffs

naive pawn
#

it requires a ForceMode type, which is an enum, so you have to get a member of that enum

#

you could also cast some other value to ForceMode

nova kite
#

ohh and that's where preknowledge comes from

#

cuz you gotta know that you do that with a dot

#

okay i see

naive pawn
#

iirc (ForceMode)0 would also be a valid ForceMode value, it'd be equivalent to ForceMode.Force

nova kite
#

because it's ordered?

naive pawn
#

you just need some value of the given type

gentle bone
nova kite
#

like an array?

static cedar
#

I think just 0 is valid.

naive pawn
rich adder
#

unless you specify the values, they start from 0 ye

nova kite
gentle bone
#

if it would be another parameter you would call that ...

static cedar
naive pawn
#

(enums are an integral type, not necessarily int)

nova kite
#

you see what this thing is a class enum etc and then treat it accordingly with knowledge you have about the language

gentle bone
teal viper
naive pawn
nova kite
#

i figured it out

#
void Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        playerRB.AddForce(Vector3.up, ForceMode.Impulse);
    }
}
#

but how do i add the jump to it because it wont let me multiply the value by the jump vlaue

rich adder
#

wdym.. its always direction * forceAmount

static cedar
#

Wild.

rich adder
#

the same thing you did for movement..

static cedar
#

Vector3.up * jump, ForceMode.impulse

nova kite
#

damn it i tried doing that earlier but not now after i fixed the second part lol

#

okay that makes sense

static cedar
#

Brainfart moment. UnityChanSalute

nova kite
#

🥲🥲

static cedar
#

Where did you think you should be multiplying earlier? notlikethis

nova kite
#

We don’t talk about that

#

🤣

static cedar
rich adder
#

forcemode 😉

#

seen it

nova kite
#

Damn it🤣🤣

naive pawn
#

do you know vector math

nova kite
#

Heck no

#

I found out what Vector is 2 weeks ago lol

#

When I watched a data structure course on YouTube

#

We aren’t getting to data structures until the final semester

nova kite
#

Wth😭

#

Is this what they teach in discrete math

static cedar
nova kite
#

My high school didn’t teach physics lmao

#

I never learned physics

static cedar
#

And the most common expressions are X and Y...

static cedar
nova kite
#

I’m gonna take the one required class next semester

#

Of physics

static cedar
#

As long as you're in a scientific field, you should have physics in college anyways right?

#

Ah ok.

nova kite
#

Yup

#

I didn’t wanna take it along with calc2

#

Cuz that’s gonna be a nightmare I heard

static cedar
#

Weak, I almost failed Calc2.

nova kite
#

🥲🥲

#

Our calc1 processor let us use our phones and any calculator we want during the exams lmao

#

It was on a pc too

#

And all multiple choice

#

Ridiculous 🤣

static cedar
#

Idk, I legit have pre calculus have the same topic as Calc2. But our teacher decided to spam the most obscure trig and algebra properties along with it.

nova kite
#

Woah you did integrals in pre calc??

static cedar
#

The topic is called anti derivatives.

nova kite
#

Yea

#

Isn’t it the same

#

Integrals

static cedar
#

Yeah pretty much.

nova kite
#

We started it a bit in calc1 and I hate it

#

So much

static cedar
#

We only went through the basic essentials. Didn't go ham with trig identities back then.

#

Did Ur teacher forced you to memories trig identities?

nova kite
#

Nope he let us have formulas luckily🥲

#

I’d have failed if not

#

Formulas is all I need

static cedar
#

Double angle, half angle, cos to sin.
sin^2() + cos^2() = 1?

#

Not even scratching it.

nova kite
#

Holy shit you remember

#

I can not memorize that shit

static cedar
#

Real.

#

I went through Calc3 while forgetting trigonometry substitution from Calc2. I am TOTALLY managing this.

nova kite
#

Hahaha I’ve been told 3 is easier idek what they teach there

static cedar
#

Also there's a shit ton of formulas.

nova kite
#

Oh my god

#

Istg if they don’t allow formulas

#

For this semester I emailed all the professors and asked if they allow formulas lmao

static cedar
#

You have a formula for each case.
And there's a lot of cases and you have to YOLO it sometimes.

nova kite
#

Damn that sounds fun hahah

#

Getting your GPA killed by yoloing it

wispy coral
#

how can i add a force in an angle? cant seem to be able to

nova kite
#
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    public Transform player;
    public Vector3 positionOffset;
    public Quaternion rotationOffset;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        transform.position = player.position + positionOffset;
        transform.rotation = player.rotation + rotationOffset;   
    }
}

why does this not work;-;

naive pawn
naive pawn
#

"doesn't work" can mean a lot of things, it doesn't really give us any info

nova kite
#

this sorry

#

doesnt compile

#

it says i cant add the rotationOffset

naive pawn
#

well, read the error

#

yeah

nova kite
#

why haha

naive pawn
#

you can't add quaternions like that

wispy coral
# naive pawn what's your current code?
void OnSprint()
{
    //If on air be able to dash one time
    if(isAbleToDash && !isOnGround)
    {
        //zoom
        rb.AddRelativeForce(Vector3.forward *dashForce, ForceMode.Impulse);
        isAbleToDash = false;
    }
}```
naive pawn
#

do you even need a rotation offset though

nova kite
#

yea

wispy coral
#

im trying to dash on direction of the camera

nova kite
#

so it looks kinda down at it

naive pawn
wispy coral
#

well atleast on the angle it is at

naive pawn
wispy coral
#

so what should i do in that case?

naive pawn
#

also do you want to dash up when you're pointing up? or just the direction of yaw

naive pawn
#

then you probably wouldn't use the camera direction

wispy coral
#

huh, how so?

naive pawn
#

since then you'd be dashing into the air or the ground along with the pitch of the camera as well

static cedar
# nova kite Damn that sounds fun hahah

(ax + by + c)dx = (ax + by + c)dy
That's a linear equation. Check if the inner equation if they are parallel or intersecting and substitute them respectively.

y'' + y' + y = 0
That's a second order linear differential equation. Let y = e^rx and substitute, solve for the constants r. There are cases each and the answer varies if they're complex, two r values, or just one.

y' + P(X)y = Q(X)
That's a first order differential equation. Use Bernoulli's equation.

x dy = y dx
That's a separable equation, move the values to the other side and integrate normally.

naive pawn
#

what's your camera/player setup

tacit compass
#

i dont konw if this would be related to unity but i for sm reason i cant boot up my vscode to start a new project:

error message:

Failed to find dotnet from path with "which dotnet".
Cannot find .NET SDK installation from PATH environment. C# DevKit extension would not work without a proper installation of the .NET SDK accessible through PATH environment. Rebooting might be necessary in some cases. Check the PATH environment logged in the C# DevKit logging window. In some cases, it could be affected how VS code was started.
PATH=/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:~/.dotnet/tools
Using local .NET runtime at "/Users/xin/Library/Application Support/Code/User/globalStorage/ms-dotnettools.vscode-dotnet-runtime/.dotnet/8.0.11~arm64~aspnetcore/dotnet"
.NET server started and IPC established in 982ms
Completed Spawn .NET server (1675ms)
Starting Initialize template service...
Completed Initialize template service (15270ms)
Starting Initialize template service...
Completed Initialize template service (155354ms)```
wispy coral
#

the whole code?

#

or the interactions between the two

nova kite
naive pawn
wispy coral
#

oohhhh ok

nova kite
#

that looks horrendous

naive pawn
#

like, is the camera a child of the player or anything? do both pitch, or just the camera?

naive pawn
static cedar
nova kite
#

calc3 is in bachlor's

static cedar
#

Yep.

nova kite
#

pain

wispy coral
naive pawn
#

so the player is yawing and the camera is pitching, yeah?

naive pawn
cosmic dagger
nova kite
#

that's true

#

how did you know that?

#

i really suck at searching stuff lol

wispy coral
nova kite
#

i searched camera follow unity and the guy is doing it in the update field

naive pawn
cosmic dagger
wispy coral
#

but its not the code that isnt working its just that i cant figure out how to get it to "dash" where the camera is looking at

#

but i can try detailing the problem more

wispy coral
#

so ive been doing it correctly this whole time

naive pawn
#

the code you showed is how you'd do it

wispy coral
#

god damn it

naive pawn
#

yeah so what's the actual issue lol

wispy coral
naive pawn
#

i mean this would be subject to linear drag, if you want a consistent speed you might want to use a different approach

naive pawn
wispy coral
#

exactly

#

im actually so sorry

naive pawn
#

you said you just wanted it to go in the direction of yaw 🤨

wispy coral
naive pawn
#

if you want it to be subject to pitch too, then take the camera's forward direction instead of the player's, since the player doesn't pitch

nova kite
#
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    public Transform player;
    public Vector3 positionOffset;
    public Quaternion rotationOffset;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame
    void LateUpdate()
    {
        transform.position = player.position + positionOffset;
        transform.rotation = player.rotation * rotationOffset;   
    }
}

the solution is to just replace the addition with multiplication???

naive pawn
static cedar
#

The solution I've seen in a YouTube tutorial for dash is to set the velocity every frame for the period of the dash.

naive pawn
#

yeah i do that too

#

isn't subject to drag, feels more like a dash in my experience

static cedar
#

Yep.

naive pawn
#

(though it should be setting the velocity every physics tick, not every frame)

static cedar
wispy coral
naive pawn
naive pawn
wispy coral
#

nvm i dont even know where its dashing now

naive pawn
#

did you do both the changes?

#

if you just make it AddForce, it'll be using world coords

wispy coral
#

ok got it i didnt see the other thing

#

im definitely sleep deprived

#

its like 3 am where im at

naive pawn
#

get some rest lol

wispy coral
#

so information is not getting trough rn

wispy coral
#

its just too fun

naive pawn
#

relatable lamy_pain

wispy coral
#

i do have a question tho, i had to use relative force to move my player but why not there?

naive pawn
#

AddForceRelative is relative to the rigidbody's rotation, which isn't pitching
you can get the same effect with AddForce by using transform.forward instead of Vector3.forward, for the transform that the rigidbody is on
that would still not be pitching, but now you can control what it's relative to by changing what transform is used

wispy coral
#

oooooh got it ok

cosmic dagger
nova kite
#

And btw i searched on google and found nothing about that solution, the only reason I know to use the Euler thing is ChatGPT but people tell me always to not use that

#

So idk what to do

subtle hedge
#

can i update or create a prefab during run time ?

frail hawk
subtle hedge
astral falcon
# subtle hedge modify a boat and letting the player play with that modified boat in the next sc...

Do you want to keep the changes through multiple runtime starts? So save it? A prefab is just some kind of blueprint for a gameobject, that you can spawn out of. What you are doing with that instance (hence the method instantiate) is totally runtime bound. So if you want to save it, you need to create a system that saves and loads your customisation. If its just for one shot play runtimes, you can just keep the boat changes with DontDestroyOnLoad between scenes

#

A preafb cant be changed in runtime, just in editor. ONly the instances can be altered

rich egret
#

using UnityEngine;

public class CameraFollow : MonoBehaviour
{
private Vector3 offset = new Vector3(0f, 0f, -10f);
private float smoothTime = 0.25f;
private Vector3 velocity = Vector3.zero;

[SerializeField] private Transform target;

private void Update()
{
    Vector3 targetPosition = target.position + offset;
    transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime);
}

}

#

why doesnt the camera is not following the player?

stark rune
#

im trying to make a script where you have to collect fuel to power the generator. the generator works the first time i collect the fuel but the second time i click on the fuel the bar doesnt apear or the fuel counter doesnt increase

stark rune
naive pawn
#

also use LateUpdate for camera updates

frail wind
#

how do i make variable for tag?
public TagUnitType BadGuy;

#

i want to make when player collide with gameObject that has "BadGuy" tag, die but i don't know what variable type i should add

naive pawn
#

tags are just strings

frail wind
#

let me test it out

frail wind
naive pawn
#

yeah, how would it know what tag you want otherwise

frail wind
#

it didn't work

 {
     if (collision.gameObject == badGuyTag)
     {

     }
 }```
#

the error say "Operator '==' cannot be applied to operands of type 'GameObject' and 'string'"

naive pawn
#

yeah think about what you're trying to say there

#

you're asking if a gameobject is equal to a tag

#

that's not gonna happen, they're completely different things

#

a gameobject has a tag, so you would compare the tags

#

and there's a handy method for that, CompareTag

frail wind
#

oh how about tag with tag?

#

like string with string

naive pawn
#

yeah that'd work

frail wind
#

let me try

naive pawn
#

huh apparently there's a TagHandle type to avoid string comparisons

#

give that a go, maybe

frail wind
#

ok

#

i bring the new later

flat sphinx
#

i was about to whine how its ass that youre forced to compare with raw strings

swift crag
#

that's why I don't use tags for very much :p

still elm
#

will "scoreTable = ScoreTable.Instance;" work if the gameobjct with the singleton is deactivated?

still elm
#

this is correctly setup right?

#

with singleton

languid spire
#

no

still elm
#

no?

languid spire
#

no!

still elm
#

What am I missing?

languid spire
#

2 things, think about how code runs

rough lynx
#

I mean it looks fine to me

still elm
wintry quarry
#

the DDOL bit probably wants to be inside the else

languid spire
#

no, it's your awake method

still elm
#

I can't see the issue

#

enlighten me

languid spire
#

do you think code stops executing just because you called Destroy?

rough lynx
#

Oh yeah that's the worst bit

still elm
languid spire
#

so what happens after you call Destroy?

wintry quarry
#

It also doesn't have a good reason to be public

rough lynx
#

You should but personally I would get rid of Instance != this BTW since there's no scenario where the singleton will call awake again

still elm
#

🙃 idk

wintry quarry
#

Not forever... just until the end of the function

languid spire
still elm
#

Don'tdestroyonload

languid spire
#

right and what did you just do with this in Destroy?

still elm
#

destroy it

languid spire
#

exactly so you want to DontDestroyOnLoad an object you just destroyed?

languid spire
#

no you do not

rough lynx
#

lol

still elm
#

so it should be in the else statement?

echo ruin
#

Wouldn’t it only destroy itself if there’s already an instance of it?

rough lynx
#

That's what is wanted

languid spire
still elm
still elm
#

so I should be able to call this using:

#

in another script

#

right?

languid spire
#

yes

still elm
#

even if it is deactivated

languid spire
#

yes

rough lynx
#

BTW you might want to change the script execution order for singletons

#

Sometimes I've had to set them to run awake before other scripts

#

(Assuming you try to refer to it in awake)

languid spire
#

Only if you also use Awake in other scripts, Start will always run after Awake

rough lynx
#

I need to use start more icl

#

Awake is always my goto

languid spire
#

You have to be careful with Awake. they run in different frames and Awake will run on an inactive object whereas Start wil not

still elm
# languid spire yes

It seems to work, but the score seems to only sow in Scene view and not in game view haha. So I have to troubleshoot taht

still elm
#

because it seems to not update the scores until after I restart the game

#

so I assume that is the issue

#

Merry Christmas btw

swift crag
#

specifically, Awake runs even on a disabled behaviour

#

It won't run if the game object is deactivated, however

still elm
#

steve is this true that she is saying?

languid spire
languid spire
still elm
#

oh ok

trim swan
#

Okayy so i got this problem (big shocker)
I have tried solving it but I do not know where to look, or what I need to change.
There are 2 NPCs (one a prefab and another a dragged and dropped copy of that prefab,) one named carl, and the other lenny. Both with a trigger that displays their own icon, and hint text (such as "press 'E' to do a thing")
However in the screenshots below, it updates (not based on the first loaded, my mistake) all at the same time
https://pastequest.com/?c1bc281ff309d6e9#G13e4cXSNkwj1XMoRF6w5YA5m6pxB1hEgfPWPLiawf26
Hopefully this is an actual issue and not me being stupid (again[again{again|again|}])

#

if i need to share additional info please tell me. imgoing insaene

#

OKAY SOOOO I serialized a gameobject variable in diatrig, put a random game object into lenny, and another into carl.
I set it to log the name of the object, and lenny logged the name of his.
But carl... CARL LOGGED LENNY'S GAME OBJECT
LENNY'S OBJECT WAS "Floor" AND CARL'S WAS "Player"
FLOOR GOT LOGGED TWICE GRAAHHHH im so close to losing it

cosmic quail
trim swan
cosmic quail
trim swan
cosmic dagger
#

what is DiaTrig and DiaMang?

trim swan
#

diatrig is the box around the NPC that checks if the player is inside and lets you enter dialog mode.
diamang is supposed to handle the text inside dialog mode

#

mang means manager like how calc means calculator

#

new slang

#

diamang works fine, its (most probably) more of an issue with diatrig and the npc prefab

trim swan
#

playerInRange was static

naive pawn
sterile radish
#

hi, i'm trying to make a doodle jump clone and im spawning objects on top of platforms. below is the code for where im spawning the objects but the objects appear inside of the platforms instead of on top of them, why is this?

https://hastebin.skyra.pw/dagahodiwu.pgsql

trim swan
sterile radish
naive pawn
#

seems like your pivot is in the center, so you're putting the center of the object at the top of the platform

#

either offset another half of the object y size, or set the pivot of the sprite at the bottom and offset your collider accordingly

#

also you still have a repeated spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size, you can put that in a variable

#

variables and functions help to reduce repetition, utilize that aspect

#
- float platformSizeX = spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size.x / 2;
- float platformSizeY = spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size.y / 2;
+ Vector2 platformSize = spawnedPlatform.GetComponent<SpriteRenderer>().bounds.size / 2;

  Vector3 spawnPosition = spawnedPlatform.transform.position + new Vector3(
-   Random.Range(-platformSizeX, platformSizeX),
+   Random.Range(-platformSize.x, platformSize.x),
-   platformSizeY,
+   platformSize.y,
    0
  );
wispy coral
#

are you able to move an object with a rigid body with a characterController and still be able to use the physics?

#

i seem to be unable to use physics when moving with a character controller

green flame
#

Hello! I have created this function:

    public void AddUIDocumentStyle(string gameobject_name, string element_id, string property, dynamic value)
    {
        UIDocument uiDocument = GameObject.Find(gameobject_name).GetComponent<UIDocument>();
        var visualElement = uiDocument.rootVisualElement.Q<VisualElement>(element_id);
        visualElement.style[property] = value;
    }
#

And Unity throw me the error "Cannot apply indexing with [] to an expression of type 'IStyle'"

#

Someone has an idea ? ^^

hasty dragon
#

how do i get the distance between 2 transforms?

polar acorn
naive pawn
wispy coral
green flame
wispy coral
green flame
naive pawn
#

few languages have that feature tbh, where dot and bracket notation are interchangeable

swift crag
#

the dynamic keyword is very scary there

naive pawn
#

i can only think of js
even in python it's not the default behavior

swift crag
#

Are you trying to save and load styles?

green flame
#

To have a generic function and use it where I need (less code)

#

No, changing/adding

swift crag
#

in that case, simply do not do this

#

directly reference the property you care about

#

Searching for a game object by name also seems very weird

green flame
#

In C# for each property I need to create a function.. ?

swift crag
#

i don't see any reason to have a function here at all

#

You can write a function to find a UIDocument by name, I guess

naive pawn
swift crag
#

the entire thing smells like a bad idea to me

green flame
#

Not repeating each time the first 2 line + If I need to do something betwen change etc.. it's better to centrilize the function

swift crag
#

you're trying to find a random object by name, then set a property by name

naive pawn
#

"by name" is kind of a bad idea in general

#

it's much easier to mess up, compared to direct references

swift crag
#

names are brittle

cosmic charm
#

apparently @swift crag knows everything ...

rich egret
#

someone have good Jump code for 2d game?

cosmic charm
#

I will be like this one day ...

rich egret
#
    {
        if (isFrozen) return;

        rb.velocity = new Vector2(rb.velocity.x, jumpForce);
    }```
#

Its my current code

swift crag
#

step 1: yell at the computer for years and years

naive pawn
#

i'd probably just have a utility method for that visualElement line
have a UIDocument (or its owning GameObject) as an explicit reference, go through the method to get visualElement, set its style explicitly

swift crag
#

it instantly sets your Y velocity to jumpForce

alpine shore
#

https://assetstore.unity.com/packages/3d/props/rolling-balls-sci-fi-pack-free-297168

I downloaded this asset but it is turning pink
I figured that it is only compatible to built-in pipeline, I didn't make changes to pipelines and I couldn't get it working by changing it from project settings

Anyone has any idea?

Elevate your workflow with the Rolling Balls Sci-fi Pack Free asset from gameVgames. Find this & other Props options on the Unity Asset Store.

cosmic charm
naive pawn
swift crag
naive pawn
swift crag
#

I'm guessing it's a 3D URP project

#

yes, it can be a nuisance :p

#

although I'm already here so it doesn't actually matter

alpine shore
hasty dragon
#

how do i make a rigidbody look at something

naive pawn
hasty dragon
#

i remember a function called lookat or something

alpine shore
polar acorn
naive pawn
hasty dragon
#

what do i do

naive pawn
#

(or set the rotation directly)

naive pawn
#

Rigidbody.rotation is also a quaternion you can modify

green flame
naive pawn
naive pawn
#

...just use static methods?

green flame
#

Of course, I'm a newby x)

naive pawn
#

you don't need a component or a class instance for utility methods that are just input->output

hasty dragon
naive pawn
swift crag
hasty dragon
swift crag
green flame
#

Ok so the whole "application" share all static class. I code for years 100% in JS so yes, the behavior of C# isnt intuitive for me atm but ty each day I learn new things 😄

naive pawn
alpine shore
naive pawn
#

rolling to look at something doesn't really make sense

swift crag
hasty dragon
naive pawn
#

you gotta work with me here...

hasty dragon
naive pawn
#

you're saying it should only yaw and not pitch, correct?

hasty dragon
#

i just wanaa update the orientation on the update method

naive pawn
#

z rotation is irrelevant to "look at thing"

hasty dragon
#

so its immediate

swift crag
#

(you'll just want Material Upgrade)

wispy coral
#

how can i set a variable that i can change during an action or something but then set it back to how it was after that action?

#

i remember that i saw how to do it on a course but i completely forgot

naive pawn
hasty dragon
naive pawn
hasty dragon
naive pawn
hasty dragon
#

thanks for your help

naive pawn
#

bro just answer the question lmao

naive pawn
#

with FromToRotation/SetFromToRotation

  • fromDirection would be the position of your object
  • toDirection would be the position of the target, projected onto the plane that your object is on (or just set x/z equal to the object's x/z)
    with LookRotation/SetLookRotation
  • forward/view would be the position of the target, projected onto the plane that your object is on (or just set x/z, as described above)

the projection only applies if you don't want pitching, which is why i asked

#

if you want help you actually have to give information for us to help with

hasty dragon
naive pawn
#

ok then say so lmao
yaw is horizontal rotation
pitch is vertical rotation

#

do you want make the rigidbody also rotate vertically

swift crag
#

pitch - up-down - X axis - red
yaw - left-right - Y axis - green
roll - tilting - Z axis - blue

naive pawn
#

needs a "forwards" arrow

#

also isn't unity right-handed

steep rose
#

what?

#

right handed?

naive pawn
#

yeah isn't unity's coordinate system right-handed

iron hull
#

Heya, just curious -

If a condition has multiple statements, does it keep evaluating them regardless of if it has a guaranteed outcome?
Ie

if (false && true && true) - would this stop after the first false? or would it keep going and checking the other two regardless of outcome Thonk
I want to assume yes but i'd just like to double check

steep rose
naive pawn
#

oh wait no it's left handed

zenith cypress
#

Unity uses left-handed

steep rose
naive pawn
#

i think the pitch arrow is in the wrong direction

steep rose
#

how

naive pawn
#

it should be going the opposite direction

steep rose
#

thats not right

naive pawn
#

this is a behavior of &&/|| as operators, not conditions as a whole

iron hull
#

Gotcha, thanks! xai_salute

naive pawn
steep rose
naive pawn
#

ah ok

rich egret
naive pawn
#

then the z-rotation is in the wrong direction

tardy whale
naive pawn
steep rose
#

its just a representation of what axes are to make them more clear

#

kind of a nitpick at that point

naive pawn
junior ether
#

If I spawn more prefabs (bullets) how can I Individually move them how can I deal with that?

naive pawn
#

rotations have a positive and negative direction

naive pawn
#

they don't interfere with each other

steep rose
#

correct, this representation is simple to just show them. All I'm saying is it isn't a big deal

naive pawn
#

the gun wouldn't be moving the bullet manually

#

im not saying it is, im just pointing it out lol

tardy whale
naive pawn
rich egret
#

but the function is called

naive pawn
junior ether
# naive pawn each bullet would have its own rigidbody or a script that handles that

I tried like this
in the Shoot script

private void OnFire(InputValue inputValue)
{
    if(inputValue.isPressed == true)
    {
        Debug.Log("FIRE!");
        Bullet = Instantiate(BulletPrefab, Gun.transform.position, PlayerAim.AimTransform.rotation);
        Bullet.name = BulletPrefab.name;

        InitialMousePosition = PlayerCrosshair.GetMousePosition();


        BulletTravel.ActivateBullet(Bullet,InitialMousePosition);
    }
}

and in the BulletTravel script

private float distance;
public void ActivateBullet(GameObject Bullet,Vector3 InitialMousePosition)
{
    StartCoroutine(Travel(Bullet,InitialMousePosition));
}

IEnumerator Travel(GameObject Bullet, Vector3 InitialMousePosition)
{
    distance = 0.1f;
    while (distance < 0.40f && Bullet != null)
    {
        Bullet.transform.position = Vector3.MoveTowards(Bullet.transform.position, InitialMousePosition, distance);
        distance += 0.01f;
        if (distance > 0.40f || Bullet.transform.position == InitialMousePosition)
        {
            Destroy(Bullet);
        }
        yield return new WaitForSeconds(0.02f);
    }
    if (Bullet != null)
    {
        Destroy(Bullet);
    }
}
#

but it says

to this line

BulletTravel.ActivateBullet(Bullet,InitialMousePosition);
#

why?

naive pawn
#

BulletTravel is null, i guess

junior ether
#

BulletTravel is the script thats in the bulletprefab

#

how can it be null if 2 lines above I Instantiate the bullet prefab

#

😭

#

im not really getting the hang of this kekwait

robust condor
#

Is it possible to get all the assets in an addressable asset group?

naive pawn
naive pawn
#

what even is BulletTravel

junior ether
#

is the script inside the bullet prefab

naive pawn
#

you haven't shown how it's defined, and you're mixing cases so i don't even know if it's a type or a variable

junior ether
#

BulletTravel should make the bullet move when spawned

naive pawn
junior ether
naive pawn
#

so ActivateBullet is a static method on that class?

junior ether
#

yes

naive pawn
#

so can there only be 1 bullet at a time?

#

because that's kinda what static implies

junior ether
naive pawn
#

yeah so static doesn't really make sense here

#

wait i didn't read the full snippet

#

ActivateBullet is not a static method there

#

why would you say it was 🤨

junior ether
#

i was confuse too sorry

naive pawn
#

....BulletTravel is a variable, isn't it

junior ether
#

no its a full script

naive pawn
#

you've just named it the same thing as the class because you're using PascalCase where you should be using camelCase

naive pawn
#

you have it as a variable and you have not set it

junior ether
#

I used this

[SerializeField] private BulletTravel BulletTravel;
naive pawn
#

exactly, it's a variable there

#

but that doesn't really make sense

#

if BulletTravel is on each bullet, why should it take a specific gameobject for a random bullet?

junior ether
#

oh

naive pawn
#

why would it be managed centrally?

junior ether
#

ugh Im trying to make the bullet just move after it is being spawned

#

but i guess its not right

naive pawn
#

ActivateBullet and Travel just need to take in initialMousePosition, since it would just be moving the bullet that the component is on

junior ether
naive pawn
#

and then you would trigger ActivateBullet on the bullet that youve created, not some random detached BulletTravel

#

i think you need to step back and think about the flow of logic here

junior ether
#

so I creat the bullet

#

which is Bullet

#

and I want to somehow call the script thats in the bullet to make it move after being spawned

naive pawn
#

actually first off go and fix your casing so you aren't shadowing random stuff and confusing classes with variables

#

that's doing you no favors

junior ether
#

so how to use cases corect

#

wich case for class and which for variable

#

camel case for variables?

swift crag
#

yeah

junior ether
#

ight

rich egret
naive pawn
swift crag
#

the default force mode for AddForce is meant to be a continuous force

naive pawn
#

you need to preserve the y velocity

swift crag
#

i.e. you call it every FixedUpdate -- do this instead

rb.AddForce(Vector2.up * jumpForce, ForceMode.Impulse);

you were also using the current X velocity for some reason

#

don't do that; just apply a force straight up

#

Also, yes, the more pressing problem was that you immediately set your own velocity, which completely overrides the force you added

junior ether
#

can i get the script component of a game object?

naive pawn
#

yes, GetComponent

junior ether
#

ok but how is the component name the scripts name?

naive pawn
#

...what?

#

you set it

#

that's kinda how c# works

#

the actual name of the file isn't important here, what's important is the name of the class

#

though with your case, you could just make bullet typed as BulletTravel instead of GameObject, then the value you get back from Instantiate would be the BulletTravel you could call Activate on

wispy coral
#

how can i remove the maxLinearVelocity on an rb?

junior ether
#

i did the camel case and tried like this

naive pawn
#

do you mean removing the restriction?

wispy coral
naive pawn
#

probably set it to infinity

wispy coral
#

alright

naive pawn
junior ether
#

ok

naive pawn
#

also bullet could probably be a local variable instsead of a class variable

naive pawn
#

im pretty sure bullet.name = bulletPrefab.name is unnecessary, it'll already have that name

languid spire
naive pawn
#

ah, right

junior ether
#

heck yess it works now

#

i understand it now

#

thx man for the help

rich egret
#

@naive pawn @swift crag Thank you!

midnight jolt
#
if (!pair.Value.Element)
{
    Button compound = Instantiate(compoundButton);
    compound.gameObject.SetActive(true);
    compound.name = pair.Key;
    compound.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = pair.Key;
    compound.transform.SetParent(content.transform);
    compound.transform.position = new Vector2(0, y);
    y = y + 40;
}```

The position of the instantiated object should be 0, 0 (initial y value = 0)
Meanwhile the button in question:
#

like what

wispy coral
#

is there a way to set a rigid bodies max velocity on select axis? tried just setting a max speed but moving while in the air made it impossible to fall

naive pawn
#

every fixedupdate

wispy coral
frigid plinth
#

hello every one
i am wondring how can i check if unity and cs code are working together cz i feel like they aren't

wispy coral
#

with mathf?

naive pawn
#

yeah

wispy coral
swift crag
naive pawn
naive pawn
wispy coral
#

but its with the mathf thing no?

frigid plinth
naive pawn
#

!ide

eternal falconBOT
frigid plinth
#

thx

naive pawn
swift crag
# swift crag here's the general way to do it!
Vector3 targetAxis = Vector3.up;

Vector3 original = rb.velocity;

Vector3 aligned = Vector3.Project(original, targetAxis);
Vector3 remainder = Vector3.ProjectOnPlane(original, targetAxis);

aligned = Vector3.ClampMagnitude(aligned, 10);

Vector3 result = aligned + remainder;
wispy coral
swift crag
#

Take the original vector. Split it into two pieces:

  • The part that lines up with your axis
  • The part that doesn't
#

Do whatever you want to those two parts, then put them back together

naive pawn
#

now that, that's math

swift crag
#

This works for any direction, not just cardinal directions

wispy coral
swift crag
#

I try to avoid touching specific vector components whenever I can

#

so that my code winds up working even if gravity is going, say, 30 degrees to the left

#

and the player is spinning like a top

naive pawn
#
[SerializeField] Vector3 maxSpeeds;
Rigidbody rigidbody;

void FixedUpdate() {
  Vector3 vel = rigidbody.linearVelocity;
  vel.x = Mathf.Clamp(vel.x, -maxSpeed.x, maxSpeed.x);
  // repeat for y & z
  rigidbody.linearVelocity = vel;
}
swift crag
#

The Vector3 and Quaternion methods can be really nice

#

I almost never do triginometry

naive pawn
#

just as an example

naive pawn
#

i'd recommend a general solution like fen's

wispy coral
#

ill try both and see which one works better for me and which one i truly understand

naive pawn
#

i can't say i recommend fen's directly since it's too late for me to understand any math lmao bruh

midnight jolt
#

oh hi fen

wispy coral
#

same thing as before

naive pawn
wispy coral
#

i see, ill note it down

naive pawn
#

a similar idea would be fine for horizontal only, with the same restriction

wispy coral
#

got it

#

honestly physics based movement is just so cool but its too much work

#

some parts are simpler

#

other

#

not so much

unborn urchin
#

how come when using Unity netcore, if I start an instance of the game as the host, and then move to the top left corner, and on my clone of the game I join as a client, itll spawn the character in where the host left off but there is only one player on the screen? shouldn't there be two?

wispy coral
#

does impulse force mode apply force everytime or just once when using update

nova kite
#
using UnityEngine;

public class CameraFollow : MonoBehaviour
{
    public Transform player;
    public Vector3 positionOffset;
    public Vector3 rotationOffset;

    // Start is called once before the first execution of Update after the MonoBehaviour is created
    void Start()
    {
        
    }

    // Update is called once per frame
    void LateUpdate()
    {
        transform.position = player.position + positionOffset;
        transform.rotation = Quaternion.Euler(rotationOffset) * player.rotation;
    }
}

this code looks correct right?

#

hey molt haha

wispy coral
#

wassup

nova kite
#

just woke up straight into coding lol

wispy coral
#

thats great same thing here

nova kite
#

what is addon?

mystic sinew
nova kite
#

ohh

#

wait for camera follow?

slender nymph
#

obligatory: use cinemachine

mystic sinew
#

i use cinemachine for 2D , but i dont have how it works in 3D

steep rose
#

cinemachine would be good but you can easily make one via scripts

nova kite
#

i was trying to via a script but it doesnt really work

#

the rotation calculation messed it up

#

i want to achieve it via script so i learn too haha

#

wait nvm it does work i just had to put different numbers for some reason

#

i thought i could just copy paste the offset from where i positioned the camera already in the scene behind the player

robust condor
#

Is there a difference in DontDestroyOnLoad(this) and DontDestroyOnLoad(gameObject)?

rich egret
#

Someone know why i cant jump?

    {
        if (IsGrounded()) 
        {
            rb.AddForce(new Vector2(0, jumpForce), ForceMode2D.Impulse);
            highestJumpY = transform.position.y;
            isJumping = true;  // Mark as jumping
            animator.SetBool("IsJumping", true);
        }
    }

    private bool IsGrounded()
    {
        return Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, groundLayer);
    }```
swift crag
#

What is groundLayer?

mystic sinew
swift crag
#

You should add a few log statements to check if Jump is running at all and if IsGrounded is returning true

rich egret
swift crag
#

okay, but what is the variable's type?

#

how did you declare it?

rich egret
wispy coral
#

how can i make counter movement with a rigidbody so i dont go slip and sliding when ever i release WASD

unborn urchin
#

can someone help me understand where this error is coming from

#

im guessing something here is wrong for my player prefab?

rancid badger
#

hi everyone, anyone has experience with dotween?

using UnityEngine;
using DG.Tweening;

public class PauseController : MonoBehaviour
{
    [SerializeField] private GameObject pausePanel;
    [SerializeField] private GameObject blockingPanel;
    [SerializeField] private float animationDuration = 0.5f;
    private bool isPaused = false;
    private RectTransform pausePanelRect;
    private Vector3 originalScale;

    void Start()
    {
        pausePanelRect = pausePanel.GetComponent<RectTransform>();
        originalScale = pausePanelRect.localScale;
        pausePanelRect.localScale = Vector3.zero;
        pausePanel.SetActive(false);
        blockingPanel.SetActive(false);
    }

    public void OnPauseButtonPressed()
    {
        isPaused = true;
        Time.timeScale = 0f;
        pausePanel.SetActive(true);
        blockingPanel.SetActive(true);
        pausePanelRect.DOScale(originalScale, animationDuration)
            .SetEase(Ease.OutBack)
            .SetUpdate(true)
            .OnComplete(() =>
            {
                Time.timeScale = 0f;
            });
    }

    public void OnCloseButtonPressed()
    {
        isPaused = false;
        pausePanelRect.DOScale(Vector3.zero, animationDuration)
            .SetEase(Ease.InBack)
            .SetUpdate(true)
            .OnComplete(() =>
            {
                pausePanel.SetActive(false);
                blockingPanel.SetActive(false);
                Time.timeScale = 1f;
            });
    }
}

the first time i enter in play mode, i click pause button, time scale goes to 0, but nothing shows then if i press again pause button the pause panel shows without animation, then if i unpause and pause again, everything works as it should

#

i also tried to call init method in start but it doesnt help

frigid plinth
#

can't find the option of the "quiz script" in the function list even though the script is added to the canvas as a component

swift crag
#

Show the inspector for the "quizCanvas" object

frigid plinth
swift crag
#

This indicates that Unity is having a problem importing your script

#

Do you have any errors in the console right now?

#

hit "Clear" to remove anything that isn't a compile error

frigid plinth
#

CS0246 this bad boy who won't leave me alone

swift crag
#

screenshot the entire error message

#

(i do not remember that error code)

frigid plinth
swift crag
#

Is your code editor not showing you any errors right now?

#

If so, you need to fix that first.

slender nymph
# frigid plinth

make sure your !IDE is configured so you don't make silly spelling mistakes like that

eternal falconBOT
frigid plinth
#

mb all caps

swift crag
#

Screenshot your entire code editor window for me.

frigid plinth
slender nymph
#

wait, it's configured

#

fix that error

languid spire
frigid plinth
swift crag
#

no, it did not

#

not the way you wrote it!

languid spire
#

he spelt it correctly

slender nymph
frigid plinth
#

im sure im missing somthing

frigid plinth
slender nymph
#

yes, you're missing the correct spelling

swift crag
#

C# doesn't care if you wrote Sprote or sprite or Psrite

#

none of these are exactly Sprite

frigid plinth
#

i seeeeeeeeeeeeeeeee

swift crag
#

Generally, type names are PascalCased

frigid plinth
#

I'm so grateful for u guys
this is actually life saving for me

#

on g

slender nymph
#

and before anyone points out "int, string, float" etc not being PascalCase, those aren't actually the type names, those are aliases

mystic sinew
robust condor
#

I'm trying to load my UI toolkit from addressables: Addressables.LoadAssetAsync<VisualTreeAsset>(assetAddress + ".uxml"); ... but it can't find it, also tried without the .uxml. I also tried having simplified names etc. but it just can't find it

#

And the report says it's in there

slender nymph
robust condor
#

Is ded

slender nymph
#

not how discord works. ask your question in the appropriate channel and when someone who is familiar with the topic sees it they can answer it. otherwise you're just creating noise in unrelated channels and your question ends up getting drown out by other questions

swift crag
#

you don't want me trying to answer your addressable questions in here 😄

#

(i will do a terrible job)

austere osprey
#

alright so i'm trying to make a 2d gun that has a massive recoil that knocks the player backwards when you fire it, and the vertical knockback is completely fine but for some reason there is no horizontal knockback at all, it is super weird
the code is here https://hastebin.com/share/dasaxisopo.csharp

mighty compass
#

Or all lower case

#

I guess just primitives are

slender nymph
swift crag
#

indeed, the proper name for float would be System.Single, for example

mighty compass
#

HIH

#

HUH

#

why

swift crag
#

convenience, I suppose

mighty compass
#

What is the purpose of abstracting a primitive data type to the same thing with a dif name lol

swift crag
#

why do we give multiple names to things?

mighty compass
#

Just sounds like purposely reducing performance

austere osprey
swift crag
slender nymph
mighty compass
slender nymph
swift crag
#

you're just making this up

austere osprey
mighty compass
#

Nevermind lol, I have no idea what this system. Stuff is

fierce saddle
#

hi guys

swift crag
fierce saddle
#

HAPPY christmas everyone

swift crag
#

Sum it up with your desired velocity, and have it quickly return to zero over time

slender nymph
austere osprey
#

aight i'll try that

mighty compass
slender nymph
#

and System.Single is a struct called Single that is within the System namespace. float is just an alias for that. much like Applied_Algorithms is an alias for you, if i were to say "tell Applied_Algorithms about namespaces" it would be clear I was referring to you, but that's not your actual name, just like float isn't System.Single's actual name
you can also set up your own local aliases with a using directive, it has no impact on performance, it just allows you to refer to a type using a different name. this is a common solution when attempting to use the Random class when both the UnityEngine and System using directives exist in a file.

#

you can also add global aliases in C# 10 the same way (but just adding the global modifier) but unity doesn't support that yet

swift crag
#

i can't wait to see what kinds of insane problems people manage to cause with that notlikethis

slender nymph
#

global using var = System.Dynamic; angerjoy

swift crag
#

fortunately that doesn't exist

scarlet hull
#

how can i do X animation when state is 4

swift crag
#

dynamic just means System.Object with special treatment

swift crag
#

If you want a bunch of numbered states, consider using an int parameter

scarlet hull
swift crag
#

you should be using a blend tree for things like this

scarlet hull
#

i dont get it how can manage greater/lesser with things like this

scarlet hull
swift crag
#

It lets you pick from many animations based on one or two parameters.

#

and in 3D (or whenever you're doing bone animation, really), it smoothly blends between the animations

scarlet hull
#

alight ill check it out

#

thanks

mighty compass
#

!ide

eternal falconBOT
forest summit
#

How would i go about applying force to an object through the direction of a raycast? currently i have a script that applies the force in the "normal" of the object but it doesnt have the physics i want

swift crag
#

presumably you already know the direction of the raycast!

#

Perhaps you're asking how to apply the force at a specific point on the object, instead of its center of mass?

#

that'll make an object tip over if you push on its top, for example

scarlet hull
swift crag
#

and pick them in the blend tree's inspector

#

(you're just using "state" twice at the moment)

scarlet hull
swift crag
#

It blends between them based on how close they are to the parameter values

scarlet hull
#

ah i see

forest summit
#

appreciate it

#

this is the current code that i have

#

RaycastHit ray;
Physics.Raycast(fpsCam.transform.position, fpsCam.transform.forward, out ray, 5f);
ray.rigidbody.AddForceAtPosition(-ray.normal * hitForce, ray.point, ForceMode.Impulse);

#

its still seems to apply force at the normal

swift crag
#

well, yes, you're using -ray.normal as the force direction

forest summit
#

or atleast not at the point of the raycast

#

ah

swift crag
#

don't do that

forest summit
#

lmao

#

sorry i didnt see that

swift crag
#

also, your code doesn't check if the raycast missed

#
Ray ray = new Ray(fpsCam.transform.position, fpsCam.transform.forward);

if (Physics.Raycast(ray, out var hit, 5f)) {
  // ... 
}

I like to construct a separate Ray to declutter the raycast call

#

and you can declare the RaycastHit variable as you call the method

forest summit
#

i see

#

thank you

swift crag
#

you also need to check if the thing you hit has a rigidbody

#

it might just be a static collider

#

(by "Static collider" here I mean any collider that isn't attached to a rigidbody)

scarlet hull
#

i decided to use 1D system

swift crag
#

I guess that...kind of works

#

But why not just use a 2D blend tree? You have an X direction and a Y direction

#

this seems like a very obvious place to use two parameters

scarlet hull
#

i find this more simple and easy to use

#

im not animating anything big

#

althou

#

still thats it? do i need to do anything more

#

for some reason animation still isnt working correctly

polar acorn
scarlet hull
#

i can see that state is being changed but

#

character is only going upwards

mighty compass
#

Can I write my own server in c++ that interprets data from unity cient and sends it over a network?

polar acorn
#

Why are you using a 1D Blend Tree for two dimensional movement?

swift crag
mighty compass
#

Im just wondering how I would get output from unity into a different file

#

from a unity client

scarlet hull
swift crag
#

but it's not a great experience

polar acorn
# scarlet hull if both can work why not?

It's going to be blending animations based on the value between your defined endpoints, and you're probably getting incorrect blending leading the animation not playing

mighty compass
#

I just heard there's a lot of networking issues with unity's built in networking, so I wanted to make my own

scarlet hull
#

alight then ill use 2d

polar acorn
mighty compass
#

Im just wondering how I can output to a file in unity

polar acorn
mighty compass
#

oh lol, thanks

polar acorn
swift crag
#

A lot of stuff is just "however you'd normally do it"

#

The main differences are when you want to interact with Unity objects

#

(e.g. you must be on the main thread)

mighty compass
#

I always think theres some specia way to do things in unity, but sometimes there isnt

swift crag
#

unity has much less power over your code than you might think!

#

I used to be stuck in that line of thinking

#

notably, I thought that it somehow turned my references into null with Magic Powers

#

(no, that's just a custom equality operator on UnityEngine.Object

mighty compass
#

it just sets them to null?

#

lol im not experienced enough in unity to understand that xdD

#

Ive written a few client and server programs in python, I think I should be able to do this i c++

scarlet hull
polar acorn
# scarlet hull

Your blend tree appears to use the state parameter that doesn't exist

scarlet hull
#

is this

#

how it supposed to be

polar acorn
#

If those are the parameters you want to use for X and Y

mighty compass
#

I'm wondering if should make the server literally just a separate program, then make some logic in unity that searches for it's ip address and port, so the server logic is completely separate from the unity project. Doe that sound like a normal thing to do? lol

scarlet hull
polar acorn
scarlet hull
#

where can i change that?

polar acorn
#

You should consider reading the error messages

mighty compass
#

Im just wondering how I would do additional checking of the gamestate on the server

polar acorn
swift crag
scarlet hull
scarlet hull
#

summoned as float in the script

mighty compass
#

oh my bad I just saw the networking thread

scarlet hull
#

i fixed it

swift crag
#

They look identical in the parameter list, which is a nuisance

scarlet hull
#

but animation is still not working

#

character is only playing upwards walk animation

polar acorn
#

Do you ever actually transition into the blend tree in the animator

scarlet hull
#

like this right

polar acorn
#

So why would you expect it to ever do anything else

swift crag
#

Transitions out of the Entry state are only considered when you start the animator

#

or when you go into Exit

#

notably, this means you are stuck in "walk up" forever

#

also, if you leave Blend Tree for any reason, you'll never get back, ever

scarlet hull
#

so i need to connect up anim to blend tree right?

#

and thats it

polar acorn
#

Doesn't the blend tree handle your directional animations?

scarlet hull
#

i got it

#

deleted others

#

thanks for the help

mighty compass
#
        if (doorToggled == false){
            doorToggled = true;
        } else {
            doorToggled = false;
        }

        if (doorToggled){
            float currentRot = 0;

            // Set adjusted correct angles.
            if (currentRotEuler.y <= 90 && currentRotEuler.y >= 0){
                currentRot = 180;
            } else if (currentRotEuler.y <= 180 && currentRotEuler.y >= 90) {
                currentRot = 270;
            } else if (currentRotEuler.y <= 270 && currentRotEuler.y >= 180) {
                currentRot = 360;
            } else if (currentRotEuler.y <= 360 && currentRotEuler.y >= 270) {
                currentRot = 90;
            }
                transform.rotation = Quaternion.Euler(0, currentRot, 0);

        } else {
            transform.rotation = Quaternion.Euler(0, currentRotEuler.y, 0);
        }
    }``` why door no move
teal viper
mighty compass
#

kk thanks!

#

do I have to have the transform.rotation within an update?

#

the method is called within an update in another script already

plucky kernel
#

I have an issue that I'm really unsure about how to solve. This is for a school project and I'm still very new to Unity. The project is that you drive a car around a terrain and pass through Waypoints, where the goal is to not run out of time. Every time you pass through a Waypoint, that Waypoint moves itself to a random position and 10 seconds gets added to the timer.

I have a spawn manager script, WaypointSpawnManager, that I've realized is unnecessary, but anyway, it spawns Waypoints by calling the WaypointScript's Spawn method. This method instantiates a new Waypoint ten times. This Waypoint is a prefab that I have dragged out and hidden in the game somewhere, and it has a component of itself and the GameObject that houses my Timer script. These Waypoints have an OnTriggerEnter method, where each time the player collides with one, the Waypoint in collision moves to a random position and adds 10 seconds to its Timer component, which is the one, singular Timer GameObject in my scene.

My issue is that the collided Waypoint randomly moves to a position like it should, but 10, 20, or 30 seconds is added to the timer, nothing more, nothing less and I'm very unsure as to why
WaypointScript hastebin link: https://hastebin.com/share/opemapibix.csharp

Forgot to mention that for debugging, I'm not sure how I would fully debug this, so I've driven my car slowly to see if it was colliding with the same Waypoint multiple times. It still randomly added either of those times. I've checked the coordinates of each Waypoint to see if it was colliding with another Waypoint when it randomly changes its position, but it's too fast for me to check that

teal viper
teal viper
plucky kernel
#

alright, thank you

#

omg it's how the free car asset I downloaded was put together. The waypoint detects one, two, or all of its SportCar prefab, Body GameObject, or its own Collider GameObject. Body is a child of SportCar and Collider is a child of Body. Do you know how I should deal with that so only one...thing...is being detected for collision? I have no clue what to do with something like that. Are there any kind of images that I should send as well?

untold shore
#

Hey, I know there is a lot of people saying "GetComponent" is really bad since time spent loading, what are other methods that you can use? Example, trying to get my script to look into another script to find a value, what would you use for that?

plucky kernel
untold shore
teal viper
plucky kernel
#

I think I can think of a way about how to do that, thanks!

wispy coral
#

how can i make a rigid body go up damn stairs

wintry quarry
wispy coral
wintry quarry
#

As always, you can freely assign the mesh that MeshCollider uses.

wispy coral
#

didnt know, thanks!

untold shore
#

Thank you!!!!

waxen pendant
#

why is renderer and collider bounds.max not giving the top point on the mesh or collider?

Vector3 topPoint = GetComponent<Renderer>().bounds.max;
Debug.DrawRay(topPoint, transform.up * 100f, Color.yellow);
wintry quarry
#

and not the actual collider itself

waxen pendant
#

is there any way to get the point without calculations

wintry quarry
wintry quarry
#

and use its position