#πŸ’»β”ƒcode-beginner

1 messages Β· Page 330 of 1

wintry quarry
#

It's just called... setting a condition or a flag?

tawdry quest
#

thats just resetting a condition

#

there is no name for it

summer stump
#

Yeah, not any special name I've ever heard of

molten dock
#

okay thank u

#

i have been using it alot so i thought it might have a name

hexed terrace
#

It's usually not needed and has a better way of doing something

molten dock
#

alright

tawdry quest
molten dock
#

if you wanted an if stament to return true once when an int is equal to 1 how would you do it

hexed terrace
#

return someInt == 1;

#

no if required

tawdry quest
#

why the grin Car

hexed terrace
#

look at the msg above

tawdry quest
#

am i misunderstanding something

tawdry quest
#

wait that works ?

hexed terrace
#

of course

tawdry quest
#

thats new for me, thanks

rich adder
#

if method returns a bool yea

wintry quarry
#

Beginners don't realize that bool is a data type

#

it's not magical or special

tawdry quest
#

didnt know you can return a == tho

wintry quarry
#

== is just an operator that returns a bool

#

just like + returns an int

#

== doesn't do anything except return a bool

tawdry quest
#

hmm never tried that, so obvious tho

hexed terrace
#

if (someInt == 1) is "returning" a bool

wintry quarry
#

bool x = a == b;

#

this is perfectly valid

molten dock
#

i cant understand this

wintry quarry
#

a == b results in true or false

#

true or false goes in a bool variable

#

bool x = true;

#

bool x = a == b;

#

same thing

tawdry quest
#

guess i could saved myself a line or two if i ever tried that

barren vapor
rich adder
#

ugly

tawdry quest
#

luckily C# isnt shit like js

hexed terrace
tawdry quest
# rich adder ugly

indeed return thisint == 1 is ugly
i will continue the if (thisint == 1) return true route

molten dock
wintry quarry
rich adder
#

what you wrote was ugly lol

tawdry quest
tawdry quest
#

but atleast js is not python, python should be a warcrime

molten dock
wintry quarry
barren vapor
rich adder
hexed terrace
rich adder
#

I do this usually when my method only does 1 thing ^^

hexed terrace
#

Doesn't even need to be returning something

tawdry quest
molten dock
#

right now i am doing this and then turning it true again abit later with an Ienumerator

kindred iron
#

guys i get error it says FindObjectOfType<GameManager> is obsolote what should i do

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

public class PlayerCollision : MonoBehaviour
{
public PlayerMovement movement;

private void OnCollisionEnter(Collision collision)
{
    if (collision.gameObject.CompareTag("Die"))
    {
        movement.enabled = false;
        FindObjectsByType<GameManager>();
    }
}

}

kindred iron
rich adder
#

also you should only need to cache it once in awake

rich adder
#

thats too vague

tawdry quest
rich adder
kindred iron
rich adder
hexed terrace
eternal falconBOT
rich adder
#

yup

#

FindObjectsByType<GameManager>() returns the result of the component find

#

you're just discarding it / doing nothing with it

hexed terrace
#

It's also only obsolete in Unity 6 preview.. it'll still work

kindred iron
hexed terrace
#

!learn

eternal falconBOT
#

:teacher: Unity Learn β†—

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

rich adder
#

and the microsoft website good too

kindred iron
molten dock
#

it would have been cool if microsoft made it and then diddnt explain it

rich adder
tawdry quest
rich adder
molten dock
#

chungus

tawdry quest
molten dock
#

microsoft made c sharp

kindred iron
#

im watching Brackeys rn. Should i watch first Brackeys video (GAME OVER - How to make a Video Game in Unity (E08)) or unity structured courses?

rich adder
kindred iron
tawdry quest
#

search for C# course to learn C# and Unity 3D course

rich adder
#

use the provided resources

tawdry quest
polar acorn
hexed terrace
# kindred iron why?
  • teaches bad practices
  • has an error in one video that plagues this channel
  • is old and becomming outdated
kindred iron
polar acorn
rich adder
#

haha need a macro for that

polar acorn
#

Brackeys is great for learning specific tools Unity has. Not so much for general C# programming. You should probably know code before going through Brackeys content

kindred iron
#

ok ty guys

kindred iron
rich adder
#

its not unity-specific no

tawdry quest
kindred iron
#

what does mean unity API

tawdry quest
#

its just c#

rich adder
#

through code

kindred iron
#

what does mean another APP

#

xd

#

im new

rich adder
#

application?

kindred iron
#

ahh

rich adder
#

since the original engine is C++

summer stump
polar acorn
#

Unity has its own suite of functions and classes, but C# contains many things that are not Unity specific

#

Unity's API is a small subset of C#

kindred iron
rich adder
#

You can use c# anywhere you want

polar acorn
#

But it's not a special flavor of C#, it's just C#

tawdry quest
#

API is an Endpoint on the web

#

GET / PUT

rich adder
#

no its not

tawdry quest
#

REST ETC

rich adder
#

REST and API are not the same

tawdry quest
polar acorn
summer stump
#

Api stands for Application Programming Interface, as I just said

polar acorn
#

REST is an example of an API

rich adder
barren vapor
summer stump
#

It is the way you interface with a program/app/library/etc

tawdry quest
polar acorn
#

API = Rectangle
REST = Square

All squares are rectangles. Not all rectangles are squares

rich adder
#

a telephone for software!

kindred iron
#

idk what api is. Even tho it means Application Programming Interface i still dont get it

polar acorn
tawdry quest
#

learn C#, thats the language Unity uses

polar acorn
tawdry quest
polar acorn
#

As opposed to making an entire new program from whole cloth

summer stump
#

void Update()

^ this is part of the Unity API

polar acorn
#

Unity provides an API that you can access through C#.

kindred iron
summer stump
#

All the methods and properties exposed by Unity are the api

barren vapor
polar acorn
#

It allows you to interact with Unity things like Rigidbodies, Materials, Transforms, etc.

kindred iron
#

after learning Unity courses then what should i do?

summer stump
barren vapor
rich adder
#

lots of it

#

repetition is key

#

to really sink the knowledge

kindred iron
#

Is unity courses teachs everything?

rich adder
#

mostly unity specific

#

You still need to learn C# on the side throughly

summer stump
kindred iron
#

then how can i learn new things with making games

polar acorn
summer stump
rich adder
summer stump
#

Making mistakes and exploring IS learning

kindred iron
rich adder
#

its more important that you know WHY and HOW its moving something for example, rather than pasting code you dont know / understand

summer stump
#

It's all small pieces that you put together into big programs

#

The course teaches you the small pieces

#

Then you just look at the docs when needed

rich adder
#

Unity docs has lots of examples

kindred iron
#

should i read all unitys documents

#

then making game

summer stump
rich adder
#

it should literally be like your bible

#

bookmark it

summer stump
#

We have said a few times, do the unity course, then make games

kindred iron
#

ty

languid spire
rich adder
#

think legos

#

you can use the same pieces in different ways

kindred iron
summer stump
kindred iron
#

no i mean about this sentence

languid spire
kindred iron
#

hm okay ty

#

so first i'll watch unity courses then making practice and i'll use doc. when i need it right?

languid spire
#

absolutely, you should always consult the docs when taking the courses so you really understand what they are trying to teach you

kindred iron
#

i have 1 more question

#

should i watch other tutorials even tho i finish unity courses

#

or make game and sometimes i should watch courses

languid spire
#

you can watch other tutorials because some of them provide additional information and techniques not covered by Unity. And by that time you should be able to tell which ones are worth watching and which ones are not

kindred iron
#

should i watch these tutorials when i need it or daily?

summer stump
#

Try to do it more rarely. Give it a shot on your own first, then if struggling look at a tutorial

kindred iron
#

hm okay ty again xd cya

shell ice
#

hello , i have something i want to do but i am not able to , here is my map for example

#

i can move the camera around

#

and zoom in and out

#

( it doesnt follow any particular thing i just move it around )

#

but i want to bound the camera to the edges of this map

#

i thought about creating a gameobject with a 2d collider which represents the bounds of the map and try to check collisions with the camera but i dont really know if its the best way to do it

#

any ideas on how to do this ?

#

i can bound the movement easily

#

but the zoom ...

slender nymph
#

obligatory: use cinemachine
it also has a confiner component

amber kayak
#

hello how dfo i move this im using the game scene any1 got vid? i looked and didnt find

#

that 4x4 i crated using this

slender nymph
outer quail
#

I don't know why this hide cursor script isn't working, when I add it to either the player game object or a cinemachine camera it doesn't work.
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HideCursor : MonoBehaviour
{
void Start()
{
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
}`

slender nymph
#

make sure to click into the game view window. the editor will not capture the mouse otherwise. the editor will also release the mouse regardless of the Cursor.lockState when you press escape so don't expect that behavior in a build without coding it yourself

outer quail
#

Thanks, is that on by default if I click the game view?

slender nymph
#

what are you referring to?

outer quail
#

In past unity versions I always needed to add the two lines of code, but you are telling me otherwise.

slender nymph
#

i never said you didn't need to do that too. i just said that it won't work unless you also click into the game view. which is how it has always worked

outer quail
#

apparently if I make the script un active the cursor hides by default if I click the game view, hide cursor is on by default now(if you click the game window).

slender nymph
#

you are probably disabling the component after that code has already run

onyx tusk
#

how 2 make dragging for 3d object? i just need 2 get mouse coords & some method for getting x & z from it, y is a constant

rich adder
onyx tusk
rich adder
onyx tusk
#

& i'm trying to set up y as 0.35

#

transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Figure.size / 2));

#

size = 0.7

winter fractal
#

hi! is there an easy way to flip my 2D sprite without moving my character?

#

right now, when the sprite is fliped, this happen

onyx tusk
winter fractal
#

Should I just change flip for rotate in the code?

slender nymph
#

you need to adjust the pivot point of your sprite in the sprite editor so that it is centered on it

polar acorn
winter fractal
#

isnt already centered?

polar acorn
#

If not, you'll need to put the pivot on the center of the sprite you actually see

winter fractal
#

oh ok

#

is there a way of changing the pivot of all sprites at the same time?

#

I undestand what you mean, the pivot is centered here instead of the body of the warrior, but when I change it it only apllies to that specific sprite, which causes errors in the animation

slender nymph
#

the best thing to do is instead to design your sprites so that they are properly centered. or slice them so that they are centered

polar acorn
winter fractal
#

is fixed!

#

the automatic slice of Unity did the work!

#

thanks!

slender nymph
#

it's not going to quite turn out the way you want for some of those sprites though

polar acorn
winter fractal
#

yea is oj

#

ok

#

I think the majority will do, I'll adjust manually the problematic ones

#

(sorry to transform the discuss from code to pixel art xD)

chrome tide
#

i have some problems with my blind enemy AI. here i have this script which adjusts the volume and range of currently emitted audio (this script is attached to the player):

using UnityEngine;

public class SoundsEmitter : MonoBehaviour
{
    //emittedAudio[0] - loudness
    //emittedAudio[1] - range
    public float[] emittedAudio = new float[2];
    public PlayerMovement playerMovement;

    private void Update()
    {
        AudioChange();
    }
    private void AudioChange()
    {
        switch (playerMovement.state)
        {
            case PlayerMovement.PlayerStates.Standing:
                emittedAudio[0] = (float)PlayerMovement.PlayerStates.Standing;
                emittedAudio[1] = (float)SoundsManager.SoundDistances.Standing;
                break;
            case PlayerMovement.PlayerStates.Walking:
                emittedAudio[0] = (float)PlayerMovement.PlayerStates.Walking;
                emittedAudio[1] = (float)SoundsManager.SoundDistances.Walking;
                break;
            case PlayerMovement.PlayerStates.Running:
                emittedAudio[0] = (float)PlayerMovement.PlayerStates.Running;
                emittedAudio[1] = (float)SoundsManager.SoundDistances.Running;
                break;
        }
    }
}```
the emittedAudio[] is an array, because the first index holds the volume, and the second index holds the range the currently emitted sound can be heard from.

i also have this Blind Monster AI script. it's long so here's the link to PasteBin: https://pastebin.com/k2dVG1yN

the problem is that the monster doesn't care about the player at all, though it correctly gets the `emmitedAudio` variable from `SoundEmitter` component in `source` (look at foreach loop in `CheckAudioSources()`). i adjusted the maxLoudnessLimit and the enums values correctly. I don't know what's the issue, could someone help? I'll be thankful
#

the problem appeared after i changed emmitedAudio variable from a single float value variable to float[] array. the previous single value variable was holding just the volume.

slender nymph
#

the problem is that the monster doesn't care about the player at all
what do you mean by that? as in it isn't using the correct value from playerMovement.state? because if that is the case, you may be referencing the prefab rather than the active player in the scene

chrome tide
slender nymph
#

you have a whole bunch of conditions that affect whether that object will enter the chasing state and whether it will actually set the destination. either use breakpoints to inspect the values you are checking, or print some useful information that actually tells you what is happening when you check those conditions

chrome tide
#

i will, thanks.

slender nymph
#

and keep in mind that you can use string interpolation to construct a single log that provides useful information. so instead of just dumping the individual values stored in your array right to the console like you're doing on lines 64 and 65. for example:
Debug.Log($"Emitter at loudness threshold: {emitter.emittedAudio[0] >= maxLoudnessLimit} and monster state {state}");

chrome tide
#

i know, i'm using it all the time. thanks for reminder though

arctic shadow
#

hi just asking how would i be able to, after picking something up, rotate it to a certain specified orientation then just not rotate it anymore?

hallow sun
#

lerp

arctic shadow
#

i know i can rotate things with transform.rotate but how can i use it to only make it rotate to a specific point then stop

arctic shadow
#

oh, thanks didnt know that existed πŸ™‚

loud pebble
#

Hi. Trying to use RayCast, but it detects only one side of a cube. What am I doing wrong?

using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{

    [SerializeField] private float moveSpeed = 7f;
    [SerializeField] private float rotationSpeed = 10f;
    [SerializeField] private GameInput gameInput;

    private bool isWalking;

    private void Update()
    {
        Vector2 inputVector = gameInput.GetMovementVectorNormalized();
        Vector3 moveDir = new Vector3(inputVector.x, 0f, inputVector.y);
        float playerSize = .7f;
        bool canMove = !Physics.Raycast(transform.position, moveDir, playerSize);
        Debug.DrawRay(transform.position, moveDir, Color.red, 1f, true) ;
        if (canMove)
        {
            transform.position += moveDir * moveSpeed * Time.deltaTime;
        }
        isWalking = moveDir != Vector3.zero;
        transform.forward = Vector3.Slerp(transform.forward, moveDir, rotationSpeed * Time.deltaTime);
    }

    public bool isPlayerWalking()
    {
        return isWalking;
    }
}```
polar acorn
loud pebble
#

I will make this line a little bit cleaner.

chrome tide
# chrome tide i have some problems with my blind enemy AI. here i have this script which adjus...

when i want to debug.log() the emittedAudio[0] and emittedAudio[1] values, instead of showing the enum value (i store enum values in these 2 indexes), it shows the index of enum. for an example, Standing's value is 0, walking is 10, and running is also 10, but instead of showing these variables it shows 0, 1 and 2. it's only for SoundVolumes, SoundDistances work fine:

this script is binded to the player:

using UnityEngine;

public class SoundsEmitter : MonoBehaviour
{
    //emittedAudio[0] - loudness
    //emittedAudio[1] - range
    public int[] emittedAudio = new int[2];
    public PlayerMovement playerMovement;

    private void Update()
    {
        Debug.Log(emittedAudio[0]);
        Debug.Log(emittedAudio[1]);

        AudioChange();
    }
    private void AudioChange()
    {
        switch (playerMovement.state)
        {
            case PlayerMovement.PlayerStates.Standing:
                emittedAudio[0] = (int)PlayerMovement.PlayerStates.Standing;
                emittedAudio[1] = (int)SoundsManager.SoundDistances.Standing;
                break;
            case PlayerMovement.PlayerStates.Walking:
                emittedAudio[0] = (int)PlayerMovement.PlayerStates.Walking;
                emittedAudio[1] = (int)SoundsManager.SoundDistances.Walking;
                break;
            case PlayerMovement.PlayerStates.Running:
                emittedAudio[0] = (int)PlayerMovement.PlayerStates.Running;
                emittedAudio[1] = (int)SoundsManager.SoundDistances.Running;
                break;
        }
    }
}```

while this one is binded to a standalone empty object SoundsManager:
```cs
using UnityEngine;

public class SoundsManager : MonoBehaviour
{
    public enum SoundVolumes
    {
        Standing = 0,
        Walking = 10,
        Running = 10
    }
    public enum SoundDistances
    {
        Standing = 0,
        Walking = 10,
        Running = 100
    }
}```
loud pebble
slender nymph
polar acorn
slender nymph
polar acorn
#

Then you should be able to see where the line is at that exact frame

slender nymph
#

but if they are printing values you do not expect then you are either using the wrong enum types, or you need to actually save your code so that the enum values are properly compiled

loud pebble
loud pebble
polar acorn
loud pebble
#

Great idea. Will do that now.

loud pebble
molten dock
#

how come doing "whilst bool is true" crashes the game

languid spire
rich adder
#

while(true)
oops

molten dock
#

the loop would end when the bool is false i think

languid spire
#

while (true);
more whoops

rich adder
#

if its inside coroutine it needs yield return null inside

molten dock
#

how come

rich adder
#

cause it wont know when to end

molten dock
#

okay swag

polar acorn
molten dock
#

it does but not with an ienumerator

wraith grotto
#

Hey hey good people. I'm new to Unity and I'm making a topdown 2d shooter.

I have an issue with my firing where instead of going forward from the front of the character it goes into a random direction (maybe my implementation is wrong.)

So, i have a square with a rigidbody2d attached with an empty sprite that's used as the projectiles starting position. The projectile should go from the empty sprite towards the mouse location but it's instead flying into a semi-random direction

I'm using the following implementation:

Projectile behaviour script:
https://hastebin.com/share/obuciluzah.csharp

Player Rotation Script:
https://hastebin.com/share/afiwinuges.csharp

Player Projectile Launcher:
https://hastebin.com/share/ijicuhurav.csharp

would be grateful for a solution πŸ™‚ and please do message me if you are missing any info (I'm new to this).

wintry quarry
# molten dock it does but not with an ienumerator

If there's no yield statement inside the loop, the entire game engine is waiting patiently for the loop to end before continuing to run. So nothing outside the loop can affect anything and if the condition doesn't become false4 in the loop, it will be frozen forever.

wintry quarry
#

you never set it to anything else

#

The variable in the PlayerAim script is completely unrelated to the one in this script

#

Also why does it seem like the gun is launching itself based on this code?

wraith grotto
# wintry quarry Your `playerMousePosition` is always 0,0,0

Yes, thank you. The PlayerAim script is just for rotating the character actually. I'm ashamed I missed it, thanks for the help πŸ™‚
There isn't actually a gun. Just based on the weapontype it will load a different sprite (will add later on) and the projectile behaviour will be different.

paper sable
#

why does my player move like this?

 void FixedUpdate()
    {
        Move();
    }
void Move()
    {
        moveDirection = GameManager.input.Player.Move.ReadValue<Vector2>();
        print(moveDirection);
        rb.AddForce(moveDirection * moveSpeed, ForceMode2D.Impulse);
    }
wintry quarry
#

It's because you don't have interpolation enabled

paper sable
#

not the jittering, thats from my recording software or pc idk but in the game its not there

#

its very fast

wintry quarry
#

then what's the question

#

you're applying a lot of force

paper sable
#

so how do i apply less?

wintry quarry
#

your moveSpeed variable (which is poorly named) is very high

#

reduce moveSpeed

primal jungle
paper sable
#

would it be alright if i divide the move speed by 10 when applying the force? so i can keep it a value like 5 or 10

wintry quarry
#

it just will be in a weird unit

#

"tenths of a newton"

paper sable
wintry quarry
#

basically the only difference between Force and Impulse is that you will need a number 50x higher with Force to do the same as Impulse

wintry quarry
#

(assuming you didn't change your fixed timestep)

#

All of these are equal:

AddForce(moveSpeed * move * 50);
AddForce(moveSpeed * move / Time.fixedDeltaTime);
AddForce(moveSpeed * move, ForceMode2D.Impulse);``` @paper sable
paper sable
#

oh alright thanks

scenic shuttle
#

Why this code not work

    public GameObject door;

    public void DoorOne(string answerText, GameObject doorObject)
    {
        this.answer = answerText;
        this.door = doorObject;
    }

And this code work

    public string answer;
    public GameObject door;

    public void DoorOne(GameObject doorObject)
    {
        this.door = doorObject;
    }
wintry quarry
#

Also is this on a MonoBehaviour?

scenic shuttle
#

Why i use the code "not work" i can't see on here.

icy sluice
#

how do i scale an image between two points on screen?

wintry quarry
#

Seems like you're looking at the wrong script entirely

slender nymph
scenic shuttle
wintry quarry
#

Anyway - UnityEvent only supports a single parameter

#

so - you can only use one

wintry quarry
icy sluice
scenic shuttle
#

oke thank you sir

icy sluice
#

image size: 64x64

scenic shuttle
slender nymph
#

you use a method with only a single parameter

scenic shuttle
#

but i need 2

slender nymph
#

well too bad, unity events only support a single parameter.
you can call a multiparameter method from another method that only has one parameter though

wintry quarry
icy sluice
#

that doesnt work

wintry quarry
# scenic shuttle but i need 2

jsut set those parameters in the inspector on your button and call a function that calls the other function with the params

wintry quarry
icy sluice
#

it doesnt show it

#

i tried

#

multiple things

wintry quarry
#

what doesn't show it

#

LineRenderers work.

lime mural
icy sluice
#

line renderrer

wintry quarry
#

You just have to understand what you're doing with the positions etc.

icy sluice
summer stump
scenic shuttle
summer stump
wintry quarry
icy sluice
#

i didnt

wintry quarry
#

You are suggesting that LineRenderer doesn't work

#

of course it works

summer stump
wintry quarry
#

My guess is you are confused about canvas space vs world space

#

A LineRenderer would draw things in world space - so you'll have to do the appropriate conversions for it to show up in the expected position in the game world

icy sluice
#

and yes, i know the line renderrer will draw in world space

summer stump
#

These are super unhelpful responses.
Why not just show what you did?

wintry quarry
#

You had trouble getting LineRenderer to work. Show what you did that wasn't working, we can help fix it

summer stump
# icy sluice what do you mean

What do you mean what do I mean?
Show what you tried with the line renderer.
You did something wrong, we need to see it to tell you what it was

icy sluice
wintry quarry
#

how were they calculated?

#

What coordinate system do they exist in?

icy sluice
#

vector 3

wintry quarry
#

πŸ€¦β€β™€οΈ

icy sluice
#

both

wintry quarry
#

??? wdym both

#

It's one or the other

#

Your answers to my questions are only confirming my suspicion from earlier that you don't understand the world space / canvas space distinction

icy sluice
#

both are in vector 3
screen pos is the square pos
the leadPos is the complex mathematical equasion that does the leaning where i need to shoot

wintry quarry
#

vector3 is not a coordinate system

#

it's a datatype

#

and obviously it's a Vector3, that's what SetPosition accepts as a parameter

#

that's not what I was asking

#

The answer to how to fix that is you need to make sure both positions are in world space before using them with LineRenderer

#

(and that LineRenderer is set to world space mode)

icy sluice
#
lineRenderer.SetPosition(1, target.position);```
#

and nothing, like before

#

there is no line

molten dock
#

sometimes i know what to do after typing the question lol

polar acorn
icy sluice
#

yes

wintry quarry
# icy sluice yes

Use Debug.DrawLine as well just to show where this line is actually

polar acorn
icy sluice
molten dock
#

that is neat

polar acorn
# icy sluice

Gonna be hard for us to tell where that's supposed to be in screen space since it's just a still image of a line but is that debug line covering roughly where you expect it to be

icy sluice
#

but idk why line renderrer it isnt in game screen still

#

so i switched to image method and now im missing the lenght calculation

polar acorn
#

And if possible try to rotate the camera so we can get a good view of where the red line is in relation to it

icy sluice
polar acorn
# icy sluice

It's hard to convey line renderers in still images since there's no depth. Assuming the game's still running but paused, can you get a shot of this from the side as well?

icy sluice
polar acorn
# icy sluice

Perfect, video is definitely best for this but it can be annoying to record and share, thanks for that

icy sluice
#

yes

polar acorn
#

So it should definitely be visible at that position. A bit small, but not so small it's not visible. Can you send a screenshot of the line renderer component while it's still paused like this? You should be able to see the positions in the inspector for it. Do they match what you expect?

icy sluice
#

i fixed it, it didnt have an material

polar acorn
#

Ah, that'll do it

icy sluice
#

tnx for help

queen adder
#

what does transform do

summer stump
#

Every GameObject has a transform (or rectTransform)

queen adder
#

ohhh

queen adder
#

i was confused where it was coming from

#

lmao

regal bear
#

Hi, i have animations for my player, its a topdown 2d game. My player has 4 animation for running, and idleing. Top down left right. My question is now my player always face down when i stop moving. How can i like save the last moved direction and play that animation. For example if i run up and i stop, the idle up should play, not idle down.

molten dock
#

how come an animation that isnt being activated is making my enemy not be able to move

deft grail
molten dock
#

because when i remove the animation from the animator controller it moves again

polar acorn
molten dock
#

yeah it moves down

polar acorn
#

You should be animating a child object, not the actual object you move around

molten dock
#

how does that work

rocky canyon
#
  • Object you move with controls
  • Object you move with animation
molten dock
#

i see swag ty

ember tangle
#

transform.GetChild(0) is causing 'Transform child out of bounds" when called frequently. Is this normal?

polar acorn
ember tangle
#

All the objects being called have children, once the function is called ~30 times it stops working and the error is thrown.

polar acorn
ember tangle
#

thanks Ill try that, but I can see that the game object has children in the editor

#

!code

eternal falconBOT
devout flower
#

Maybe it's removed then put back?

ember tangle
#
private void TriggerSelectionIndicator(GameObject unit, bool isVisible)
{
        unit.transform.GetChild(0).gameObject.SetActive(isVisible); 
}```
The function is pretty simple, maybe its the SetActive part
polar acorn
stuck palm
#

what is the point of the non generic getcomponent?

polar acorn
stuck palm
#

interesting

devout flower
#

Is Debug.Log($"name is {unit.name} ") the same as Debug.Lof("name is" + unit.name) ? Just curious

stuck palm
#

yeah

devout flower
#

I see

devout flower
#

Oo ok imma read this

#

Thankss

stuck palm
polar acorn
#

Concatenation is combining collections

#

String concatenation would be using +

stuck palm
#

i see

ember tangle
tranquil hollow
#
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{

    public float Speed;
    public float JumpForce;

    private Rigidbody2D rig;

    // Start is called before the first frame update
    void Start()
    {
        rig = GetComponent<Rigidbody2D>();
    }

    // Update is called once per frame
    void Update()
    {
        Move();
        Jump();
    }

    void Move()
    {
        Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
        transform.position += movement * Time.deltaTime * Speed;
    }

    void Jump()
    {
        if(Input.GetButtonDown("Jump"))
        {
            rig.AddForce(Vector2.up * JumpForce);
        }
    }
}
#

i still cant jump

#

can soembody help me?

rich adder
#

every frame

tranquil hollow
#

how can i fix it?

rich adder
#

if its a rigidbody it should not even be using transform. You should use velocity , or AddForce

#

if you use velocity you make new vector2 keeping y as rb.velocity.y

rocky canyon
#

leave the Y velocity alone (like he mentions ^ just feed it back to itself)

tranquil hollow
#

how can i do that?

rich adder
#

replace this line
transform.position += movement * Time.deltaTime * Speed;

#

with the proper one

rocky canyon
#

rb.velocity = new Vector3(Input.GetAxis("Horizontal"), rb.velocity.y, 0);

#

but w/ ur smoothing and stuff

tranquil hollow
#

ok

rocky canyon
#

keynote.. u pss its own velocity.y back to teh Y

ember tangle
#

Is it best practice to use the Animation system as a State Machine?

#

As in using the Animation system to create a State Machine that does a lot more than animation.

cosmic dagger
rocky canyon
#

if u have to knowledge to be able to use the animator as a state machine..
you probably have the knowledge to build out a custom state machine to use

cinder crag
#

why does it say i dont have data to save when i do? and i checked and my save file didnt create for some reason

bitter crown
#

hey guys i have a problem but its not with code can i ask here?

cinder crag
bitter crown
#

then where?

cosmic dagger
#

we have no idea what kind of question you have. only you do . . .

ionic zephyr
#

Any idea on how to do a dash but when the player quickly presses the move button?

deft grail
ionic zephyr
#

the thing is I dont know how to do the code for it to happen only when you press fast the moving input

deft grail
#

there is no speed in pressing a button

#

its either pressed or its not

ionic zephyr
#

Im talking about pressing the button twice in order to do dash

#

but those presses need to be fast

deft grail
#

ok well thats something

#

you can use a timer and check if its hit twice within a certain time

ionic zephyr
#

if(Input.GetKeyDown(KeyCode.RightArrow))
{
timer = Time.deltaTime;
if (Input.GetKeyDown(KeyCode.RightArrow) && timer < _dashRepeat)
{
timer = 0; Dash();
}
else
{
timer = 0;
}
}

#

is it okay like this?

cosmic dagger
deft grail
cinder crag
untold patrol
#

Using code from 2 different tutorials i followed from youtube, one controlled the camera and player movment and now im trying to use code from another person which allows me to interact with objects. im having a problem that rather than the crosshair being where the raycast is sent from, instead it comes from the mouse. im not sure how to change it but ive found the line of code which the raycast is emitted:
void Update()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))

How do i change it from being the mouse position to instead be the crosshair or raycast from my camera?

cosmic dagger
untold patrol
#

how?

cosmic dagger
#

maybe, by accessing your crosshair GameObject and getting the position? we don't know how your crosshair is setup at all . . .

untold patrol
#

tbh im very out of my depth here, i already have raycasting for another interaction script i just dont know how to port it over to this

#

im extremley new to this and have just been following tutorials

cosmic dagger
#

then i would take a step back and learn something simpler . . .

rocky canyon
#
  Vector3 cameraPosition = Camera.main.transform.position;
  Vector3 cameraForward = Camera.main.transform.forward;
  float rayDistance = 10f;
  RaycastHit hit;

 if (Physics.Raycast(cameraPosition, cameraForward, out hit, rayDistance))
 {
      // this would raycast from your camera *straight forward*
 }```
cosmic dagger
#

it's hard to help if you don't understand the help given . . .

untold patrol
#

i understand what i need to do

#

i dont understand how exactly to do it

rocky canyon
#

the question is a bit puzzling as well

untold patrol
#

basically what i want to happen is when i look at an object with the script attached to it the item name will appear on screen. the code works but what i think is happening is because if followed a differnt tutorial for how the players camera functions its not working correcty. the raycast isnt coming from the centre of the players fov or crosshair but instead its coming from my cursor on screen. its a first person game and the cursor shoudlnt be there

#

can i send videos or stuff in here

rocky canyon
#

the codeblock i sent raycasts from the camera

#

str8 forward (camera's forward) it should be where ur crosshair's pointing (if ur croshair is indeed in the middle of the screen)

untold patrol
untold patrol
rocky canyon
#

where ever you need the raycast to happen

untold patrol
#

where input. is was where "mouseposition" was

#

oh i think i did it

#

thank you

rocky canyon
# untold patrol thank you
Vector3 cameraPosition = Camera.main.transform.position;
Vector3 cameraForward = Camera.main.transform.forward;
float rayDistance = 10f;
RaycastHit hit;

if (Physics.Raycast(cameraPosition, cameraForward, out hit, rayDistance))
{
    var selectionTransform = hit.transform;
    interaction_text.text = selectionTransform.GetComponent<InteractableObject>().GetItemName();
    interaction_Infor_UI.SetActive(true);
}
else
{
    interaction_Info_UI.SetActive(false);
}```

nice!.. it would look similar to this (im just using ur code as is)
untold patrol
#

i mean quite close tbf

rocky canyon
#

ya, see.. not too hard..

#

just gotta step back.. look at it.. figure out kinda how its working.. and trial and error

untold patrol
#

now im having the issue that the text doesnt dissapear until i send the raycast onto a different object in range

#

thanks

#

a lot

rocky canyon
#

u probably want to add another else statement. at the end of ur if(physics.raycast)

#

soo.. if it doesn't hit something in the distance it'll also set it false

#

so.. if(it hits something and its not interactable) -> set false
and.. if(it just doesn't hit anything) -> set false also

untold patrol
#

well i broke soemthing

rocky canyon
#
if (Physics.Raycast(cameraPosition, cameraForward, out hit, rayDistance))
{
    var selectionTransform = hit.transform;

    if (selectionTransform.GetComponent<InteractableObject>())
    {
        interaction_text.text = selectionTransform.GetComponent<InteractableObject>().GetItemName();
        interaction_Infor_UI.SetActive(true);
    }
    else
    {
        interaction_Info_UI.SetActive(false);
    }
}
else
{
    interaction_Info_UI.SetActive(false);
}```
untold patrol
#

yea thats what i got

#

lemme try and figure it out for myself firsd

#

first

#

gimme 5

#

thank yo tho

rocky canyon
#

but u do realize.. ur calling getcomponent twice.. everyframe now...

    var selectionTransform = hit.transform;
    InteractableObject interactableObject;

    if (selectionTransform.TryGetComponent(out interactableObject))
    {
        interaction_text.text = interactableObject.GetItemName();
        interaction_Infor_UI.SetActive(true);
    }
    else
    {
        interaction_Info_UI.SetActive(false);
    }``` heres a better solution
untold patrol
#

idk why that } is red

#

nvm im special

#

nvm nvm im lost

deft grail
untold patrol
#

nah

#

i tried

#

i feel its obvious

deft grail
#

ok

#

you cant use else on an else

untold patrol
#

oh sorry wrong ss

#

yeah i got that

rocky canyon
#

your missing a } to close off the first if

summer stump
#

Extra }

rocky canyon
#

put a } between the red } and the else below it

summer stump
#

Oh no, in the wrong place

rocky canyon
#

and remove that oen at the end u added

untold patrol
#

yea that fixed it

#

thank you again

#

and now the thing fully works

rocky canyon
#

think of it like this

untold patrol
#

appricaited

#

that makes sense

#

its my first time using c#

rocky canyon
#

if { and } else { and }

untold patrol
#

and my only other experince is phython basics

rocky canyon
#

you'll learn.. practice makes perfect

untold patrol
#

hopfully soon cuz i have procrastinated this project way to much

wicked cairn
untold patrol
#

but yeah thank you so much im sure this has saved me ages

rocky canyon
#

python dgaf πŸ˜„

wicked cairn
#

C# brackets are better, it’s like keeping the code contained and organized

untold patrol
#

i like how random discord strangers are more help than the people employed to teach me this stuff

rocky canyon
#

exactly..

rocky canyon
#

only a different kind..

untold patrol
#

i had about 6 months to do this proejct and now i got like a week and a half

#

lightwork

rocky canyon
#

sounds about par for what i normally see in here..

#

people come in here stressing "bro, i gotta build this game in 1 week"

#

oh really.. how long have u had to work on it?
"3 months"

untold patrol
#

diamonds are made under pressureπŸ”₯

#

(im failing)

rocky canyon
#

it almost makes us wanna watch u burn..

deft grail
untold patrol
#

good to know im not the only one tho

rocky canyon
#

BUT.. if u have valid excuses.. and are really trying.. we still help

#

its the ones that just want copy/paste code that really push my buttons

untold patrol
#

tbf when we first got it i started really well and then everything corrupted and i didn tthink to kep a backup so i lost a lot of motivation and did other stuff

wicked cairn
#

I think most people go through the same issues just at a different time in life

untold patrol
#

i mean understandable

rocky canyon
#

backup.. and backup some more

#

some of my projects have been in the works for over a year

untold patrol
wicked cairn
rocky canyon
#

if they corrupt i'd throw my PC out in the street

untold patrol
rocky canyon
untold patrol
#

"teach a fish to man and fish a day for fish"

rocky canyon
#

exactly

untold patrol
#

well if it all breaks again im sure ill be back in here sometime soon

#

but naaa i got this light work ez clap

#

thank you tho for ur help

#

much appricated

rocky canyon
#

πŸ‘ good luck sir, πŸ€

untold patrol
#

you too tho im sure you dont need it

rocky canyon
#

oh we.. all do

untold patrol
#

duno if that makes me feel better or more worried but ill take it how it is

rocky canyon
#

well, its b/c the more advanced u get.. the more advanced stuff u try to do..

#

if ur not pushing ur boundaries. u aren't learning anymore

eternal needle
young smelt
#

Hey I am having a problem uploading to playstore. They keep complaining about policy violation I don't know what I violated. I have read their emails and it is not helping either. After the last build I send, the app got suspended.

untold patrol
#

back again. this time im just confused why this doesnt work. whats meant to happen is when the player enters the collider it sets the "playerinrange" function to true and when he leaves the collider it returns to false but it just isnt doing it and idk why . hole point is once the player is in range to interact with the object they can pick it up but i cant get this working

summer stump
untold patrol
summer stump
#

Hover over the three dots

untold patrol
cosmic dagger
#

. . .

summer stump
#

Dang. Alright

blissful lagoon
#

bro capital T πŸ’€

untold patrol
#

thanks

rich adder
#

name is not the same as Name

tidal kiln
#

if youre using vs there should be a snippet when you start typing out ontrigger enter

cosmic dagger
#

make sure to go over the C# basics as they are vital . . .

regal bear
#

Hi, what is the best way for create rooms in a topdown 2d game? I have a room, when i go to the door, i got teleported to the corridor, like old RPG games or like Stardew Valley. I did this by build the corridor far away from the room, and modified the player position on door trigger. Is it good, or how should i do this?

tidal kiln
#

if it works it works

cosmic dagger
#

if it works, it works . . .

rich adder
#

nice

regal bear
#

true haha

tidal kiln
#

you could also split it by scene if your map is larger but dont over complicate it if you dont have to

#

your solution sounds fine

acoustic arch
#

new to unity events, im trying to make a pointer enter, then it enables the outline over whats being hovered

#

it works but never goes away after moving the cursor

#

i made an exit but now it never shows up

regal bear
#

Btw i have a UI image for a bar, it act weird, i set native size, then the box does not match with my sprite like this:
Whats wrong?

cosmic dagger
acoustic arch
#

when does exit get called?

slender nymph
#

Untick the raycast target option on the outline image

#

It's blocking the cast to the object you are hovering causing it to exit as soon as the object is set active

acoustic arch
#

oh interesting thanks!

regal bear
acoustic arch
regal bear
#

oh okay πŸ˜„

slender nymph
regal bear
acoustic arch
odd crown
#

@summer stump
using UnityEngine;
using UnityEngine.UI;

public class InteractionPrompt : MonoBehaviour
{
public Image promptImage; // Referencja do obrazka SpacePrompt

void Start()
{
    // Ukryj obrazek SpacePrompt na starcie gry
    promptImage.gameObject.SetActive(false);
}

void Update()
{
    // SprawdΕΊ, czy gracz jest w zasiΔ™gu interakcji z jakimΕ› NPC
    bool playerInRange = IsPlayerInRange();

    // WyΕ›wietl lub ukryj obrazek SpacePrompt w zaleΕΌnoΕ›ci od tego, czy gracz jest w zasiΔ™gu interakcji
    promptImage.gameObject.SetActive(playerInRange);
}

// Metoda sprawdzajΔ…ca, czy gracz jest w zasiΔ™gu interakcji z jakimΕ› NPC
private bool IsPlayerInRange()
{
    // SprawdΕΊ, czy w zasiΔ™gu interakcji z graczem jest jakiΕ› obiekt z tagiem "Blocker"
    Collider2D[] colliders = Physics2D.OverlapCircleAll(GameObject.FindGameObjectWithTag("Player").transform.position, 1.5f);
    foreach (Collider2D collider in colliders)
    {
        if (collider.CompareTag("Blocker"))
        {
            return true;
        }
    }
    return false;
}

}

#

(the comments are in polish, dont worry ab that btw)

regal bear
eternal falconBOT
odd crown
summer stump
cosmic dagger
summer stump
odd crown
#

im kinda new in Unity and would use some help

odd crown
cosmic dagger
#

that's why you're asking here, no?

odd crown
#

maybe, idk, still new here

summer stump
cosmic dagger
summer stump
#

Also show the inspector for that script

odd crown
odd crown
#

gotta find that first

cosmic dagger
summer stump
#

Ok, 1.5 should be big enough then. Your player is quite tiny

#

Now the inspector for the script you showed

odd crown
#

i changed that to 3 and nothing happened so

odd crown
summer stump
#

Ah, it is ui

#

Oh, nm

#

That should be fine. Show the object you are checking for with the Overlap

odd crown
#

you mean the NPC I want to be in range with for this prompt to apear?

queen adder
#

how to get the center of screenspace again?

#

for a UI text popup

summer stump
odd crown
#

okay okay

swift elbow
queen adder
#

isnt that bot left?

swift elbow
#

Maybe I'm misremembering things, just create a UI element that's a child of the canvas and copy it's world position

summer stump
summer stump
# odd crown

Why is the collider size absolutely massive when the scale of other things is tiny

#

It is also offset 4 meters left

queen adder
#

i want it to always center no matter what, ig imma just do resol/2

odd crown
#

just... happened

#

like I said - im new to unity

#

the offset is gone btw

queen adder
#

i remember theres some method specialized at getting screenspace thingies before tho

#

i hate that resolutions arent given as v2's tho UnityChanOops

summer stump
# odd crown dont know mate

Well, everything looks superficially set up right. The collider is there, the tags are right, the code is valid.
I would do some Debug.Logs to verify what code is running. Add values like the players position and cound of colliders picked up. In the foreach log the name of the object

odd crown
#

damn, seems hard for me

#

nvm, gotta leave that for other time

summer stump
#

I recommend !learn

eternal falconBOT
#

:teacher: Unity Learn β†—

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

odd crown
#

ty for trying mate

summer stump
#

Oh, but did you reset the collider size?

odd crown
#

no I think

#

set it to 20 and something

summer stump
#

And offset to 0,0 if it isn't already

odd crown
summer stump
#

Yes

odd crown
#

and now I can walp through an NPC

#

well... half of him at least

#

and the prompt is not showing still

summer stump
#

Alright. Well, debug.logs are gonna give you the answer

fleet sky
#

Can i use a custom shader or camera to take in a cubemap and render to the rendertexture?

odd crown
#

maybe

fleet sky
#

my overall goal is to have a camera that renders to a cubemap, and then a shader that samples that view (with panini projection) and outputs to the screen

fleet sky
#

hrm okay

acoustic arch
#

odd issue i'm hoping will have an easy fix, there is a scriptable object for each card in my game and their can be duplicates of the same card

#

but now testing out battles i dealt damage to the opponents card but it changed the health of every scriptable object that was the damaged card

#

will i be forced to have some type of cardWrapper object to put it in?

summer stump
#

Generate a class from the SO data, and modify that class

#

So I guess yes to your last message

swift stone
#

Its my first time using visual studio with unity and codes in general i'm on the latest version of visual studio does anyone know how to fix this?

summer stump
swift stone
summer stump
acoustic arch
pure kite
summer stump
summer stump
# swift stone 2022

I would close visual studio completely, go into unity, go to the edit > preferences > external tools menu, and click regenerate project files

acoustic arch
#

then change it from there

summer stump
summer stump
acoustic arch
summer stump
#

The constructor for the poco would just take the SO and populate its values from that

#

But there are lots of ways to do it

static cedar
#

How to prevent this?

#

It gets pretty annoying./

summer stump
summer stump
dusty zinc
#

Hey yall, im trying to implement a system that allows me to save the players progress through files. The problem? The player picks up items that are added to the players class, each of these items contains a sprite. Whenever i convert my classes to json and add them to files I cant load the sprite back into then item. Im trying to use a class for sprites that maps their location to a id reference i save the id instead of the sprite and then use a function from this class β€œgetsprite()” to find it. But i cant seem to make it work for the life of me! Am i going about this all wrong? Does anyone have experience with this or have a simpler way?

acoustic arch
summer stump
acoustic arch
#

oh lol

summer stump
#

Does not inherit from MonoBehaviour or SO or anything

acoustic arch
#

here look at what i found online which i think will work

#

spiney199 example

#

4th comment

#

i think that's what your referring to as well?

summer stump
#

Didn't read too much, but what the second comment is saying is exactly what I am suggesting

#

Yeah, and the 4th

acoustic arch
#

alright cool, might have a decent bit of work to do fixing this around then

#

least i did this earlier than later

static cedar
swift stone
#

I'm opening this

polar acorn
#

there's no code there, it can't break on that

static cedar
polar acorn
eternal falconBOT
static cedar
#

It should be tbh. There are places where debugging does work (though scant). And i do get highlighting and warnings.

static cedar
#

What is happening. UnityChanDown

summer stump
static cedar
#

Ig i should update this and see.

teal viper
#

Also, make sure you don't have compile errors.

fleet sky
#

why does this loaded resource go kaboom after one frame?

#

is there some way to get a permanent reference? or is getting it every frame not a problem?

polar acorn
fleet sky
#

i definitely do things with it

polar acorn
#

Show the full !code and explain what you mean by "go kaboom"

eternal falconBOT
fleet sky
#
public class PaniniCamera : MonoBehaviour
{
    private Camera _cam;
    private Shader _shader;
    private Material _mat;
    private RenderTexture _cameraCube;

    private int _CameraCubeID;
    
    void Start()
    {
        _cam = GetComponent<Camera>();
        if (_cam == null) throw new Exception("This object is not a camera!");
        
        _shader = Resources.Load<Shader>("Shaders/PaniniShader");
        _mat = new Material(_shader);

        _CameraCubeID = _shader.FindPropertyIndex("_CameraCube");

        _cameraCube = Resources.Load<RenderTexture>("RenderTextures/CameraCube");
    }

    private void OnRenderImage(RenderTexture source, RenderTexture destination)
    {
        // _cameraCube = Resources.Load<RenderTexture>("RenderTextures/CameraCube");
        
        _mat.SetTexture(_CameraCubeID, _cameraCube);
        
        Graphics.Blit(source, destination, _mat);
    }
}

This starts throwing NPEs after one frame on the SetTexture line

#

when i uncomment that line, it works fine

polar acorn
fleet sky
#

wait one sec i changed something else and it's dying

#

huh nvm, guess it works now

rocky canyon
#

Edit > ☝️

static cedar
#

Ah yes.

versed light
#

in unity example code they have this in an editor script:
floatValue = EditorPrefs.GetFloat("FloatExample", floatValue);

if you have two different editor scripts both named "FloatExample" will this cause conflicts or does it seperate them based on the script

scenic shuttle
#

I need help for code simplification.
In my Code I have variables
"GameObject doorOne, doorTwo" and "Button btnOne, btnTwo;"

So I'm confused about how to make the code simpler if in my case I have 10 different buttons and 10 different doors.

It would look very stacked in my opinion if I listed 10 variables.

    [SerializeField] private GameObject doorOne, doorTwo;

    [SerializeField] private Button btnOne, btnTwo;

    private void Start()
    {
        btnOne.onClick.AddListener(() => Door("1", doorOne));
        btnTwo.onClick.AddListener(() => Door("2", doorTwo));
    }

    public void Door(string answerText, GameObject doorObject)
    {
        keypad.SetActive(true);
        this.answer = answerText;
        this.door = doorObject;
    }
versed light
#

put the doors in an array

#

same goes for buttons

#

then in start just loop the array where each door index matches a button index

#

now you just need to make sure your two arrays are in the correct order in inspector

scenic shuttle
versed light
#

if you need more complex answerText your array might need to be a key value pair where you have <GameObject,string> for your door array

versed light
#

if you use array not list then its .Length not .Count but you get the idea

scenic shuttle
#

Okay thanks. I will try it.

fleet sky
#

what's a good way to pass camera information around?

#

rotation, position, etc

versed light
#

make it a singleton

#

assuming theres only one camera through the duration of the game

fleet sky
#

ehh more or less

versed light
#

thats the simplest way the other way is those that need to know can just find the camera via FindObjectByType<Camera> in Awake

#

now they hold reference to camera

#

in other words dont pass camera info around, only pass reference to the camera its far simpler

#

oh wait if its the only camera its already in the global domain via Camera.main

#

so ignore all i just said and use Camera.main where you need it

fleet sky
#

so i technically do have multiple cameras

versed light
#

ah ok are you using cinemachine

fleet sky
#

uh i don't think so xD

versed light
#

if you have multiple cameras is only one active at any give time

fleet sky
#

well... hmm

scenic shuttle
fleet sky
#

no they're both technically active, just different render textures

#

there will only be one rendering to the main RenderTexture

heady horizon
versed light
fleet sky
#

okay lemme back up, sorry, singleton probably makes the most sense

#

it's more like a player

#

and there's only one player, and i need to pass around its information

versed light
#

like two rotations going on

heady horizon
#

i split it out so i'm just rotating the pivot_hurtbox empty game object

versed light
#

can you show inspector of cylinder

heady horizon
versed light
versed light
fleet sky
#

yeah, i only used the word camera because i don't really have a player yet, only a camera controller and a camera

onyx tusk
#

how 2 make dragging for 3d object? i need only x & z, i have an global y

heady horizon
#

it's all being done in this animation

rocky canyon
#

its not going to rotate correctly w/ scales being offset like that

#

if u need the scale offset use it as a child object and scale the child object instead. keeping the parent object scaled to 1:1:1

regal bear
#

Hi, im just making my first game, i have stats like hunger, thirst, fatigue, and i just change these independently but with the same formula, i feel like its unoptimized an i see a lot of kinda repetitive code, so how should i handle stats like these?

topaz mortar
topaz mortar
#

I have a bunch of combat logic that I need to run both on my client and server (anti-cheat)
They're both C#, but they're two separate code bases
Any tips on how to manage this so my combat doesn't desync?
The code is very similar, but it's different in a few places as well, not sure if it's possible to make all the actual combat logic the same and then separate the extra stuff that is different

eternal needle
topaz mortar
#

why wouldn't I want anti-cheat for a small game?

#

it's not a huge deal or perfect anti-cheat (probably) but some basics are fine not?

eternal needle
warped sorrel
#

building a 2d game like terraria/minecraft. should i make each block/tile it's own gameobject?

topaz mortar
#

my server is not build in unity

eternal needle
topaz mortar
#

well it's not really a question about networking or multiplayer
I just wanna know how to keep two separate code bases synced

astral falcon
# topaz mortar my server is not build in unity

I think you are mixing up somethings in your head when it comes to syncing. You do not want to replicate the whole code base on both sides, but the returning values or predicted ones when it comes to network.

topaz mortar
#

it has nothing to do with networking 😦

#

and yeah I do not want to duplicate the entire code base

#

I want to somehow make sure my combat logic remains the same on both client & server when I need to make changes to it

astral falcon
#

Again, the logic should happen on your client. The server should check if its allowed, but not dictate the logic of your game

#

or maybe you need to rephrase, what you are actually want to do. Combat logic sounds something for client for me. But that could be anything, as combat can be anything, so maybe you gotta explain a bit more

topaz mortar
#

I'm generating a random seed on my server, which is saved on the server and then sent back to the client
The client then handles combat using that random seed
At certain intervals, for example after an item drop, the client will send a notification to the server that something happened
The server then re-runs the combat logic to make sure everything is ok and gives the reward

astral falcon
#

Ah, now things get clearer. So where is your issue. You dont want things to get desynced. But your datastream already sounds like its quite static and dependent on seeds, so your code should already know whats the latest state for both sides

topaz mortar
#

the issue is that I have two separate code bases, one Unity client and one C# Module server
So I have most of my combat code twice
I want to prevent minor bugs sneaking into it when I change things that could cause a desync

astral falcon
#

Id say it is just bad practice to have it that way. I would refactor it before running into not updated code on one side because documentation was lagging to tell or whatever

topaz mortar
#

how?

#

They're different code bases? There's no way around that?

astral falcon
#

If they are different code bases but doing the same thing, one thing is doing too much. no matter the codebase, language or what not

topaz mortar
#

They're not doing the same thing.
The client is showing combat to the user.
The server is preventing cheating

astral falcon
#

Well, your messages are kinda confusing then. You have "most of my combat code twice" but "they are not doing the same thing"

topaz mortar
#

Let's say there's a formula for damage in there somewhere: int baseDamage = 100
And I want to change that value to 105 but I forget to do it on the server

#

that's what I want to prevent

astral falcon
#

yeah, DO NOT have it twice

#

jesus...

topaz mortar
#

How?

west sonnet
#

In my 2D game, I have enemies that will follow the player when they detect the player. How can I stop the enemies from falling off edges if the player jumps to another platform? I want them to stay on the platform they're on

astral falcon
# topaz mortar How?

Decide who will provide those values and deliver them to the other side. Id say your server and database have the values and set them on the client. Client is only using them. If the client wants to change them, they have to send a request to the server and the server decicdes if its correct or not.

topaz mortar
#

That makes sense for values, but what about actual code?
For example I have armor and % armor reduction and flat armor reduction
I first calculate % armor reduction and after that flat armor reduction
But I decide to change it around at some point, how do I make sure that logic is on both the client & the server?

What you're suggesting would have me execute all the code on the server. Which would then have to send back all the data to the client
Which is way too slow on the client and causes delays

astral falcon
# topaz mortar That makes sense for values, but what about actual code? For example I have armo...

Again, your server is providing values and predecting maybe. But if you have an item with armor and reduction, thats on client side. If you want to prevent the client to alter that armor stat, you can always sync now and then against the servers database of items for example. And saying "I decide to change it around at some point", what is IT? the default value? The calculation of the armor in general? In that case you are dreaming of a runtime compiled game...

#

and as someone else said before, this is like totally about networking and syncing logics. so maybe you get some more insights over there

topaz mortar
#

Let's start a thread for this? πŸ™‚

west sonnet
#

I have an edge detector object infront of my enemy. I want the ray detection to go straight down so I can use it to detect if the enemy is on the ground. How can I calculate the raydirection ?

#

To get it to go straight downwards

astral falcon
#

Vector.down?

astral falcon
west sonnet
#

This makes sense, right? The ray direction would be starting at the EdgeDetector object and going downwards?

astral falcon
west sonnet
#

My RayDirection is going 0,0,0 to my detector?

astral falcon
#

your direction is vector.down, and the origin is your detector

#

you are confused about position vector and direction vector πŸ˜‰ we all have been there

west sonnet
astral falcon
#

yes, so do not subtract your detector in your direction. the direction is only a direction, up down, left right, whatever, but from the origin you set within your raycast

topaz mortar
#

randomSeed = System.Convert.ToInt32(entry.Value);
entry.Value is an int64 from my server, why does a plain (int) cast not work?

astral falcon
topaz mortar
#

but then System.Convert.ToInt32 wouldn't work either? would it?

astral falcon
#

64 is like trillions, default int numbers to 33k or something. I am not sure if it will cry about it or just try to convert it and cut off, which would be bad for you. I do not think you need 64 in this case.

topaz mortar
#

Why is it even a 64 bit value? I'm just defining a normal int, which should be int32, it's C#, not unity

#

int randomSeed = random.Next(1, 2147483647);

#

Guess the server is transferring it as int64 for some reason

molten harness
keen dew
#

You'll have to show the entire movement code

west sonnet
#

I have this code for my enemies to detect when they are on ground. When they reach an edge, they stop, instead of running off the edge. Thing is, if the player goes onto the other side of the enemies, they don't try to go to the player, I think because the raycast for edge detection is detecting and edge, which stops the enemy from moving. Anyone have any idea how to get them to move again?

topaz mortar
#

Is there a more reliable random number generator other than System.Random?
It's not producing the exact same results on my server and my client using the same seed.
The client somehow makes some values 1 lower and some the same

maiden niche
#

Could someone help me with adding a new inventory system to my project. i already made the new inventory system its just that i dont know how to add it properly

keen dew
west sonnet
#

How can I flip a Ray Direction? I want it to face left then flip to face right

west sonnet
#

Why am I getting this error? This is all written in Update()

topaz mortar
languid spire
#

read the message. RayDirection is not always assigned to before you use it

topaz mortar
west sonnet
#

How so? It's dependent on a bool which is always true or false?

topaz mortar
languid spire
#

exactly so why the second if ?

west sonnet
#

ahhh, I see. Thank you

keen dew
molten harness
molten harness
molten dock
#

could i be helped trying to figure out why my onTriggerEnter dosent seem to be working

eternal falconBOT
deft grail
#

are you in 3D? do you have a Rigidbody? do you have a Collider with isTrigger checked?

keen dew
molten dock
#

there is no rigibody

languid spire
#

So why no Debug BEFORE the if to see if it's even executed?

deft grail
#

read the documentation for OnTriggerEnter/OnCollisionEnter

molten dock
#

thank you

languid spire
# molten dock thank you

you should not need someone to tell you to read the docs, you should be doing that automatically yourself

molten dock
#

yeah real

#

was just too blindsighted by other issues i forgot that i needed rigibody

proud fossil
#

can someone help me? my regular jump suddently became super weak but is still affected by "Jumping power" but when I jump by using the Jump Buffer it works normally for some reason

eternal falconBOT
proud fossil
#

ah

deft grail
# proud fossil ah

just without looking at the code your probably overwriting the velocity somewhere else before/while you jump

fleet sky
#

why do you have to get the parent object through the transform... sob

languid spire
fleet sky
#

unintuitive

#

it's not that bad but it's just unintuitive

#

one would expect to be able to have a game object and directly access its children

languid spire
#

true, you would expect the game object to have the parent. but the transform component deals with both parents and children, blame Unity devs for poor design choices

#

Basically, GameObject is just a holder for Transform, so you have to ask, why bother?

fleet sky
#

odd

#

it's weird that all objects need a transform tbh

#

but not necessarily a problem either

#

just kinda odd

languid spire
#

no, transforms hold all the real info, what is odd is that transforms need a game object

fleet sky
#

huh, i see

languid spire
#

if you think about it a Game Object is just a List of Components nothing more and one of those is the Transform

fleet sky
#

yes except Transform is special because it can't be removed

languid spire
#

yep because without position rotation and scale an object is just a figment of your imagination

fleet sky
#

what if i want a figment of my imagination weheline

languid spire
#

ScriptableObject

fleet sky
#

ah, lol okay

outer scarab
#

Hello, I wanna create a isometric game like Sims where players can create new rooms based on existing room models but I also want them to be able to edit those room models (add/delete grid cells). Is Unity Tilemaps suitable for this or do I have to generate my own tilemaps/grids programmatically?

outer scarab
#

Thanks :))

languid spire
outer scarab
languid spire
outer scarab
#

I know how to bundle assets

#

Thought you are talking about a pre existing one

languid spire
#

you want your users to edit your assets, so you make asset bundles or addressable packages provide them to your users which they can then edit and use in your game

outer scarab
#

Aaaaah

#

Gotcha

#

Thanks

fathom locust
astral falcon
fathom locust
#

sry

#

wait a min

astral falcon
#

!code

eternal falconBOT
fathom locust
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Thirdpersonmovement : MonoBehaviour
{
    public CharacterController controller;
    public float speed = 6f;
    public float turnsmoothTime = 0.1f;
    public Transform cam;
    float turnSmoothVelocity;

    void Update()
    {
        // Check if the controller reference is not null
        if (controller != null)
        {
            float horizontal = Input.GetAxisRaw("Horizontal");
            float vertical = Input.GetAxisRaw("Vertical");
            Vector3 direction = new Vector3(horizontal, 0f, vertical).normalized;

            if (direction.magnitude >= 0.1f)
            {
                float targetAngle = Mathf.Atan2(direction.x, direction.z) * Mathf.Rad2Deg + cam.eulerAngles.y;
                float angle = Mathf.SmoothDampAngle(transform.eulerAngles.y, targetAngle, ref turnSmoothVelocity, turnsmoothTime);
                transform.rotation = Quaternion.Euler(0f , angle , 0f);
            
                Vector3 moveDir = Quaternion.Euler(0f, targetAngle , 0f) * Vector3.forward;
                controller.Move(moveDir.normalized * speed * Time.deltaTime);
            }
        }
        else
        {
            Debug.LogWarning("CharacterController reference is not assigned!");
        }
    }
}
astral falcon
#

What have you tested yet and whats not expected to happen?

fathom locust
#

My sprite should be walk correctly but unfortunately it's not

#

When I pressed WASD It's worked normally but when I didn't pressed them My sprite was flown away

#

as you can see in the video

loud mango
#

how do i make it so that as long as i keep pressing a button i keep moving ( for mobile unity 2d game )

#

idk what to use

#

like button.something..... idk something

astral falcon
fathom locust
#

the capsule one lamooo

loud mango
#

ofc, the only rule is to use a capsule as a player duh

fading trench
#

Vector3 moveDir = Quaternion.Euler(0f, targetAngle , 0f) * Vector3.forward;