#💻┃code-beginner

1 messages · Page 314 of 1

patent compass
#

hello I am trying to read json file from resources by using resources.load but getting null error. even though the file is present in the resouce folder.
TextAsset jsonFile = Resources.Load<TextAsset>("cubeData.json");

slender nymph
acoustic arch
#

is there a way i can make a class thats inherited be able to be referenced by the base class?

#

like for example if I had public class Fireball : Ability

misty coral
#

I have an object that is following the players movement, how can I use rotateTowards to make it move 15 degrees?

timber tide
acoustic arch
wintry quarry
wintry quarry
timber tide
#

public Ability Ability

wintry quarry
#

you can put any Ability there

acoustic arch
#

👍

misty coral
wintry quarry
#

You can achieve gradual rotation in many ways.

#

do you mean around the x axis?

#

Rotations happen around axes, not along directions.

misty coral
wintry quarry
#

over what time period? Under what circumstances? With what other code in action?

misty coral
#

no other code handles the objects rotation, but it does interfere with the objects positioning

delicate portal
#

Whats it the solution when the instance is null?

wintry quarry
#

the only thing to do if it's null is say "oops the lobby manager is null, we can't create a lobby"

misty coral
#

I want it to rotate along the x axis of the object

#

but idk how to access that as a variable

wintry quarry
small mantle
#

Is there a way to make tangled code more readable easily?

misty coral
#

never heard of it

wintry quarry
#

code that can pause in the middle to allow time to pass

#

in this case yield return null; allows one frame to pass

misty coral
wintry quarry
normal smelt
#

Do anyone know how to change a rigidbody's gravity scale via a script ?

normal smelt
#

Thx

normal smelt
#

Its perfect since my game is in 2d

willow scroll
#

You can change the 3d gravity by applying a static force in the desired direction

delicate portal
#

It says it is null.

#

However I set it in awake

wintry quarry
#

or it's never running

#

e.g. because that script doesn't exist in the scene

delicate portal
misty coral
wintry quarry
misty coral
#

I am already using moveTowards to move an object back for a set amount of time...

#

should RotateOverTime()s time be set to that number?

delicate portal
wintry quarry
#

I have no idea whatr that function is

wintry quarry
#

so I have no idea what it does

wintry quarry
#

that's probably what's happening

delicate portal
#

I also tried start

wintry quarry
#

start would be better

misty coral
delicate portal
rich adder
#

ohh I saw lobby idk lol

misty coral
delicate portal
wintry quarry
#

Then you don't have a LobbyManager in the scene

delicate portal
#

I actually deleted it without a reason

ocean dove
ripe flame
#

Is there a way to play an audio file from a certain point?
I have music playing in the main menu (scene 1) and I want the song to continue in the actual game (scene 2) with a different audioSource so I can create a fadeout effect

ripe flame
#

whoa that was fast, thanks a lot I will read through that

wintry quarry
ripe flame
#

thanks legend

delicate portal
#

I have a script and with that I can move object with my mouse when dragging them. But whenever I click and drag an object, since the game is 2d, it detects the object behind them ocassionally. Why is that?

glass ivy
# misty coral MAN I WISH I KNEW THAT EARLIER LOL

back in the early days of Unity 2.6 there a kid (forest something) who made all their demo projects, he used coroutines a lot so we learned from that. nowadays examples are super convoluted so you miss a lot of the niceness (and also coroutine tend to explode in your face at scale haha)

#

lol

spiral narwhal
#

Should I put assertions in UNITY_EDITOR only? I.e. what happens in a build? Because I guess the best thing would be to try to move on, but I believe failed assertions block the program flow like exceptions right?

honest haven
#
         {
             activeBattlers[currentTurn].PlayParticleEffect(activeBattlers[currentTurn].zoneHighlight);
         }``` Ho can i make this pre fab follow the player with out making it a child?
spiral narwhal
#

It is easier to have it be a child tho

honest haven
#

ok cheers

zenith cypress
#

tldr; they are enabled by default in a debug build. A built game, that isn't that, won't have them, so you don't need the conditional for em.

spiral narwhal
#

Awesome thanks for the reply

honest haven
#

what does this mean, i understand that its tell me to change it, but im just trying to destroy a instatiated game object (Particle)

#

i then get this if i use DestroyImmediate(activeBattlers[currentTurn].zoneHighlight, true);

rich adder
#

don't use DestroyImmediate. thats for editor only

honest haven
#

yh my bad, thanks

queen adder
#

i dont understand the problem

slender nymph
#

get your !IDE configured. then make sure to actually save you code so unity recompiles it

eternal falconBOT
slender nymph
#

when you save the code you should see a new error

queen adder
#

how do i switch to vs code?

slender nymph
#

well you'll have to configure that too, and it is notoriously harder to get configured and get it to stay configured

queen adder
#

wait

#

it said i needed to install an update or smth is that the problem

slender nymph
#

you need to follow the guide to configure visual studio

#

complete all of the steps to get it configured

queen adder
#

ok

timber tide
#

What do people usually do when they want to prevent a more derived class from being inserted into an inspector field? I've been deriving a similar class copy to overcome this limitation but it feels like such a janky solution.

#

or is there some attribute im overlooking here

ivory bobcat
cosmic dagger
#

!code

eternal falconBOT
timber tide
misty coral
#

How can I make the moveCamera() actually move the camera

#

do I need to use courtine or whatever its called?(if so how)

stuck palm
#

how can i check if any controller connected has the button B pressed?

ivory bobcat
timber tide
#

AbstractProjectile -> CastableProjectiles

#

so basically I branch from AbstractProjectile into an empty class such that I call them TriggerProjectiles but really it's an empty class /shrug

#

So now CastableProjectiles has components of TriggerProjectiles it can trigger, but if I were to have a non-abstract Projectile class instead it would allow CastableProjectiles to have CastableProjectiles

#

so yeah, some editor jankyness to get around

summer stump
# misty coral

A coroutine is not needed. You have to just actually move it. Nothing in that method has anything to do with movement, just rotation.
There are tons and tons of tutorials on how to move objects online.
I'll just say, do camera movement/rotation in late update

summer stump
green ether
#

just wondering

#

camera movement in lateUpdate I mean

stuck palm
#

how can i check if any controller connected has the button B pressed?

green ether
summer stump
# green ether why is that?

It is after the internal animation update and is IMMEDIATELY before rendering

It happens after most things have moved too, and after input would be captured

stuck palm
green ether
#

@stuck palm

#

Check that maybe?

#

I uploaded an example of a simple input system I have a few days ago

green ether
stuck palm
green ether
#
using UnityEngine.InputSystem;
#

I think

#

I only just started using the new Input System

#

So I am not entirely sure how it all works yet. But what I posted there works on controller and pc

stuck palm
#

i dont see it there

#

i thought u made that class yoursel

green ether
#

let me check really quick

stuck palm
#

cus it looks very convenient for sure

green ether
#

Dont have my project open was about to go to bed xD Gimme a sec to launch it

stuck palm
#

but i canat find it

stuck palm
green ether
#

no worries xD

#

Now im curious myself cause I still need it

#

Did that a few weeks ago just to make sure some controller inputs work

ivory bobcat
# timber tide so basically I branch from AbstractProjectile into an empty class such that I ca...

The dirty Java solution would be to use interfaces with conflicting function definitions but I'm not certain if c# can do this. In Java, using multiple interfaces, you could prohibit inheriting other specific interfaces by having the interfaces require specific methods but with different return types. As return types aren't a part of a functions definition, they would conflict in that the other interface has already defined the function but with a different return type - making it impossible to implement both.
(what a Stack overflow suggestion stated, at least https://stackoverflow.com/a/50534086) Hacky ol Java.

green ether
#

Make sure to check "Generate C# Class"
on your input Action Asset

ivory bobcat
misty coral
#

I am using a boolean to allow for it to work

#

but it doesnt work

green ether
misty coral
#

it worked like once than i changed something and now im lost

summer stump
timber tide
summer stump
#

MoveCamera is never called. So it will never run

#

A method that is not called is never ever run...

misty coral
#

I call it in another method

green ether
timber tide
#

Problem is it's per seat so I'll be buying it for my mate and friend haha

green ether
#

dont have it myself but was thinking about it

#

Ahhh

#

Yeah

misty coral
stuck palm
green ether
#

Its the Input Actions Asset

#

Autogenerated c# class

stuck palm
#

appears to be this

green ether
#

yes

stuck palm
#

i see

green ether
#

He called it controls

stuck palm
#

actually its fine i can just watch the video

green ether
stuck palm
#

ohhh okay

#

alright thanks bro

green ether
#

No problem!

#

That video probably explains it alot better so might aswell watch it)

#

Also gonna have to rewatch it once I implement the rest of my controller inputs)

summer stump
misty coral
#

alr i got it working... ish

stuck palm
#

thanks this is very helpfyl

misty coral
summer stump
#

Could have an empty gameobject that represents "base" rotation, and just set the camera to the same as that when you want

misty coral
#

oh wait

#

i misinterpreted what you just said

misty coral
#

So after the thing rotates I try to rotate it back

#

you can see its commented out right now

#

because for some reason even without calling it it snaps back to the origin

#

where am I setting the rotation I dont understand

#

I figured out this is why its snapping

#

and also that my code to move it back does not work....

burnt rampart
#

kinda silly question, but is everything written in C# part of the ".NET framework"? Just trying to understand some documentation better

proven sail
#

hello guys. i need a little help here.

proven sail
#

sorry im new .(

#

now i can jump infinitely i just wanted to make a double jump thing

slender nymph
#

you need to get your !IDE configured

eternal falconBOT
proven sail
#

thank you i did it

#

but does it solve the problem?

slender nymph
#

no, but it will at least point out your compile error so you can fix it

proven sail
#

thank you dude

#

so how can i fix the infinitejump problem?

slender nymph
#

do you see the compile error underlined in red in your code now?

proven sail
#

nope

#

and it updates quickly

#

thankssss againnn

dusk wren
#

I have a model I'm trying to import into Unity and define as a Humanoid.

I get an error saying it has to have at least 15 bones.

Is there a way I can import custom humanoid models with any amount of bones? I have the animations all complete as well

proven sail
slender nymph
#

🤖 but is your IDE configured yet

slender nymph
proven sail
dusk wren
slender nymph
proven sail
#

no problem right?

slender nymph
#

yeah not configured

proven sail
#

how !!!!

slender nymph
#

follow the entire guide to configure visual studio. after you have completed the steps regenerate project files and restart it

burnt rampart
#

getting it configured will save you a lot of suffering in the future

proven sail
slender nymph
#

after you do all that open the solution explorer inside of visual studio and screenshot the entire window

slender nymph
acoustic arch
#

i apologize in advance for the scripts organization its just a prototype 😭

main anchor
#

how would i make the loading screens for my game stay for a certain amount of time, currently they disappear after around half a second which i don't really like, is there a way to make them stay for about 5 -10 seconds?

eternal needle
serene barn
#

!code

eternal falconBOT
proven sail
slender nymph
#

does it show you the error in your code now?

proven sail
summer stump
proven sail
#

this is ok right?

main anchor
proven sail
slender nymph
proven sail
#

what is this???

slender nymph
#

the error i was referring to

eternal needle
slender nymph
#

you hadn't saved before so it wasn't showing up in unity (also why you were still able to play)

proven sail
slender nymph
#

yes, that is not valid code

proven sail
summer stump
slender nymph
eternal needle
summer stump
proven sail
summer stump
#

Y = this thing and this thing

#

How does that make sense?

slender nymph
proven sail
#

dude pleasseeee i need to see my project starting until i go for 6 months

proven sail
summer stump
eternal needle
# acoustic arch alright ill try it

another thing i notice could be related, in update you call BattleRuntime every frame if some condition. this method also calls InvokeRepeating("EnergyGrowth", 0, 1);. This will be extremely laggy quickly, if its not an infinite loop, your game is freezing because its running way too much

proven sail
#

i will make it work right now!

slender nymph
# acoustic arch alright ill try it

note that if you have the debugger attached, when the editor freezes you can Break All in the debugger and inspect what is happening on the main thread

acoustic arch
acoustic arch
proven sail
#

?? is this ok???

proven sail
#

nope im still jumping infinitely...

slender nymph
# proven sail ?? is this ok???

no for two reasons, one the logic doesn't make sense. and two, you clearly have a compile error (hence the red squiggly line)

proven sail
summer stump
slender nymph
#

because they don't know how to code so they are attempting to code by approximation

proven sail
slender nymph
#

stop wasting your time and go learn the basics

proven sail
#

yes i dont know how to code but im trying to learn

#

i had a working game on godot but i converted to unity thats why learning is so hard rn

summer stump
#

Then do this
!learn

eternal falconBOT
#

:teacher: Unity Learn ↗

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

summer stump
#

Just do essentials and junior programmer
THEN come back to your game

proven sail
#

😦 just double jump please

summer stump
slender nymph
acoustic arch
eternal needle
#

"just one thing" until the next thing

proven sail
#

sorry

#

i think i switch back to godot unity is way harder

summer stump
#

It's not like you can just switch without relearning some things

slender nymph
#

the issue here isn't really even an issue of unity vs godot. it's a matter of reading your own code so you can see the glaring flaw in the logic

proven sail
#

i create theese

summer stump
proven sail
#

if the jump button is pressed and i can move and my remaining jumps are greater than 0 i jump and the jumps remaining gets -1

#

right?

summer stump
#

Correct

proven sail
#

and if im on the ground remaining jumps will be equal to max jump count which is 2

#

so what i dont understand is

slender nymph
#

read that again

proven sail
#

okay i will read it again

summer stump
#

! is the negation operator

#

Aka, not

proven sail
#

if im on the ground, my transformation on the y axis

#

omggggg yessssssss

summer stump
#

You didn't fix the issue I was pointing out

#

You combined them, which you do not want

proven sail
#

i was doing the two seperate things for that i remember

#

i forgot it in the middle of im writing it

#

thank youuuu just wait

stuck palm
#

why cant i do this? slugger inherits character

slender nymph
#

Just because player is a Character does not mean it is a Slugger

acoustic arch
#

could be user error tho

slender nymph
#

wdym it doesn't detect anything? i told you to break all when it freezes. then you can look at what is happening on the main thread to see what the loop is

slender nymph
#

i did not say anything about break points

acoustic arch
#

i'm trying to follow the guide you sent me mb

summer stump
stuck palm
summer stump
stuck palm
#

Am I using the term upcasting correctly

stuck palm
slender nymph
stuck palm
#

It runs once

rich adder
proven sail
#

okay there is one more problem. the jumps remaining count is 2 only when im grounded

stuck palm
summer stump
proven sail
#

i can jump on the air one more time

slender nymph
proven sail
#

like the double jump thing

summer stump
#

That is the point of subtracting from jumps remaining

proven sail
#

but it is subtracting so fast i think

stuck palm
summer stump
#

Not GetButton

#

The latter is true as long as you hold it down, which is gonna be more than a single frame

proven sail
#

oh okay let me try

#

i thought it was public float

#

it should be public int

summer stump
#

Ah I see.
I mean yeah, int makes more sense there

#

Since you can't half jump, unless you want to implement like a percent of max jump? Hahaha

proven sail
#

the guy who write the code made it int and i used float because the guy that made the character controller used that only

eternal needle
proven sail
#

what should the KeyCode be?

slender nymph
proven sail
#

oh not that sorry

summer stump
#

Yeah I was just going on memory. Down is the important part

proven sail
#

oh now mouse doesnt work

#

wait i will fix it

#

oh its fixed and i can jump 3 times right now i will fix it too

atomic sierra
#

the gameobject has the script and the player body sprite has the rigidbody

#

sorry it took so long

proven sail
#

I installed the unity today, coming from godot. i spent all my day by learning right way of fbx exporting from blender, learning about post processing in unity and trying to recreate the look of my game in godot. its 3 am in my country and i need to sleep. before i sleep i said i need to try some coding and mess up with the code. you guys are so helpfull, thank you so much for helping me fix it and im sorry if i disturbed any of you. good night guys.

#

its looking good for now @summer stump thx @slender nymph thxx

proven sail
proven sail
stuck palm
summer stump
atomic sierra
#

so if i do that, will the dash indicator then follow the parent?

#

or i mean the object

summer stump
rich adder
rich adder
#

what kind of game are you going for

proven sail
# stuck palm why the switch from godot if i may ask

i was trying to create a animated sky for 2 days ended up adding 90 frames one by one for half an hour to AnimatedTexture thing. when i asked the godot community said there is no other way and AnimatedTexture thing will be removed in the next update. i even tried a TextureAtlas but it was worse. so i think there is some technical deficiencies in godot. godot is still one of the best for me but i will give a chance the unity since i tried it once or twice in the past. (one more reason is that i see my idol world4jack converted his game to unity from godot)

stuck palm
proven sail
# rich adder what kind of game are you going for

an open world game that has many little stories in it. trying to catch the vision from when we were childs and see the world more brighter and differently, like a ps2dream as an adults eye with graphics. and the stories are about daily things but one by one they get crazier and more dreamlike.

atomic sierra
#

@summer stump it works now

#

but im confused why wouldnt it work before and now it works?

#

is it the fact that i had a script and the rigidbody in two separate gameobjects?

proven sail
#

if you like this kind of graphics you can look at world4jack's videopix on youtube he inspired me alot

summer stump
atomic sierra
#

oh

#

OHHHH

#

i see

#

that makes a whole lot more sense

acoustic arch
#

it worked well for me when i first started

#

but i would fact check it every now and then still

proven sail
eternal needle
#

That is some pretty bad advice.

#

A beginner isnt gonna be able to fact check it in the first place, and if you can then you know how to google to research what you need in the first place. Just follow the links sent above by others

proven sail
#

i will try it thank you if it dont fit me i wont use it thank you for the advice againnn❤️❤️❤️❤️

#

Now im going to sleep goodnight guys you all so cool

eternal needle
cobalt dagger
#

is there a variable type of Tag?

frosty hound
#

If you make one, sure

summer stump
cobalt dagger
abstract finch
#

How does one do a get a radial position on a 3d plane? Basically what I'm trying to do is get a random direction then have it raycast to see if there is anything in that direction, if there is do a rotation along one axis. The purpose is i want a flying enemy to find a direction to dash to. So I'm checking it along a radial pattern

summer stump
#

But likely your issue is checking the wrong object if it's in OnTriggerEnter (assuming you are SURE it is the same string)

cobalt dagger
abstract finch
serene barn
#

I'm having issues with the jumping code, I'm following a tutorial and everything is correct. So I'm not too sure what is wrong

#
public class PlayerMovement : MonoBehaviour
{
    [Header("Movement")]
    public float movementSpeed;

    public float groundDrag;

    public float jumpForce;
    public float jumpCooldown;
    public float airMultiplier;
    bool readyTojump;

    [Header("KeyBinds")]
    public KeyCode JumpKey = KeyCode.Space;

    [Header("Ground Check")]
    public float playerHeight;
    public LayerMask WhatIsGround;
    bool grounded;

    public Transform orientation;

    float horizontalInput;
    float verticalInput;

    Vector3 moveDirection;
    Rigidbody rb;

    private void Start()
    {
        rb = GetComponent<Rigidbody>();
        rb.freezeRotation = true;   
    }
    void Update()
    {
        grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.2f, WhatIsGround);

        MyInput();
        SpeedControl();

        if (grounded)
            rb.drag = groundDrag;
        else
            rb.drag = 0;
    }
    void FixedUpdate()
    {
        MovePlayer();
    }
    private void MyInput()
    {
        horizontalInput = Input.GetAxisRaw("Horizontal");
        verticalInput = Input.GetAxisRaw("Vertical");

        if(Input.GetKey(JumpKey) && readyTojump && grounded)
        {
            readyTojump = true;

            Jump();

            Invoke(nameof(ResetJump), jumpCooldown);
        }
    }
#
 void MovePlayer()
    {
        moveDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;

        if (grounded)
            rb.AddForce(moveDirection.normalized * movementSpeed * 10f, ForceMode.Force);
        else if(!grounded)
            rb.AddForce(moveDirection.normalized * movementSpeed * 10f * airMultiplier, ForceMode.Force);
    }

    private void SpeedControl()
    {
        Vector3 flatVel = new Vector3(rb.velocity.x, 0f, rb.velocity.z);

        if(flatVel.magnitude > movementSpeed)
        {
            Vector3 limitedVel = flatVel.normalized * movementSpeed;
            rb.velocity = new Vector3(limitedVel.x, rb.velocity.y, limitedVel.z);
        }
    }
   
    private void Jump()
    {
        rb.velocity = new Vector3(rb.velocity.x, 0f, rb.velocity.z);

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

    private void ResetJump()
    {
        readyTojump = true;
    }
}

#

I don't have nitro so that's why i broke it into two

eternal falconBOT
serene barn
acoustic arch
#

i used it to explain things like properties and give examples

young warren
#

that's the point

abstract finch
#

Debug.DrawRay(transform.position, Quaternion.AngleAxis(_currentAngle, Vector3.up).eulerAngles, Color.red);
The ray isnt matching the arm, is this the right approach to converting the angle to direction?

acoustic arch
#

ive never used the attatched debugger with unity and im having some trouble

#

ive managed to attatch it but the first time I recieved -

#

No compatible code running The selected debug engine

#

also how can I step each line to try and find errors?

faint osprey
#

Ive got a UI button in world space however its being covered by a UI image that the camera is projecting to and so i think thats why the button isnt working so i dont know how to fix it

hollow slate
#

AngleAxis would spin the angle around the V3.up, which wouldn't really do anything in this case, as we're already pointing upwards.

#

it seems like you want to use Debug.DrawRay instead, as DrawLine draws from a position to another, while DrawRay draws in a direction.
If you want the angle to be relative to the arm you should use the arm's transform when rotating with _currentAngle, so maybe arm.transform.right in the AngleAxis.

hollow slate
pale vault
#

I'm tryna get the length of the animation, but the results are always inaccurate. It's gonna be 1 or 0.833333 or something

public void UseButton()
{
    animator.SetTrigger(TriggerName);

    float ClipDuration = animator.GetCurrentAnimatorStateInfo(0).length; //I'm trying to reference the duration of the animation state
    Log("ClipDuration: " + ClipDuration.ToString());

    StartCoroutine(ExecuteFunctions(ManualTiming ? AnimationDuration : ClipDuration));
}

The comment in the line of code describes the problem.
Anyone here can help me?

pale vault
faint osprey
pale vault
pale vault
hollow slate
faint osprey
#

so the camera is projecting onto a texture which is then being placed as UI

hollow slate
pale vault
#

So the problem now is... how do I make it not the empty state

#

I want my custom animation's length to be referenced, not the empty state

hollow slate
#

oh, I believe you have to give an extra frame of leeway for the state to actually change.

pale vault
#

Thanks by the way

hollow slate
#

animations are framerate-dependant, so even if you change the trigger in code, it won't actually change the animation until it undestands that it needs to.

hollow slate
#

giving extra frames isn't the norm in Unity, but some systems do need it :(

pale vault
#

I'm gonna try it out

hollow slate
faint osprey
hollow slate
#

I see, okay.

#

And this UI image of (presumably what the camera can see), is blocking your other UI elements when pressing buttons etc?

abstract finch
hollow slate
#

"To keep any UI canvas or element from blocking clicks or registering mouse input, simply give that canvas or element a Canvas Group component (Add Component->Layout->Canvas Group), then turn off Blocks Raycasts. "

pale vault
#

@hollow slate Thanks dude, it worked

misty coral
#

What can I do to stop this when it reaches a certain position

#

doing == doesnt work, probably too precise

summer stump
hollow slate
faint osprey
hollow slate
#

not article, forum post. Whatever

misty coral
hollow slate
misty coral
#

my bad I said position

#

I meant rotation

hollow slate
faint osprey
summer stump
misty coral
#

how to v3.Angle

#

like access a the transform.position

hollow slate
#

Vector3.Angle()

misty coral
#

and get an angle?

faint osprey
misty coral
#

but the angles for the game object are independent from the gam world rotation

#

they are adjusted by player cam

polar acorn
# misty coral

Instead of lerping with a changing start position and fixed percentage, you should lerp from a fixed starting and destination, and increase the percentage to 1. This will put you at exactly the ending position. You can probably do this in a Coroutine.

https://gamedevbeginner.com/the-right-way-to-lerp-in-unity-with-examples/

Learn to animate buttons, move objects and fade anything - the right way - in my in-depth guide to using LERP in Unity (including copy / paste examples).

hollow slate
misty coral
hollow slate
hollow slate
misty coral
#

alr

faint osprey
hollow slate
whole narwhal
#

is it possible to have code execute after frames/milliseconds?

eternal needle
burnt rampart
#

any idea why my DisplayDialogue coroutine is not waiting at all before calling TypeText()?

whole narwhal
#

just a short wait like something i would do in scratch. the idea is, after ExitCollider2D, wait 5 frames before removing the ground check

eternal needle
eternal needle
burnt rampart
whole narwhal
eternal needle
eternal needle
whole narwhal
burnt rampart
eternal needle
misty coral
eternal needle
burnt rampart
ember oasis
#

how do I use a void from one script in another script

burnt rampart
ember oasis
misty coral
burnt rampart
#

do you mean a method?

misty coral
#

but the transform.localEulerAngles interferes with it

#

and basically just overrides the animation

#

what do I need to do to it to make both work?

hollow slate
misty coral
hollow slate
#

ah

misty coral
#

but i need help

#

with the stuff I just mentioned

#

above

hollow slate
#

right, well you're adjusting the rotation when you set the angles no?

hollow slate
#

we're just doing Update and moveCameraBack?

misty coral
#

ok so with moveCameraBack I get a nice smooth animation going to the position, but with the transform.EulerAngles uncommented, it snaps back to the origin position

#

but I need transform.EulerAngles to control the players cam vertically

#

so im kinda stuck

hollow slate
#

uh-huh, is it a first-person style camera?

#

or some kind of camera that needs to move horizontally at least?

misty coral
#

first person yea

#

i can send videos if you think it would help

hollow slate
#

so what effect do you want the moveCameraBack to have?

#

just move the camera to Quaternion.identity?

#

which is the same as setting the angles to (0, 0, 0).

burnt rampart
# ember oasis like exampleVoid()

I'm going to assume mean a method. void is a return type for a method, it signals "this method has no return value". I do recommend looking into that more, but to actually answer your question:

you need to get a reference to an instance of the class that method belongs to. There are multiple ways of doing this, too many to list here. A popular one is to use [SerializeField] private <class name here> cowboy
then drag and drop the reference via editor

you can then call the method by using
cowboy.methodname();

misty coral
#

I demonstrate the differences there

#

basically

#

the moveCameraBack makes it nice and smooth

misty coral
ember oasis
#

I figured it out

#

thank you anyways

burnt rampart
#

np

hollow slate
#

so what's the issue when you comment the line out?

#

looks like it's doing it smoothly then no?

misty coral
#

idk if you can tell from the video

hollow slate
#

ah

misty coral
#

but with it commented out I can only move the cam left and right

hollow slate
#

if what you want to create recoil with this I'd suggest doing it in a similar way, but with a few generalizations.

ember oasis
#

I hate the unity animator :3

hollow slate
#

if you want constant control of the camera (which is generally what we want for FPS games), but with additional stuff like shaking/recoil - I'd suggest this (as I've done this pattern before):

store a value for the X and Y rotation of the character, which you're already doing for the verticalRotation variable.

Every Update, create a Quaternion that aligns with these value, often just doing Quaternion.Euler(horizontalRotation, verticalRotation, 0)

Then we add whatever recoil we want to this rotation. The concept of adding doesn't really exist for Quaternions, as they're quite mathematically complex, but we can essentially do it using multiplication.

Create another function to get whatever the current recoil-rotation would be and add it to the current camera's rotation (look up order of multiplication for Quaternions).

Finally set the rotation of the camera to the combination of these two.

#

that's the general way to allow for adjustments of the camera's rotation without overriding the input.

misty coral
hollow slate
#

it would be this line in your script.

ember oasis
#

could someone tell me why this block of code refuses to work

#

I'll drop the whole .cs file's code if that's required

eternal needle
twilit cliff
#

Hey guys, I have two crate Prefabs in CratePrefabs[] both are tagged with Yellow crate and Red crate respectively as per their crate color. I used Input method to move Yellow crate left and right arrow keys and used A & D keys to move if it's a Red crate. However, if the Yellow crate is instantiated, it's using A & D key to move and if Red crate is active, it's using arrow keys

Can someone please help me understand what mistake I'm doing here?

eternal needle
twilit cliff
# eternal needle add some debugs, to show which part of the code is running. youve likely given t...

Even I was confused for a while that I might have added wrong tags to those crates but I've checked multiple times to confirm that the respective crate tag is added and even I have added the logs in some other method to confirm, which crate is instantiated when it's instantiated and even the logs confirm that the Yellow crate is instantiated but still it's using A & D keys to move instead of arrow keys

eternal needle
#

well add some debugs inside the current code, to see which part of the code is running. Then you'll see more into why its entering one if statement instead of the other

twilit cliff
misty coral
#

The recoil is pretty snappy

#

also using transform.localEulerAngles cancels out any of the effects from trying to adjust the angles

#

so i still need to comment it out

supple needle
#

I am making a game with roads of different markings, there are roads with markings that show that we cannot overtake. If we do i want the game to detect it and deduct my points. Is there a efficient way to implement this? I was thinking of using some collider triggers, but having them for every road in my game could affect performance right?

eternal needle
eternal needle
supple needle
#

Are colliders being used for everything in games common?

eternal needle
#

if you want collisions, yes

supple needle
#

But i think mesh colliders are a bit more heavy performance wise compared to the cube or sphere ones right?

eternal needle
#

If you plan on having a TON of these, well first thing maybe you are trying to have too much in one scene.
But also then you can specify more about your game, like are you using rigidbody or other movement where the user can go absolutely anywhere they want? Are they on a fixed path and dont have control over going offroad?
If its completely free movement, triggers will be your only solution really. If you decide where the user goes, and for example they press A/D to move left or right you can keep track of it differently possibly.

supple needle
#

Ive been using cube colliders to help traffic vehicles stop if they detect a car up front, stoo at a traffic signal etc..

supple needle
eternal needle
#

Since these arent gonna be moving and colliding with each other, i doubt you'll have any issue

#

its just the cars moving

supple needle
#

I was just asking to see if there was a unique approach to this problem, colliders seem the easiest way, and the most effective, thanks for info!

eternal needle
#

idk too much about asset stuff, but i noticed that was a common thing done. making a separate mesh for the collider

twilit cliff
whole idol
#

hi

#

is there a way to get the reference of a text GameObject inside of a canvas object?

whole idol
#

wait

#

I can just make a public variable

#

modern problems require modern solutionsthinksmart

#

Ok so turns out you cant do that

#

I couldnt drag a text object onto the reference var in my inspector

#

Canvas or Text, I cant drag any of them

twilit cliff
static bay
#

Handles all TMP Text objects I believe.

#

Probably.

twilit cliff
summer stump
static bay
onyx tusk
#

how 2 rotate camera ONLY at 1 axis?

#
  1. code
  2. before
  3. after
willow scroll
willow scroll
eternal needle
# onyx tusk 1. code 2. before 3. after

you are rotating it by one axis. use this code on a basic cube and see how it works. Do not trust the rotation you see in inspector. 2 things, it is a local rotation, and it is also an euler representation of the real quaternion used. The conversion from euler (what you gave) to quaterion, then back to euler will not always give the same numbers back. It is the same rotation though

onyx tusk
summer stump
summer stump
# whole idol

Oh wait, are you trying to drag a scene object onto a prefab? You can't do that

eternal needle
onyx tusk
whole idol
#

what if I add my prefab in as an invisible Gameobject and turn off its mesh?

frigid ravine
#

Hey guys! How do I make the yellow Puck spawn only once and share location through the host and client?

#

I'm using NGO and Relay

whole idol
willow scroll
#

Are you referring to its type? As they have told you, you should use TMP_Text, not GameObject

whole idol
#

ok

#

I didnt create a script inside of a prefab instead I added it into my Player gameobject

#

why is this taking so long?

#

4 minutes?

#

I just saved a script

eternal needle
# whole idol

probably some unity error. you might just have to close and reopen

delicate portal
#

Hey,
I have a script and with that I can move object with my mouse when dragging them. But whenever I click and drag an object, since the game is 2d, it detects the object behind them ocassionally. Why is that?

timber tide
#

if it's not on a canvas and fully 2D then it's probably grabbing the first collider it hits and if all elements are on the same z then i assume that would cause some complications

delicate portal
#

Alright I realised the problem just now, its the z positions, how would you look at it?

willow scroll
delicate portal
timber tide
#

not sure of the most correct way of solving that in 2D besides just inching back the z values by a few minor units

willow scroll
delicate portal
timber tide
#

could also do a raycast all and iterate through all colliders and pick the most top card if you have it sorted as it seems

#

since you do seem to have a most top card being rendered

willow scroll
#

Well, why wouldn't you make them UI instead of sprites?

#

It makes more sense, since you also have those users, Ben and Steven, which should be images

delicate portal
willow scroll
delicate portal
#

Interaction, animation and iteration

delicate portal
willow scroll
willow scroll
willow scroll
#

You'll thus have to have a script applied to each of your cards

timber tide
#

I assume the top card has the highest sorted order what i mean, such that you can just check through all those hit by the raycastall

willow scroll
#

In the case, when the cards are sprites, multiple will be selected using OnMouseDown

willow scroll
timber tide
#

if they are on the same z then it wont always do that though

#

it will be rng at that point

#

raycastall would grab everything bunched together then you choose the collider by highest render ordering

willow scroll
#

When using sprites, you'll simply have to change their z positions according to the desired order

timber tide
#

I assume canvas does something similar

willow scroll
#

Canvas doesn't care about the z position

timber tide
#

right, it cares about the ordering, but grabbing elements via colliders wouldn't be accurate alone

willow scroll
#

Where the render queue is changed via Graphic.renderQueue

willow scroll
delicate portal
willow scroll
eternal falconBOT
timber tide
#

Dont think OnMouseDown is the idea here. Probably just check for input then raycast onto the board if you want to do it that way, and you'd need RaycastAll if you want to compare multiple colliders per ray

willow scroll
timber tide
#

Actually I guess that kinda works

willow scroll
delicate portal
#

I get it, yet you still recommended raycasts?

#

I'm confused

willow scroll
#

Anyway, as was mentioned by Mao, you can actually find all Raycasts and check for the sortingOrder, as that's how you see the objects appearing on the screen.
You can also find the Raycasts and change the objects' z position, which is more appropriate when dealing with Physics

#

But I would rather do it in UI space

delicate portal
timber tide
#

then how do you have some cards above other cards

willow scroll
delicate portal
willow scroll
#

So you either

    1. Get all Raycasts and check which has the highest sortingOrder
    1. Get the first Raycast based on the Z position, which you have correctly set up
    1. Use UI and get the cards according to the first Raycast target
#

Note that the options are ordered from the best worst to the best

delicate portal
timber tide
#

idk what you mean by spawning order, it's pivot sort then sorting order

delicate portal
willow scroll
willow scroll
#

Yes, you just increase the sorting order

#

Just make sure the cards don't have their orders willing to exceed 32767

split dragon
#

Hi. I like to shorten very much, if possible, and I have a question: Is it professional and correct to shorten the code? Of course, I understand that everyone has a different approach, but I would like to hear the opinions of others. Также хотел бы узнать: Можно ли пренебрегать фигурными скобками, если для условия нужно будет 1 действие (если фигурные скобки необязательны)?

willow scroll
split dragon
delicate portal
delicate portal
willow scroll
#

!code

eternal falconBOT
willow scroll
#

Have a single script to manage Raycasts

delicate portal
willow scroll
delicate portal
willow scroll
delicate portal
#
        if (Input.GetMouseButtonDown(0)) {
            RaycastHit[] hits;
            hits = Physics.RaycastAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
            foreach (RaycastHit hit in hits) {
                if (hit.collider.TryGetComponent<Card>(out Card card)) {
                    if (card.GetSortingGroup().sortingOrder > lastSortingIndex) {
                        lastSortingIndex = card.GetSortingGroup().sortingOrder;
                    }
                }
            }
        }
    }```
#

Somewhy, the positioning is off

willow scroll
#

The code you want to write won't even be easier than the normal one, which is much better for the performance

delicate portal
#

But I tried this, this will get the card object which has the biggest index

willow scroll
delicate portal
willow scroll
willow scroll
oblique herald
#

sashok, hope I'm not coming off as needy, but I hope you could check your dms.. thanks and sorry in advance

willow scroll
oblique herald
#

alright then

willow scroll
#

You should get the card with the highest sortingOrder among the Raycasts

delicate portal
#
private int lastSortingIndex = 0;

private Vector3 offset;
private bool isDragging;

private void Update() {
    if (Input.GetMouseButtonDown(0)) {
        RaycastHit[] hits;
        hits = Physics.RaycastAll(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
        if (hits.Length < 0) return;
        System.Array.Sort(hits, (hit1, hit2) => hit2.collider.gameObject.GetComponent<SortingGroup>().sortingOrder.CompareTo(hit1.collider.gameObject.GetComponent<SortingGroup>().sortingOrder));
        RaycastHit hit = hits[0];
        selectedObject = hit.collider.gameObject;
        offset = selectedObject.transform.position - Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, selectedObject.transform.position.z));
        isDragging = true;
        }
    }```
willow scroll
#

Now, please, format it as I have asked you 🙂

delicate portal
#

Yes

green ether
#

add c# after the 1st ``

willow scroll
#

And in this case, please, send it via a site

delicate portal
delicate portal
willow scroll
#

Thanks

delicate portal
#

I don't do anything yet with the selectedObject and isDragging, and also with the offset neither

oblique herald
#

https://hatebin.com/kyszaelfmr
https://hatebin.com/lntnbnjgtn
I know this looks atrocious( I have less than a day to finish the project), but currently the problem I'm facing is somewhat a Update() Overload(? I dont know how to phrase it properly)
where when I craft certain items it doesnt pop up (Cake and Cage) to be exact, but others do, they have the same function structure, same lines of code, so I guess the function is working,
but the update is overloading(still dont know how do you call it), could anyone help out or give some advice? Much appreciated.

willow scroll
delicate portal
willow scroll
delicate portal
willow scroll
#

You think so?

#

Why don't you print it?

#

Your Sort method appears to be inverted

delicate portal
#

I got an index was outside the bounds of the array error to this piece:
RaycastHit hit = hits[0];

delicate portal
green ether
#

nothing hit?

delicate portal
#

Looks like it

willow scroll
#

This way it's sorted as hit2 -> hit1, where hit2 has smaller sortingOrder

#

Therefore, hits[0] returns the lowest card

delicate portal
#

So I rather compare hit1 with hit2

willow scroll
willow scroll
delicate portal
#

But it doesnt debug me anything yet

willow scroll
#
hits.OrderBy(h => h.collider.GetComponent<SortingGroup>().sortingOrder);
delicate portal
#

The problem is, hits.lenght is 0

#

There is nothing hit with the RayCastAll

young fossil
#

Hey guys, I would like a dropdown for my enum parameter for UnityEvents. Any way of doing this?

willow scroll
delicate portal
young fossil
young fossil
delicate portal
#

Can the mouePos.z be a problem?

willow scroll
delicate portal
willow scroll
#

Nothing is going to be hit with the Raycast in a 2D game

languid spire
delicate portal
willow scroll
oblique herald
languid spire
delicate portal
oblique herald
# languid spire you appear to have made no attempt to debug your code so you should do so also I...

additionally, I have try a few things that seems to me if Update() is relevant at all,

  1. I removed the craftCard function including the check if craftable all together, and the whole system works again
  2. I added a line of DebugLog in CageCrafting, specifically in confirmCraftCage after if (canCraftCage && itemSlotScript.craftingImage.sprite != itemSlotScript.emptySprite) and seemingly no log was debugged.
  3. I removed every item craft except Card, Cage and Cake, and only Cage seems to work.
oblique herald
languid spire
#

And dont take them out when you post your code

#

Alternatively learn to use the debugger, it will prove to be much more useful

oblique herald
# languid spire there is very little point adding Debug.Logs AFTER if statements because they te...
public void cageCraftingRecipe() {
        Debug.Log("selectedItemImage=" + itemSlotScript.selectedItemImage.sprite + ", cakeLCraftItem=" + cakeLCraftItem + "selectedItemImage2=" + itemSlotScript.selectedItemImage2.sprite + ", cageRCraftItem=" + cageRCraftItem + ", craftingImage.sprite=" + itemSlotScript.craftingImage.sprite + ", cageCraftedItem=" + cageCraftedItem);
        if(itemSlotScript.selectedItemImage.sprite == cakeLCraftItem) {
            if(itemSlotScript.selectedItemImage2.sprite == cageRCraftItem) {
                itemSlotScript.craftingImage.sprite = cageCraftedItem;
                canCraftCage = true;
            } else {
                itemSlotScript.craftingImage.sprite = itemSlotScript.emptySprite;
            }
        }
    }
selectedItemImage=CA (UnityEngine.Sprite), cakeLCraftItem=CA (UnityEngine.Sprite)selectedItemImage2=GE-export (UnityEngine.Sprite), cageRCraftItem=GE-export (UnityEngine.Sprite), craftingImage.sprite=1_Generic_16x16_0 (UnityEngine.Sprite), cageCraftedItem=cage (UnityEngine.Sprite)
UnityEngine.Debug:Log (object)
InventoryManager:cageCraftingRecipe () (at Assets/Script/forRoom1/InventoryManager.cs:330)
InventoryManager:Update () (at Assets/Script/forRoom1/InventoryManager.cs:83)

selecteditemimage1 and selecteditemimage2 is the same? how is craftingImage sprite still not = to cagecraftedItem ?

young fossil
#

Opinions on making my SceneLoader class static? It's used for loading scenes, similar to SceneManager in Unity. Also deals with transitions and loading screens.

whole idol
#

Is it possible to see the type of a variable inside of Visual Studio?

young fossil
whole idol
#

I am hovering

#

it says (field)

young fossil
#

The type is TMP_Text

whole idol
#

oh

#

ok then is it possible to change that into Int?

gaunt ice
#

if you change it to int, then where you want to display the score?
create another variable to store it

languid spire
# oblique herald ``` public void cageCraftingRecipe() { Debug.Log("selectedItemImage=" + ...

First a lesson in how to write Debug statements. Try this one

Debug.Log($"selectedItemImage={itemSlotScript.selectedItemImage.sprite.GetInstanceID} cakeLCraftItem={cakeLCraftItem.GetInstanceID} selectedItemImage2={itemSlotScript.selectedItemImage2.sprite.GetInstanceID} cageRCraftItem={cageRCraftItem.GetInstanceID}
craftingImage.sprite={itemSlotScript.craftingImage.sprite.GetInstanceID} cageCraftedItem={cageCraftedItem.GetInstanceID});
young fossil
#

So what you have there is a declaration. You have
public TMP_Text text_score
That means

  1. public you can change or get it anywhere in the software without restriction
  2. TMP_Text is the type, it is Text Mesh Pro text type, therefore Unity's way of dealing with text
  3. text_score is the name of the field
whole idol
#

float text_score_Variable_Carrier += TMP_Text text_score;

#

can't I do something like this?

young fossil
#

Due to poor naming, I think you have got confused. This text_score name refers to the actual text... Not the score number.

If you wanted the score, you declare it like public int text_score

whole idol
#

or this

#

well its referencing to the TXP_Text

gaunt ice
#

the tmp_text is a component in ui that displays the text

whole idol
#

otherwise I wouldnt be able to access it

#

public int text_score is nothing

young fossil
#

You need to actually read what I am writing

whole idol
#

yep

whole idol
gaunt ice
#

so you need another varaible in your clsss to store the actual score then assign to the tmp_text.text

whole idol
#

ok

#

i see what you mean

#

but why is it a problem that I name it text_score ?

#

I dont think thats a problem

young fossil
#

So the mechancism of what you're trying to do is basically this.

You have the actual text, which is the TMP_Text. That is what needs to be updated.
Then you have the number or value, which is the score that the TMP_Text updates with.

whole idol
#

there is no score

#

I named it text_score

#

but nothing in my unity is named score

#

im trynna create a score rn

young fossil
gaunt ice
#

yout should name it to score_text

whole idol
#

ok

willow scroll
gaunt ice
#

btw keep your naming comvention consistent, snake_case and camelCase and PascalCase both exists in your variable names

oblique herald
young fossil
#
willow scroll
whole idol
#

its the type for number variables in c#

#

like float is another type for float numbers

#

and double is for double numbers etc.

#

I think i need to convert my scoreText variable

young fossil
whole idol
#

into a variable that can be editted

willow scroll
languid spire
whole idol
#

int has numbers like this 4, 5, 121 etc.

willow scroll
oblique herald
young fossil
whole idol
oblique herald
pine bone
#

Hello, i have made a building system similar to Bad Piggies. However i'm having an issue connection the neighbour objects together, i have multiple object types (Ropes, Wheels, Blocks) that should have their own connecting types. The wheel should only connect if there's a block above it, the rope can connect to other ropes or blocks. What's the best way to do this? My current script checks the object type manually but i think the code will get very messy after adding more object types to the game. Thanks

gaunt ice
#

the only way is ofc checking it adjacency cells(?) manually
you have serialize the eg accepted neighbors in list to prevent hardcode it or using json to define the connectivity

languid spire
whole idol
#

ok so i just realized

#

what my mistake was

#

and what someone of you where trynna hint at

#

and i fixed that

#

now scoreText I think will not work in the current set up that I have

#

int scoreTextVariableHolder += scoreText;

#

it seems to throw an error on +=

young fossil
gaunt ice
#
public class Class{
  private int _x;<-------|
  public void Method(){  |
    int _x=10;<----not the same _x
  }
}
young fossil
#

You shoudn't even worry about operators like +=, you should just stick to + and = then learn to code from the basics

oblique herald
languid spire
# whole idol

Please go and learn some C# and Unity basics as you have been told time and time again

tawny bolt
#

can anyone help why my speed is not increasing

young fossil
# whole idol ok

This is an excellent tutorial

#

Since you know some stuff, you should wizz through it wth relative ease

willow scroll
# pine bone Hello, i have made a building system similar to Bad Piggies. However i'm having ...

So, I would do it like that:

  • Create a main class for all the objects you have, you may call it how you want, let's call it Item

  • The classes like Rope, Wheel, Block should be derived from this main class

  • The connection may be done by assigning multiple blocks to the parent GameObject, so you may want every of your Items be already placed in an empty GameObject, which performs the position changes

  • Implement the dragging object, I don't remember how it's done in the game

  • Implement a list of, I would say, flag enums, which stores the items you have

[Flags]
public enum ItemType
{
    Rope,
    Wheel,
    Block
}
  • Every Item should have its own ItemType itemType and the ItemTypes collisions it can collide with. Note that itemType must have the logic of an enum, as if it doesn't have flags. So have a single itemType and multiple collisions
  • When dragging the objects close enough to each other, check whether the each other's collisions contain the each other's itemType
whole idol
gaunt ice
#

note that you have only have up to 64 types if you use flag

young fossil
languid spire
young fossil
#

This channel is for fixing prolems assuming the person knows basics on how to code

young fossil
#

@whole idol This is a short video I found, I don't think it is amazing code but it's a quick start for beginners

#

That's what I imagine you're trying to do

#

Good luck, don't be afraid to still ask

willow scroll
patent compass
#

Hello, I am trying to read data from a json file. But getting this error.

Invalid vector string: 97.31, -47.31

This is the code for parsing the vec.

    Vector3 ParseVector(string vectorString) {

        string[] parts = vectorString.Trim('(', ')').Split(',');


        if (parts.Length != 3) {
            Debug.LogError("Invalid vector string: " + vectorString);
            return Vector3.zero; 
        }

        float x, y, z;
        if (!float.TryParse(parts[0], out x) || !float.TryParse(parts[1], out y) || !float.TryParse(parts[2], out z)) {
            Debug.LogError("Failed to parse vector string: " + vectorString);
            return Vector3.zero; 
        }


        return new Vector3(x, y, z);
    }```
pine bone
willow scroll
oblique herald
pine bone
gaunt ice
#

the purpose for flag is to fast checking for the type of other object collided with

willow scroll
pine bone
languid spire
gaunt ice
#

you can still use the flag when assign the type to object, but you can only assign one enum to it

willow scroll
oblique herald
#

but still thanks for your debugging

patent compass
willow scroll
main zealot
#

hey guys i'm trying to access an object's component in DontDestroyOnLoad with this

  public static CustomNM getNM()
    {
        // Je sais pas si y'a une version jolie pour faire ça
        GameObject[] DDOL = SceneManager.GetSceneByName("DontDestroyOnLoad").GetRootGameObjects();
        for (int i = 0; i < DDOL.Length; i++)
        {
            if (DDOL[i].CompareTag("RoomManager"))
            {
                return DDOL[i].GetComponent<CustomNM>();
            }
        }

        return null;

    }

but it says "this scene is invalid"
Should i use another thing to access it ?

patent compass
#

Getting info from json and showing it on ui

willow scroll
gaunt ice
#

unity has a built in type called Collision

willow scroll
#

Oh, sorry

#

I got it

#

Naming problems

pine bone
gaunt ice
#

btw maybe having four list for four directions and accepted item types

willow scroll
#

Well, yeah, you'd have to rename your class. It was just an example

willow scroll
willow scroll
#

You'll have to enumerate through every single list

gaunt ice
#

when you check the adjacency cell you first need their direction

#

top/bottom/left/right

pine bone
gaunt ice
#

so thats why four lists

willow scroll
willow scroll
#

It's discussable

gaunt ice
#
enum Direction{
  top,bottom,left,right;
}
bool Accept(Direction dir){
  //get the list at dir
  //get the item at the cell at dir
  //return if the item stored in the list
}
willow scroll
#

This will probably cause inconveniences in the Inspector

#

Because of them having to serialize all four lists.

#

Which might make it less easy to adjust

#

I would say, the performance wouldn't differ so much

#

They might find an item in the single list by its ItemType and check for the Direction being correct

pine bone
#

Okay i implemented the item script to all prefabs, i didn't create inherited classes

willow scroll
#

The item, obviously, shouldn't always exist there

gaunt ice
#

actually your way will slower than mine

willow scroll
whole idol
#

now i have a much better idea of what to do, thanks

willow scroll
#

Enumerating through even a hundred of different ItemTypes won't cause any issues if done every second

#

This way, I would prefer the convenience in the Inspector

willow scroll
#

By the way, both methods can be combined. Serialize a single list in the Inspector and then split it into 4, for four different Directions, in the Awake.

abstract finch
#

How would one go about getting a direction from a Quaternion.AngleAxis?

abstract finch
# willow scroll Direction? 🤔

Basically I'm doing something like a radial check using quaternion angleaxis. I need to convert into a direction to raycast to check if somethings there before operating it

wanton crater
#

does putting this in update cause lag?

willow scroll
eternal needle
green ether
willow scroll
wanton crater
abstract finch
eternal needle
#

Vector = vector * quaternion
Will rotate it

abstract finch
willow scroll
#

Is that so? @abstract finch

eternal needle
#

That's not really what it sounds like, anyways that'd just be solved with the built in quaternion functions.

abstract finch
#

the red represents the initial raycast and the direction it will check

willow scroll
abstract finch
#

that looks right if the red is moving toward a direction

willow scroll
#

Red circles represent obstacles

abstract finch
#

yep

#

and it keeps checking based on that pic , counter clockwise

willow scroll
#

And blue one is the position before and after the dash

abstract finch
#

yea

willow scroll
#

What is the desired direction? 12 AM?

abstract finch
#

well it doesnt have to be specific to where which direction it rotates along, as long as a full radial check si done

eternal needle
#

What I said above should work perfectly fine for this.

vocal marlin
#

I want my enemy to turn completely white when damaged, I'm not sure how to do that, as setting the rgb to white is just the sprite's original colour, can anyone help?

pine bone
willow scroll
abstract finch
willow scroll
eternal needle
abstract finch
willow scroll
#

I assume, they didn't want to simply rotate it

sullen rock
#

https://gdl.space/tacapodabe.cs Hello, for some reason the raycastHit.textureCoords is always 0,0 here. Could someone please help me find out why? the texture is a blank tex2D generated by the script in the link as well

eternal needle
#

Yes, so they take the initial vector and simply rotate it until finding the directions that do not collide. Where is the confusion?

willow scroll
abstract finch
#

I simply need a vector3 direction, im trying the code once i fix my unity

willow scroll
#

I assume, this might affect the performance

willow scroll
#

This way they will have to call raycasts countless amount of times

eternal needle
#

No, I think you've misunderstood the problem

willow scroll
long tiger
#

hellooo I need some help real quick. I have this script that has a countdown from 30 to 0 but I cant seem to get this one part to work. I want to have a trigger where when tag player enters the timer stops and the script stops too but it aint working lmao

here's the script for the OnTriggerEnter2D code. Do I have to wrtite something else orrrrr (also ignore the other GameObjects lmao

public class Timer : MonoBehaviour
{
    public GameObject timeText, inGame, postGame, gameOverTimer, gameOverHealth, fallOG;
    public float timeRemain = 30;
    float timer = 0;
    bool timerRunning = true;
    private void Awake()
    {
        timer = timeRemain;
    }
    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            timerRunning = false;
            return;
        }
    }
abstract finch
vocal marlin
willow scroll
long tiger
#

here

    void Update()
    {
        if (timerRunning && timer > 0)
        {
            timer -= Time.deltaTime;
        }
        else
        {
            timer = 0;
            timerRunning = false;
        }
        if (timer == 0)
        {
            inGame.SetActive(false);
            postGame.SetActive(true);
            gameOverTimer.SetActive(true);
            gameOverHealth.SetActive(false);
            fallOG.SetActive(false);
        }
        timeText.GetComponent<TMP_Text>().text = timer.ToString();
    }
}
languid spire
#
if (timer == 0)

never test floats for equality

abstract finch