#💻┃code-beginner

1 messages · Page 130 of 1

wicked blaze
#

i tried something but didt really work

modest dust
#

Showing something in the inspector isn't the only purpose of using 'public'. Read about encapsulation

novel shoal
modest dust
novel shoal
#

but what's the point of making things private if they don't affect anything?

celest flax
#

I'd like to check if a list contains every value in either an array or another list using just an if-statement. What would be a good way to do this?

novel shoal
novel shoal
spiral oak
modest dust
novel shoal
modest dust
gaunt ice
#

encapsulation is oop concept

#

google it and you will get the results

novel shoal
#

in the learn.unity pathway there wasn't oop

gaunt ice
#

there actually is, but just one chapter iirc

modest dust
spiral oak
dire torrent
#

whats confusing about it? I would suggest learning basics of programming before getting into unity.
I would spoonfeed you code but that probably wont be healthy for you either. And I assume you're asking here because you wanna learn rather than just getting spoonfed code that could be provided to you by chatgpt or elsewhere 😄

novel shoal
dire torrent
novel shoal
#

i come from python, there i learned about oop, i also did a full course with classes too, but since i hadn't used them ever since i forgot about them

dire torrent
#

i see

novel shoal
celest flax
quick edge
#

(already posted this yesterday, but maybe someone can help me today ;) )

Yo! I have a problem. I have created an empty game object (a pivot) as a parent of a Camera. When I'm not in play mode if I rotate the pivot the camera rotate around it like supposed, but when I'm in play mode it doesn't work anymore. The camera rotate around itself. I don't understand why. I didn't find any solutions on the internet. Can you help please?

Edit : Someone told me to remove "* Time.deltaTime" so now this isn't in the code naymore

https://gdl.space/luviwaxuwa.cs

novel shoal
gaunt ice
#

hash table is data structure, it is just a name to desrcibe something that can offer you a O(1) lookup for given key
dictionary is hash table (or hashmap)

spiral oak
novel shoal
gaunt ice
#

btw the name is not important

spiral oak
#

Just researching about what I want to do before actually doing it works for me

novel shoal
novel shoal
dire torrent
quick edge
spiral oak
dire torrent
quick edge
#

np

#

And something I didn't mention. When I'm in play mode and I manually rotate the pivot, the camera rotate on itself instead of rotating around the pivot

dire torrent
quick edge
#

The camera rotate locally, not around the pivot

#

If that makes sense

dire torrent
#

ah

novel shoal
quick edge
dire torrent
#

or maybe you have a script on the pivot AND the camera var

quick edge
lunar tapir
#

Hi, I am trying to make a cyborg futuristic hacking game.

I have this OperatingSystem script which goes onto cyborgs with a serialized list of Applications

public class OperatingSystem : MonoBehaviour {
    private Root root;
    [SerializeField] private List<Application> applications;

    private void Start() {
        root = new Root();
        applications.Add(new TerminalApplication(this));
    }
}```

Here is my application class. It is not a MonoBehaviour but all its fields are serialized ( as far as I understand ).
```cs
[Serializable]
public abstract class Application {
    [SerializeField] private string name;
    [SerializeField] private bool adminPerms;
    [SerializeField] private OperatingSystem os;

    public Application(string name, OperatingSystem os = null) {
        this.name = name;
        this.os = os;
        if (os != null) { adminPerms = true; }
    }

Here is the TerminalApplication class which inherits from Application.

[Serializable]
public class TerminalApplication : Application {
    public TerminalApplication(OperatingSystem os) : base("TERMINAL", os) {}
}```


It should show the list of applications in the inspector as far as I understand, but it is not showing (as seen in the screenshot). What might be wrong?
dire torrent
quick edge
#

I don't understand at all x)

#

I saw one person having the same problem on the Internet, but nobody answered the solution

wicked blaze
dire torrent
dire torrent
quick edge
#

no way

dire torrent
#

you're modifying the camera's position

dire torrent
#

not about rotation but when you move the camera

quick edge
#

Ohhhhhhhhhhhhhhhhh

#

Yes

dire torrent
#

you need to move pivot

ancient island
#

hey guys, I'm designing my game's UI and I wonder which is the lowest screen resolution I should design for? I've been working on 800x400 portrait (yes, it's forced to be portrait) provided by unity, but when arranging some stuff they simply don't fit into the screen (with other game components) or they are too small for larger screen resolutions. I already know about canvas scaler and configured it to my needs, but the problem persists so I wonder if people actually uses 800x400 phones

gilded pumice
#

hey guys how can I reference a public variable in a different script (attached to a different game object if this helps) I've already referenced the script and that works fine for calling methods from the other script, but I can't for the life of me figure out how to reference a variable

quick edge
#

I set the camera behind the character. This prevent the camera from "rotating" around the pivot because in reality it's not rotating but moving around ?

#

This is the problem ?

ancient island
dire torrent
#

and then you can just move the pivot on the exact player's position without offset

little garden
#

im not sure how to compute the time dialation seconds

quick edge
#

Thanks! It was simple my bad x)

languid spire
dire torrent
gilded pumice
languid spire
#

on which line?

gilded pumice
#

the if line

#

it doesn't like hardGameManager.phaseNumber

#

which is script variable with public variable from that script

languid spire
#

then hardGameManager is null, so you're not referencing it correctly

gilded pumice
#

am I supposed to use the assigned variable to the script or the actual name of the script here?

#

I thought it was the assigned variable that I declared in start

#

hardGameManager = GameObject.Find("Game Manager Hard Mode").GetComponent<HardModeGameManager>();

languid spire
#

do you even check to see if that line works?

dire torrent
# wicked blaze trueeee

imma dm you in a lil while after a work call to help you understand without spoonfeeding 😄

hidden sleet
#

currently watching a tutorial on saving data using json, but they say they'll be using the BinaryFormatter, however someone here yesterday said that isn't wise as it was depreciated or something. What else could be used then?

wicked blaze
#

i made it myself

wicked blaze
#

im suprised it actually works

#

but im happy

#

and now i dont really know what else to add

novel shoal
dire torrent
#

line 31 has a ; after while :D

novel shoal
wicked blaze
wicked blaze
novel shoal
wicked blaze
#

damn

#

cool feature

dire torrent
# novel shoal right

also i think you just need to use if instead of while there since Update is essentially a loop itself LUL

novel shoal
#

i'm 99% sure it won't work tho

wicked blaze
gilded pumice
# languid spire do you even check to see if that line works?

the one in start certainly does as I've been able to call methods from that script just fine. I'm getting the null reference error specifcally on that line (the if conditional). It is not a compilation error, it only kicks it out when I press the space bar during test. I certainly don't see any errors with syntax but I'm also pretty new

languid spire
#

null ref is a runtime error not a compilation error. it means something is null. so on this line

if (Input.GetKeyDown(KeyCode.Space) && hardGameManager.phaseNumber > 0)

the only thing that could be null is the hardGameManager variable

wicked blaze
#

hmmmm is adding some hand movement to the game an good idea just for the player to not be an capsule

#

some capsule hands 🙂

#

xd

#

im going to try to make an item pick up feature and try to learn something new

novel shoal
swift crag
#

Rigidbody.velocity += new Vector3(0, wallDrag, 0);

This runs every frame, so the amount the velocity changes per second will depend on your framerate.

hidden sleet
#

currently working on a saving and loading system, I guess I can put the save function in the on application quit method?

swift crag
#

Consider using AddForce -- and doing it in FixedUpdate, too.

swift crag
#

Application.quitting won't fire if the game crashes or gets forcibly closed

hidden sleet
#

switch levels sounds good, not sure how I would get it to recognise that the scene has been switched though

swift crag
#

SceneManager.activeSceneChanged

#

that event fires when the active scene changes (unsurprisingly)

#

You could also just save the game when you decide to load a new scene

hidden sleet
#

shrimple as that

swift crag
#

since you'll presumably have code whose job is to load levels

swift crag
hidden sleet
#

at the moment I lierally just have a button that switches scenes and that's it, got no custom loading stuff yet

swift crag
#

Although, maybe other parts of your code are changing your velocity so quickly that you can't get off the ground at all

novel shoal
swift crag
#

add some Debug.Log statements to find out exactly what is going on

#

also, if you're now in FixedUpdate, you will need to change how you get input

#

specifically, GetKeyUp is flaky in FixedUpdate

#

because it only returns true for one frame

#

you might get two frames before another physics update happens

hidden sleet
#

what's the difference between fixed and regular?

novel shoal
swift crag
swift crag
#

Update runs once per frame

#

FixedUpdate runs right before the physics update

#

which normally happens 50 times per second

swift crag
#
bool wantsJump = false;

void Update() {
  if (Input.GetKeyUp(KeyCode.Space))
    wantsJump = true;
}

void FixedUpdate() {
  if (wantsJump) {
    wantsJump = false;
    // do a jump
  }
}
#

like so

warped roost
#

what is the best and most efficient way to learn c#?

novel shoal
#

@swift crag using debug.log, it prints something to the console, but it adds no force

languid spire
hidden sleet
#

I learnt it back at secondary school, which was a good way to point me in the right direction, but from scratch I'm not really sure what the best way would be

#

I've got an absolutely huge handbook that I've written which contains all the things I've learnt though

#

oh, I seem to have an issue. When you quit the application by pressing the play button again is it suppose to clear out this inventory?

dire torrent
hidden sleet
#

well in this case the inventory should already have stuff in it

#

since I'm aiming to save it when the application closes

#

but does putting it there mean the object already has its data wiped before it can save or something?

buoyant knot
#

uh, that is dangerous business

hidden sleet
#

in what way

buoyant knot
#

on application quit, several things might be null

hidden sleet
#

yeah that's what I was thinking

#

not sure how else to handle it then

buoyant knot
#

same thing happens in OnDestroy

hidden sleet
#

unless I save every time an item is picked up perhaps?

buoyant knot
#

don’t save on application quit

#

save at specific points like autosaving

dire torrent
#

just save in between or when you click the quit or exit to menu button :O

buoyant knot
#

openning and writing files is expensive shit

hidden sleet
#

don't have any kind of auto save system at the moment

swift crag
#

you should save often, but not too often (:

#

tighten bolt. do not overtighten. do not undertighten.

swift crag
#

i've never thought about that

buoyant knot
#

you also don’t want to save if the player expects it to not be saved

swift crag
#

I'm only ever saving data that isn't on scene objects anyway

dire torrent
#

maybe make a save button too on top of periodical saves if player chooses to keep on autosave

hidden sleet
#

well this is only meant to be a uni project, it's scale is absolutely tiny. I suppose saving on scene change might work, but it's only played for a couple of seconds in total

buoyant knot
#

especially if you force quit or something

novel shoal
buoyant knot
#

or stop the process, or crash

hidden sleet
buoyant knot
#

find a trigger where it makes sense to save

#

something that happens not super frequently

hidden sleet
#

scene change might be useful, but I also don't want them to pick something up then quit and lose it

buoyant knot
#

or a button the player can press

#

most modern games have manual save, autosave, and a button to turn off autosave

hidden sleet
#

I mean, this is literally all I have at the moment. You walk over the boxes and it adds stuff to an inventory which carries over to the next scene, this isn't going to have a save slot system

novel shoal
buoyant knot
hidden sleet
#

alrighty then

#

not sure when that trigger could possibly be though

buoyant knot
hidden sleet
#

since the user should be able to leave at any point, they could potentially pick up one thing then leave the game which is valid

#

best way I could describe it is a pokemon go type thing where you can just load it up, pick something up then shut it off

buoyant knot
hidden sleet
#

but I assume that just stores it all on a database somewhere else, not locally

dire torrent
# novel shoal guys please

i think it'll be a good idea at this point to not use velocity for movement but just move using AddForce
a mixture of both is gonna be pretty inconsistent to use and will result in more issues down the line

buoyant knot
#

i use both when I want to make .velocity methods override added forces

hidden sleet
#

also why is everything red

dire torrent
novel shoal
buoyant knot
#

AddForce impulse mode directly modifies velocity instantly btw

#

it’s just something you need to be aware of

#

AddForce (force mode) adds a force vector to be added in at start of similation.
Changing velocity changes velocity as of right now

dire torrent
buoyant knot
#

it does

#

at least in Physics2D

novel shoal
buoyant knot
#

AddForce in impulse mode directly changes your velocity from one line of code to the next. and does not change totalForces

#

maybe 3D is smarter

dire torrent
#

that's probably not the only issue but should be an issue

buoyant knot
#

your jump method should probably set rigidbody.velocity = new Vector2(rigidbody.velocity.x, jump speed);

dire torrent
#

you can do it with AddForce

#

that code is fine, try changing the number, increase it

novel shoal
dire torrent
#

and Rigidbody.AddForce(new Vector3(0, jumpForce, 0), ForceMode.Impulse);

#

i think that's the issue... you arent making a new Vector3

buoyant knot
#

setting y velocity makes your jump a specific height from start position, every time, even off of a falling platform.
AddForce impulse mode will make your jump just add force from your starting velocity, so jumping from falling platform can still have a downward velocity

#

depends on what you want. both are valid

hidden sleet
#

if the json here is just {}, even though the serialisable tag is on the slot that the container is a type of, is that just down to the fact that the item itself can't be properly serialised?

buoyant knot
#

i prefer set velocity, which is more cartoony, and simpler for the player to know where they will end up

#

AddForce maintains reference frame, and conserves momentum

novel shoal
#

horizontalInput = Input.GetAxis("Horizontal");
Rigidbody.AddForce(new Vector3(horizontalInput * horizontalSpeed, 0, 0),ForceMode.Impulse);
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
Rigidbody.AddForce(new Vector3(0, jumpForce, 0),ForceMode.Impulse);
isGrounded = false;
}
@dire torrent

dire torrent
#

looks fine and yea loop's point is valid, if you want to air jump that's gonna be a bit iffy

buoyant knot
#

that will work, but in 2D, you should use Vector2

dire torrent
#

he's doing 2.5D :D

#

so 3d objects

buoyant knot
#

is your rigidbody in dynamic mode?

novel shoal
#

it is

#

my bad

dire torrent
#

put a debug.log and see if the code is getting called

novel shoal
#

the wall jump works only once

buoyant knot
#

use Debug.Log when you call AddForce to know if it is getting called at all

#

because it could be adding the force followed by something blocks it, OR it just never tries to add the force at all

dire torrent
buoyant knot
#

and make sure your rigidbody is in continuous collision detection mode

#

default is discrete, which is wrong

novel shoal
#

i think the issue is that i add a -5 force on the x axis on the wall jump

#

even if the wall is on the left

#

but idk how to make it so that it's +-5 depending on the direction of the movement

hidden sleet
#

strange, I can serialise the whole class but not the list in the class. So when serialising, can you not just directly pass in a list? Does it have to be a class with a list in it?

novel shoal
hidden sleet
#

raycast perhaps?

novel shoal
#

what?

hidden sleet
#

well to detect the wall the first one I'd try would be a raycast to the left or right that juts out a short distance, and if it intersects the wall, which could have a tag on it, it knows it's on the wall

#

or a collider perhaps

novel shoal
#

i need to see a tutorial on what raycast is

hidden sleet
#

I watched Game Dev Beginner's one on it recently, was pretty good

buoyant knot
#

In 2D, raycast has a very similar cost to casting your whole box collider

swift crag
#

A raycast is like shooting a laser into your scene.

#

The laser stops when it hits a collider.

#

It's part of a small set of physics queries that are all extremely useful

novel shoal
#

i checked unity's tutorial on raycast

buoyant knot
#

i never raycast. I always use Cast on my colliders, because it gives me more complete info

novel shoal
#

so i have to create a ray on collision with a wall, whose origin is the player and check which is the nearest wall?

buoyant knot
#

and the moment you shoot 2 raycasts for one collider, it straight up costs more than .Cast

spiral oak
#

Hey, I'm a bit unsure about something about C#: If I use a using clausule when using unmanaged resources (in my case StreamWriter), there's no need to make the class IDisposable, right?

buoyant knot
#

there are a few ways to cast.

ContactFilter2D contactFilter = // make a contact filter that only shows terrain with walls
List<RaycastHit2D> hits = new();
int hitCount = playerCollider.Cast(Vector2.left, contactFilter, hits);
then check hits for valid hits

novel shoal
#

can't also i do transform.position - collider.transform.position and check wether it's positive or negative?

buoyant knot
#

there are several ways to make that better, but that is the general idea

languid spire
buoyant knot
#

you can also call playerCollider.GetContacts, which gives you all the contacts for the player collder. Then sift through them to check for a wall

hidden sleet
#

what happens then when you call collider.Cast instead of just raycast?

buoyant knot
#

collider.Cast checks moving the whole shape

spiral oak
hidden sleet
#

so would that essentially perform multiple raycasts across the whole collider to the lefT?

hidden sleet
#

oh wait no it sends out the whole shape

#

ah

languid spire
hidden sleet
#

like sending out a ghost of yourself

buoyant knot
#

if you shoot a raycast, it’s like a laser, which would have gone straight though and missed both green shapes

hidden sleet
#

does that also exist in 3D or is it just 2d?

buoyant knot
#

idk about 3D

#

i just know it’s super convenient in 2D

hidden sleet
#

sounds like it would be

spiral oak
languid spire
hidden sleet
#

goodness me my project is already becoming a mess

spiral oak
gaunt ice
#

you use some idisposable class doesnt mean your class have to be idisposable

spiral oak
languid spire
spiral oak
languid spire
#

yes

novel shoal
#

@dire torrent

dire torrent
#

what do you mean

gaunt ice
#

you must implement the dispose method even if the method body is empty

spiral oak
# languid spire yes

Then I guess it makes the garbage collector delete the class instance when the using clausule ends. Am I wrong?

novel shoal
#

on collision i did transform.position.x - collision.gameobject.position.y to check the direction of the player on the wall

languid spire
dire torrent
novel shoal
ivory jacinth
#

Hi could someone help me with this error

languid spire
#

not unless you post a proper screenshot

spiral oak
novel shoal
#

@languid spire can you help me, too?

languid spire
novel shoal
dire torrent
ivory jacinth
novel shoal
dire torrent
#

I imagine you could do collision.GetContact(0).point.x but idk

#

sorry yea collision

dire torrent
novel shoal
#

i forgot to use collision.gameobject.transform.position, and instead used collision.transform.position

hidden sleet
#

there's a difference?

languid spire
spiral oak
dire torrent
#

shouldnt make a difference

novel shoal
shut bronze
#

Hey Guys, I have a pretty advanced problem. I am currently working on a registration screen in Unity while storing the user data on a MySQL Database. Does somebody here have experience on the subject?

novel shoal
#

but it doesn't change if the collision is negative

shut bronze
# languid spire yes, what is the problem?

The storing of the Data is working fine, but I hav implemented a function where the php Code should echo a Error Code when the Username is already taken. The function is working, but i don't get the Error code that should be echoed

languid spire
#

that sounds more like a php problem rather than a sql problem

shut bronze
languid spire
#

no, I don't do php

shut bronze
dire torrent
#

ohh it could happen when your player's X is negative
so
if player is left of the wall player.x - collision.x could be -3-6 and now you get -9 which means you apply force on the right side when you should be applying force on other side

#

or wait bad math on my end var

#

nvm idk lol

novel shoal
#

@dire torrent actually you are right, i switched them and it works

#

tyyyy

polar acorn
languid spire
#

also a typical X Y problem

novel shoal
#

gotta suffer to reach perfection

hidden sleet
#

why is it that so many times when I try to do the 'attach to unity and play', VS goes into play mode but unity itself just freezes up and does nothing

polar acorn
hidden sleet
#

nope, it's just doing nothing

polar acorn
#

Does the game run normally without being in debug mode

hidden sleet
#

perfectly fine

#

its just like just spending an absolute preparing itself to run in debug

#

oh and now somehow implementing file saving has broken my ui... neat

languid spire
#

how is that even possible? System IO has absolutely nothing to do with UI

fickle plume
#

@dire torrent No off-topic media, please

hidden sleet
novel shoal
#

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

public class EnemyBehaviour : MonoBehaviour
{
public float minXValue;
public float maxXValue;
public float xSpeed;
public Rigidbody rb;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
rb.velocity = new Vector3(xSpeed, 0, 0);
if (transform.position.x < minXValue || transform.position.x > maxXValue)
{
xSpeed *= -1;
}
}
}

this should invert the enemy direction if it gets out of selected bounds, but, using a cylinder as an enemy it's buggy and doesn't work

wintry quarry
#

not to mention you're inverting it AFTER you already set the velocity this frame
so there wil be a 1 frame delay before it takes effect

ivory bobcat
#

Define buggy?

burnt vapor
eternal falconBOT
novel shoal
#

even if it's inside the bounds

wintry quarry
#

how about this:

    public float speed;
    float currentSpeed;

    void Start() {
        currentSpeed = speed;
    }
    
    void FixedUpdate()
    {
        float xPos = rb.position.x;
        if (xPos < minXValue) currentSpeed = speed;
        else if (xPos > maxXValue) currentSpeed = -speed;
      
        rb.velocity = new Vector3(currentSpeed, 0, 0);
    }```
amber spruce
wintry quarry
#

Looks like a problem in SkinChangedServerRpc at Assets/Scripts/MultiplayerPlayerController.cs:163

amber spruce
#
 [ServerRpc(RequireOwnership = false)]
 private void SkinChangedServerRpc(int variable)
 {
     SkinNetwork.Value = variable;
     Skin = variable;
 }
 public void SetSkinWizard()
 {
    //CharacterSelect = GameObject.Find("CharacterSelect");
     //SkinNetwork.Value = 2;
     SkinChangedServerRpc(2);
     animator.runtimeAnimatorController = WizardCombo[0].animatorOV;
     animator.Play("Attack", 0, 0);
     m_Coll.size = new Vector2(0.35f, 0.66f);
     m_Coll.offset = new Vector2(0f, 0f);
     CharacterSelect.SetActive(false);
 }

those are the 2 functions it has a problem with

wintry quarry
#

based on the rest of the trace possibly you have a NetworkObject that was not properly initialized

amber spruce
ivory bobcat
amber spruce
#

like should they have a network object component

#
        SkinNetwork.Value = variable;
#

this is 115

        SkinChangedServerRpc(2);
wintry quarry
#

Whatever object MultiplayerPlayerController is on needs to be a NetworkObject

amber spruce
#

it is

ivory bobcat
wintry quarry
#

and how was it created?

wintry quarry
amber spruce
wintry quarry
#

the NRE is happening inside some deepish networking stuff

ivory bobcat
wintry quarry
#

which kinda implies to me the network variable is somehow not set up properly, or the network object itself isnt

amber spruce
#

everything works fine otherwise

ivory bobcat
#

So you get the error because something is null. Which is expected - the entirety isn't working properly.

prime lodge
#

how to make x increase when y is decreasing

#

in script

ivory bobcat
#

Two options:

  • Record the previous value and check if it's changed.
  • When you change the value, update the other.
prime lodge
#

but i mean in equation

frosty hound
#

x ++
y --

is the equation

#

Unless you have something more elaborate? But not according to your initial question

amber spruce
gilded pumice
#

Does anyone have an idea why a UI won't update a number?

public void PhaseAbilityNumber(int phaseToAdd)
{
    phaseNumber += phaseToAdd;
    if (Input.GetKeyDown(KeyCode.Space) && phaseNumber > 0)
    {
        phaseNumber--;
    }
    hardPhaseText.text = "Phases Left " + phaseNumber;

}

The code works in every way except it doesn't decrement phaseNumber visually (it still obviously recognizes that the number has been subtracted) I'm sure the answer is simple I just am unsure what to do. I tried moving the if statement to update but that didn't work either. It's like the "phaseNumber" part of the .text isn't updating

prime lodge
gilded pumice
#

it updates positively but not negatively visually

prime lodge
#

but i have no idea how to do it

ivory jacinth
#

Hi could someone help me

gilded pumice
languid spire
gilded pumice
#

an int

languid spire
#

what is line 21 and 22?

ivory jacinth
#

Where ?

amber spruce
#

so each character is a button and the samurai one works but the other 3 dont i get the previous error when i try pressing the other 3

public void SetSkinSamurai()
{
    SkinChangedServerRpc(1);
    animator.runtimeAnimatorController = SamuraiCombo[0].animatorOV;
    animator.Play("Attack", 0, 0);
    m_Coll.size = new Vector2(0.31f, 0.7f);
    m_Coll.offset = new Vector2(0.06f, 0f);
    CharacterSelect.SetActive(false);
}
public void SetSkinWizard()
{
    SkinChangedServerRpc(2);
    animator.runtimeAnimatorController = WizardCombo[0].animatorOV;
    animator.Play("Attack", 0, 0);
    m_Coll.size = new Vector2(0.35f, 0.66f);
    m_Coll.offset = new Vector2(0f, 0f);
    CharacterSelect.SetActive(false);
}
public void SetSkinKnight()
{
    SkinChangedServerRpc(3);
    animator.runtimeAnimatorController = KnightCombo[0].animatorOV;
    animator.Play("Attack", 0, 0);
    m_Coll.size = new Vector2(0.38f, 0.64f);
    m_Coll.offset = new Vector2(-0.02f, 0f);
    CharacterSelect.SetActive(false);
}
public void SetSkinButter()
{
    SkinChangedServerRpc(4);
    animator.runtimeAnimatorController = ButterCombo[0].animatorOV;
    animator.Play("Attack", 0, 0);
    m_Coll.size = new Vector2(0.46f, 0.83f);
    m_Coll.offset = new Vector2(0f, 0f);
    CharacterSelect.SetActive(false);
}

those are each characters functions

frosty hound
languid spire
ivory jacinth
frosty hound
ivory jacinth
#

this is the script

gilded pumice
ivory jacinth
languid spire
#

Vector 2 ?????????????

gilded pumice
#

its line 22, character 34 according to your error message

ivory bobcat
languid spire
#

Obvious Syntax Error

ivory jacinth
swift crag
#

given that your avatar is the python logo, I presume you've written python before

ivory bobcat
#

Vector and 2 needs to be joined

languid spire
#

what do you think should be in place of Vector 2 ?

swift crag
#
foobar = 3
print(foo bar)
swift crag
#

you've made the same mistake

ivory jacinth
languid spire
#

I give up

#

which is correct c# syntax?
Vector 2
Vector2
?

ivory jacinth
#

this one Vector2

languid spire
#

so why are you not using that?

#

btw your !IDE is probably not configured otherwise it would have shown you this

eternal falconBOT
ivory jacinth
#

thank you very much @languid spire sadok

quick edge
#

Yo! I want to Clamp an (euler) angle between -90 and 90 but angles in Unity are between [0, 360] (from what I saw). I saw people create functions to convert it between [-180, 180] but my question is. Is it easier to Clamp a Quaternion ?

languid spire
#

you cannot clamp a Quaternion

quick edge
#

R.i.p...

ivory bobcat
#

Those values wouldn't be euler values

quick edge
#

Then the only solutions is to convert to [-180, 180] ?

#

Or whatever I want ?

swift crag
#

well, that would involve converting your quaternion into euler angles

#

can you explain what you want to accomplish first

#

not "clamp an angle"

#

what are you making your game do?

novel shoal
quick edge
#

I have a camera on a player. I want the camera to be locked between -90 and 90 degrees (on top of my character or on the bottom)

#

I used Mathf.Clamp() but it doesn't work because the transform.position.eulerangles.x is between 0 and 360

#

The solution I found is what I said earlier. But I want to know if this is the correct way to process (if there is one)

swift crag
#

i would suggest just storing the pitch you want the camera to have in a float

#

and then directly set the camera's rotation based on that

wintry quarry
quick edge
#
    private void HandleRotation()
    {
        float xAxisMouse = _playerInputActions.GroundedGameplay.CameraMovement.ReadValue<Vector2>().y;
        float yAxisMouse = _playerInputActions.GroundedGameplay.CameraMovement.ReadValue<Vector2>().x;
        
        transform.Rotate(-xAxisMouse * _rotationSpeed, 0f, 0f, Space.Self);
        transform.Rotate(0f, yAxisMouse * _rotationSpeed, 0f, Space.World);

        yPivotAngle = transform.rotation.eulerAngles.x;
        yPivotAngle = Mathf.Clamp(yPivotAngle, _yMinimumRotation, _yMaximumRotation);
        transform.rotation = Quaternion.Euler(yPivotAngle, transform.rotation.eulerAngles.y, transform.rotation.eulerAngles.z);
    }
#

This is my code actually

swift crag
#
float yaw;
float pitch;

void Update() {
  yaw += // yaw input
  pitch += // pitch input
 
  yaw = Mathf.Repeat(yaw, 360);
  pitch = Mathf.Clamp(pitch, -90, 90);

  camera.rotation = Quaternion.AngleAxis(yaw, Vector3.up) * Quaternion.AngleAxis(pitch, Vector3.right);
}

This is how I usually do it.

novel shoal
wintry quarry
wintry quarry
quick edge
wintry quarry
swift crag
#

You can definitely turn a rotation back into a pitch and yaw

#

But it's annoying

novel shoal
wintry quarry
novel shoal
wintry quarry
#

why not pause the game e.g. with timeScale when it's not active

swift crag
#
            Vector3 flattened = Vector3.ProjectOnPlane(entity.transform.forward, Vector3.up);
            yaw = Vector3.SignedAngle(Vector3.forward, flattened, Vector3.up);

            Vector3 rotated = Quaternion.AngleAxis(-yaw, Vector3.up) * entity.transform.forward;
            pitch = Vector3.SignedAngle(Vector3.forward, rotated, Vector3.right);

This is how I figure out the right pitch and yaw when taking control of an entity in my game

wintry quarry
gilded pumice
#

Why does this visually update when I add but not when I subtract? do I need to pass 2 parameters to this method for that? It seems to functionally decrement, but it doesn't update the number on the screen (only positively) any ideas?

public void PhaseAbilityNumber(int phaseToAdd)
{
phaseNumber += phaseToAdd;
if (Input.GetKeyDown(KeyCode.Space) && phaseNumber > 0)
{
phaseNumber--;
}
hardPhaseText.text = "Phases Left " + phaseNumber;
}

quick edge
#

What does that mean ?

novel shoal
swift crag
#

(and Roll is...rolling!)

novel shoal
swift crag
#

it's the remainder operator

#

-1 % 5 == -1

#

oh, well

#

yes, that's right! :p

#

Repeat is the modulus operator. It's just that people often call % "modulo" when it really isn't

ivory bobcat
swift crag
#

(please, microsoft, give me a %% operator)

swift crag
gilded pumice
swift crag
#

Perhaps you wanted GetKey?

gilded pumice
lunar tapir
#

Hi, how can I create a Text Input action in the new Input system?

quick edge
swift crag
#

I don't know what you intend for this code to do

swift crag
quick edge
#

ok lmao

swift crag
#

But you want X-axis rotation in your code

#

That's what you're using

quick edge
#

Then the other one serves no purpose ?

swift crag
#

You called it "y axis", but that's probably because it's coming from the Y part of player input

swift crag
#

If you only want to tilt the camera up and down, you're only changing its pitch, or its local X rotation

quick edge
#

Okay

delicate portal
#

Hey what can I do against camera object clipping and stuff like theese?

gilded pumice
#

and it will go up which makes the mystery even worse

swift crag
#

how do you know the program "recognized" that the value went down?

rich adder
ivory bobcat
gilded pumice
ivory bobcat
#

Likely how you're calling this with a negative value simply likely isn't occurring instead

swift crag
gilded pumice
#

I'll give it a go

quick edge
swift crag
#

The point is that you track the pitch value you want

#

and then directly set the rotation based on it

#

you aren't just adjusting the existing rotation

#

note that you'll probably want to switch to local rotation here

#

so that the camera is being pitched up and down relative to its parent

ivory bobcat
delicate portal
rich adder
quick edge
#

If it's not in your world it can't clip

rich adder
#

yea I suggested that already, its called camera stacking

quick edge
#

My b

rich adder
#

that wont give you shadows on the weapon from the world you're in, which is a major drawback

#

but if you dont care about that then its fine

naive wharf
#

I've got a bunch of objects with the same script and one manager object with a manager script. Now I want the manager script to have a list with every object that has the other script. What would be a smart way of doing that where I wouldn't have to drag and drop the objects in the list in the editor?

swift crag
#

I like to go with the physically accurate approach of pulling the weapon back

rich adder
#

same

swift crag
#

if you also accurately fire from the gun's muzzle, rather than just raytracing from the center of the screen, this could have some gameplay implications

ivory bobcat
rich adder
naive wharf
#

all the objects are there at the start i dont spawn them in

rich adder
#

whats wrong with the inspector then? its usually the fastest solution

naive wharf
#

not if i have 30 objects

#

and i need to change them

rich adder
#

the amount is inconsequential

#

you can select all and drag them in array

naive wharf
#

when my game evolvs

naive wharf
rich adder
swift crag
#

If you're always adding and removing objects, I would just grab them all in Awake

naive wharf
#

well I need to add new ones and remove old ones while developing and i think its annoying to have to reasign them

swift crag
#

or have each object report itself to the manager

#
void Awake() {
  Manager.instance.Register(this);
}
#

this sort of vibe

rich adder
# naive wharf oh true

if you type t:MyScript in hierarchy search, you will find all your objects btw so you dont have to go through the hirerchy

swift crag
#

I have an EntityManager that keeps track of all entities in my game

#

at the end of the entity's Awake method, it registers itself

#
            EntityManager.Instance.Register(this);
ivory bobcat
# naive wharf when my game evolvs

It's incremental. You'd provide the change as change occurs. Automation is usually less performant - the cost of your efforts with precaching vs potential error prone runtime loading.

swift crag
naive wharf
#

that also

#

i used to do that

#

but now all my old games are broken

swift crag
#

If the goal is to just get every object of type X, doing it at runtime will be way more reliable.

#

If you have more specific needs, then the issue is murkier

naive wharf
ivory bobcat
swift crag
#

for example, if you care about the exact order of objects, and also need to exclude certain objects based on non-trivial criteria, you might just want to set it up in the inspector

swift crag
#

because you got all of them!

ivory bobcat
swift crag
#

it sounds like Pixel wants to get every instance of X.

junior parrot
rich adder
#

make editor script that mixes FindAll and Inpsector xD

swift crag
swift crag
novel shoal
swift crag
#

maybe

#

but it's a common term in mathematics

rich adder
swift crag
#

there you go, latin

swift sedge
ancient island
novel shoal
rich adder
junior parrot
novel shoal
ivory bobcat
swift crag
ancient island
#

try looking in the composite collider options, there should be an option to select whether you want it to be "outline" or "polygon". Make sure to choose polygon

swift crag
#

I am a fallible meatbag

rich adder
swift crag
#

for example, my game's settings menu is generated completely automatically

#

I hand the game a hierarchy of settings definitions and it spits out menus and sliders and buttons

#

When I add a new setting, it automatically appears in the settings menu

#

I can't forget

swift crag
#

and I can't accidentally modify one of the prefab instances so that it looks a little wrong

rich adder
swift crag
#

I automate anything that I can express through code.

novel shoal
#

i am taking latin in middle school too

rich adder
#

exactly xD

#

but yeah lets not go offtopic

novel shoal
#

i couldn’t do informatics since my parents wanted me to do latin bc “it makes you reason”

novel shoal
ancient island
# junior parrot Oh thanks, it worked!

nice! the issue was that te box collider was detecting the outline, so at the middle of the ladder you were inside the collider so the boxCast didn't catch it. When you set it to polygon, the collider is set also inside the outline

woven crater
#

do i want to use object pooling when spawning enemy.....?

rich adder
ivory bobcat
# swift crag I can't forget

When a setting is missing and you don't recall what you've done with it, how it's found or which script does the initialization.. it can be tedious if your system isn't well built.

rich adder
#

but anyway can you repost your issue @novel shoal

swift crag
#

they all live right here

#

I do have an editor script that makes sure every setting has valid localized strings and is included in the hierarchy

#

data validation, basically

#

a setting with no category makes no sense; there is nowhere to put it

#

It's all very uniform.

#

I guess it would be bad if my code was bad

#

but that's a tautology. everything is bad if it's bad.

ivory bobcat
#

For example, Play button is missing but it's obviously in the scene. You've set this up 3 years ago and do not recall which component script is managing this.

swift crag
#

if it's obviously in the scene already, then it's clearly not being created automatically

ivory bobcat
#

Or if whatever is expecting it to be there simply isn't able to properly acquire it etc

novel shoal
swift crag
#

you're describing a very vague category of problems

ivory bobcat
novel shoal
swift crag
#

There is only one play button, after all.

#

But if I had several levels, each of which had varying numbers and kinds of enemies, I'd be very unhappy if I had to make sure every single one was dragged into the EnemyManager's enemy list

ivory bobcat
swift crag
ivory bobcat
#

No user awareness is necessary if the code base is perfect

swift crag
#

this does not feel very productive

novel shoal
#

i could also use a coroutine

normal mango
#

thinking about a mechanic where the player can walk to each "door", and a snapping arrow appears that points to each other door, too which the player can teleport too. any suggestions on starting to make this?

novel shoal
rich adder
#

so speed can always be positive

novel shoal
swift crag
rich adder
#

whats the objective of that?

swift crag
#

If you want to draw an arrow between the two doors, you'll need a LineRenderer or something. You would give each door its own LineRenderer, and you'd set its points appropriately when the player runs into the trigger

novel shoal
rich adder
#

sure that can work

swift crag
#

It'd look a bit like this

#

you'd write similar code to hide the arrow

novel shoal
#

and so forth

rich adder
coarse compass
#

Hi, I want to Raycast to a navmesh. But navmeshes are not colliders. Is it ok to add a mesh collider to the navmesh surface or is this dumb af? What would be a better solution?

ivory bobcat
swift crag
#

this method checks if a ray crashes into a navmesh edge

coarse compass
#

Yeah I know I found that

#

Not what I want as you said 🙂

swift crag
#

Maybe you can just use SamplePosition?

#

Especially if you can raycast onto the colliders that are used to create the navmesh in the first place

#

raycast onto a floor collider -> SamplePosition to snap onto the mesh

rich adder
#

yeah def raycast on collider then use SamplePosition

swift crag
#

This won't work if you're using renderers, not physics colliders, to create the mesh

#

I don't like doing that, though :p

#

i always switch my surfaces to hierarchy only + physics colliders

coarse compass
#

I'm already using that but I specifically want to raycast downward from points high up above the navmesh. SamplePosition has a "spherical" range.

rich adder
#

same, that makes my "scenery" objects have navmesh

coarse compass
#

Ok so basically using the base geometry instead of the navmesh

#

got it

rich adder
novel shoal
#

anyways i can put the time of the coroutine in a variable and change it for every enemy depending on its position

ivory bobcat
visual hedge
#

Pokemon-ish type of game.
Each player / character has the list of the "pokemons" he owns. "Pokemons" are also upgradeable and so on.
Player is also upgradeable and so on.
Serialization: Do I serialize both player data and pokemon data as player data or do I separate the pokemon data from players data and serialize (I mean save the data into json or binary) them separately?
Together: CharName.dat
Separately: CharName.dat + CharNamePokemons.dat

coarse compass
#

I guess I could also use SamplePosition and then NavMesh.Raycast to see that point fall on the border, which means it wasn't above the navmesh but next to it 🤔

#

Not sure how NavMesh.Raycast behave with a source position that isn't on the NavMesh

rich adder
ivory bobcat
# novel shoal i can set time off?

You could be missing frames and potentially traversing farther or shorter than the wanted distance. But likely this will not happen. Just sort of reminds me of older Bethesda games running at frames > 60 or lag

rich adder
coarse compass
# rich adder curious, what is the usecase here?

I'm creating random points with Poisson Disc Sampling over a rectangular area, and then I want to project those points to the navmesh, discarding any that wouldn't hit the navmesh. Using SamplePosition with a small range does that but if there is lots of height variations on the navmesh then I need to increase the range and I'd get lots of points on the borders of the navmesh.

coarse compass
#

I'll generate the points really high up and raycast down to infinity

rich adder
twin bolt
#

Does anyone know how this code could bug out my pickup system, where gameobjects that the player is holding, moves freely around while the player is looking around? If the player is just moving and not looking around, the item stays in the right position. ```#Movement///
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");

        // Calculate the movement direction relative to the camera's rotation
        Vector3 forward = playerCamera.transform.forward;
        Vector3 right = playerCamera.transform.right;
        forward.y = 0f; // Ensure no vertical movement
        right.y = 0f;   // Ensure no vertical movement
        forward.Normalize();
        right.Normalize();

        Vector3 desiredMoveDirection = forward * verticalInput + right * horizontalInput;

        // Apply the movement to the rigidbody
        rb.velocity = desiredMoveDirection * playerSpeed;

///

#Camera Movment
///
yaw = playerCamera.transform.localEulerAngles.y + Input.GetAxis("Mouse X") * mouseSensitivity;

            if (!invertCamera)
            {
                pitch -= mouseSensitivity * Input.GetAxis("Mouse Y");
            }
            else
            {
                // Inverted Y
                pitch += mouseSensitivity * Input.GetAxis("Mouse Y");
            }

            // Clamp pitch between lookAngle
            pitch = Mathf.Clamp(pitch, -maxLookAngle, maxLookAngle);

            playerCamera.transform.localEulerAngles = new Vector3(pitch, yaw, 0);

///```

#

The item is a child of the playerCamera

short hazel
#

I'd advise against reading and writing to localEulerAngles directly.
Store the rotation in degrees in your script, as two variables, and modify those instead. Then assign to localRotation using Quaternion.Euler(x, y, z). This is because there can be multiple Euler angles that represent the same rotation, so on two consecutive frames you might be getting wildly different XYZ values

twin bolt
short hazel
#

Is the parent scaled other than (1, 1, 1)? That might be the cause of them warping

wintry quarry
#

warping is also a possibility

twin bolt
short hazel
#

Is the movement consistent or random?

twin bolt
short hazel
#

Show the Inspector of one of these pickups while they're a child of the player

short hazel
#

Screenshot, just to see what components are attached to it

short hazel
#

Does it need to have a rigidbody? What I usually do is have the base item as a prefab, and make a variant of it for the pickup

#

See if the problem goes away when removing the Rigidbody

twin bolt
short hazel
#

Yeah I have these separated. A prefab for holding, and a prefab (variant) for picking up

twin bolt
#

How is the rigidbody doing this?

short hazel
#

They run on the Physics system, which is updated at a different rate than the rest of the game (eg. Update vs. FixedUpdate)

twin bolt
short hazel
#

You can't

#

Make prefab variants. Updating the root prefab will also update its variant

spiral narwhal
#

How do I change the z-index of UI Images if I cannot change the hierarchy? (it is used for layout reasons)
In this example, if I hover over any card, it should be the topmost card

novel shoal
#

void FixedUpdate()
{
if (gM.isGameActive)
{
gameObject.SetActive(true);
}
rb.velocity = new Vector3(xSpeed,0,0);
StartCoroutine(MoveForSecond());
gameObject.transform.Rotate(0, 180, 0);
}
is this ok?

carmine elm
#

how can i acess an int variable from another script

novel shoal
swift crag
cosmic dagger
spiral narwhal
cosmic dagger
swift crag
#

the order is being used for layout already

rich adder
#

SetSibilingIndex

swift crag
#

I guess you could just run the layout once, then turn it off

carmine elm
boreal sundial
#

!code

eternal falconBOT
spiral narwhal
cosmic dagger
swift crag
#

then make the real cards follow the dummy ones as long as they're in your hand

short hazel
spiral narwhal
novel shoal
#

if the script you are trying to access to is the game manager, just declare a variable in your script: public GameManager gM;
and then access its component gM = gM.GetComponent<GameManager>();
and then you can access every value in that script by using something like gM.(insert variable name/method name)

#

@carmine elm

swift crag
#

The only problem is that you need to seamlessly get rid of it when you grab the card, and make sure it always overlaps properly

novel shoal
short hazel
#

"doesn't work" - what does this mean?

novel shoal
#

like, what the hell is a quaternion

short hazel
#

Yeah, you need to use Quaternion.Euler(vector)

#

It's how Unity represents rotations

novel shoal
#

what the hell is a quaternion

spiral narwhal
swift crag
#

yeah, that's just down to how UI rendering works

cosmic dagger
short hazel
swift crag
#

the specifics are irrelevant -- just like how you don't actually care how a Transform works

novel shoal
#

huh? dude you are scaring me

short hazel
#

You can search for it on Wikipedia but I'm not liable for the brain damage induced from reading the page

novel shoal
swift crag
#

It is a way to store a rotation. It works better than Euler angles

swift sedge
#

its a rotation matrix

swift crag
#

a 16-element matrix of floats

#

Quaternions are weird math, but you don't really care about the weird math

#

I kind of wish Unity just called it a Rotation

novel shoal
#

rb.rotation =Quaternion.Euler(0,180,0);

swift crag
#

Yeah, that's what you need to do.

#

Quaternion has lots of methods for creating and messing with rotations.

swift sedge
novel shoal
#

i'll (maybe) understand quaternions at university (not likely)

swift crag
#

you know how complex numbers work?

#

they're complex numbers 2

novel shoal
swift crag
#

real number: a
complex number: a + bi
quaternion: a + bi + cj + dk

novel shoal
swift crag
#

they're a bundle of joy

novel shoal
swift crag
#

but again: we do not care about how they work

#

I don't care how they work!

#

I've also forgotten how transformation matrices work. Been a hot minute since I did those in college.

#

I just let Unity deal with it

swift sedge
#

all you really need to use is Quaternion.Euler which has x, y, z

short hazel
#

God that method name is awful. FromEulerAngles() would be better

swift sedge
swift sedge
novel shoal
#

rb.rotation =Quaternion.Euler(0,180,0);
it doesn't flip the object

novel shoal
novel shoal
short hazel
#

Check other places where you could be overriding transform.rotation directly

novel shoal
short hazel
#

And yes constraints will prevent it from moving/rotating on the enabled axes

novel shoal
#

with transform.rotate instead of rb.rotation it used to work

short hazel
#

If you just need to flip a sprite, then use spriteRenderer.flipX instead of rotating the whole object

novel shoal
buoyant knot
#

does your gameobject have colliders

prime cobalt
#

Is there a command to get a component in a parent of a parent or do I have to make a self refrence loop?

buoyant knot
#

if you move transform.rotation, that does not update the colliders etc

novel shoal
summer stump
prime cobalt
#

Oh ok cool

naive wharf
#

I made a gravity simulation using rigidbodys and a script that adds a force to them but making a stable orbit is really hard because you have to restart the scene and slightly tweak the initial velocity until its stable. So I want to make a script that shows me where the object will go in the future but i have no idea how to do that. I've looked at other peoples code that did similair stuff but they dont apply to my case, how could I even approach this?

novel shoal
novel shoal
#

but with transform.rotate it used to rotate

buoyant knot
#

2D rigidbodies have rotation as a float, not a quaternion

short hazel
novel shoal
buoyant knot
#

and it has a rigidbody, not rigidbody2D?

novel shoal
buoyant knot
#

for that, I would try MoveRotation

#

.rotation tries to move it instantly

novel shoal
buoyant knot
#

like a teleport

novel shoal
split dragon
#

Hi. I have a problem that I need to select several array elements at the same time to change the volume of the sound on the slider at the same time. I tried to write comma separated (0, 1, 2, etc.) or from 0 to 10, but there can only be 1 value in the array (the console told me so). Is it possible to get around this somehow and call several array elements at once through 1 line? Of course, I know that you can create a new int, etc., but is there an easier way?

novel shoal
#

rb.MoveRotation(Quaternion.Euler(0, 180, 0)); @buoyant knot

summer stump
buoyant knot
buoyant knot
#

and automatically interpolate during non-fixed frames

small mantle
#

I just installed the Input System, but its not showing up in code?

buoyant knot
#

should be

swift crag
buoyant knot
#

but that is a really fast rotation

swift crag
#

and also restart your code editor

novel shoal
#

instead, it should be instant

buoyant knot
#

well, that rotation will take 1 fixed frame, potentially many normal frames. so 0.05 s by default

small mantle
buoyant knot
#

rb.rotation is instant, but does not respect colliders

swift crag
#

the thing you use to edit code files

robust condor
#

Can the tile system rule placement feature be used at runtime? When a player places a tile, I want it to change the terrain so that the edges get a cliff for example. So it knows if it will be a corner piece or not

novel shoal
buoyant knot
#

i would debug.Log to see the transform.rotation and rigidbody.rotation before and after. For rb.rotation, and transform.Rotate()

buoyant knot
#

because it’s possible something else is overwriting the change

novel shoal
novel shoal
#

now even transform.Rotate does not work

buoyant knot
#

sounds like it was never really working

#

that’s the problem with moving transforms. there are side effects

novel shoal
#

void FixedUpdate()
{
if (gM.isGameActive)
{
gameObject.SetActive(true);
}
rb.velocity = new Vector3(xSpeed,0,0);
StartCoroutine(MoveForSecond());
transform.Rotate(0, 180, 0);
}
what could overwrite it?

buoyant knot
#

just print with debug.log

#

Debug.Log(transform.rotation.ToString() + “ - “ + rb.rotation);

languid spire
short hazel
#

Do note that transform.Rotate() will not wait until the coroutine has finished running. It will be executed immediately.
Co-routine, runs "separately" / "concurrently"

tawny rain
#

!IDE

eternal falconBOT
buoyant knot
#

also, you are doing this in fixed update, every fixed frame rotating to 0,180,0. Meaning you move once and never again?

novel shoal
languid spire
serene barn
#

does anyone organize there code?

#

or do you just look at it and are like "good enough"

novel shoal
languid spire
#

that makes no sense

short hazel
#

If the game object is not active the method does not run at all

short hazel
#

So your if statement will technically never pass when this object is disabled

#

It's not needed to have it right now

novel shoal
#

i need to put it in the game manager?

short hazel
#

Anywhere else that is active, so the code to enable your object runs

hard cloak
#

Please can someone tell me the simplest way to make a gameobject active when a player hits a boxcollider2d trigger box?

slender nymph
#

do you know how to set a gameobject active?

hard cloak
#

SetActive(true) right?

slender nymph
#

yes. so do that in OnTriggerEnter2D

novel shoal
novel shoal
slender nymph
#

that wouldn't work with a trigger

slender nymph
novel shoal
slender nymph
#

why would it do that?

novel shoal
#

that’s what i thought

slender nymph
#

you thought wrong. there is nothing preventing you from starting multiple separate instances of the coroutine because you do nothing to check whether it is already running or not

novel shoal
slender nymph
#

that is one way, yes

novel shoal
slender nymph
#

what is xSpeed set to

novel shoal
#

one

slender nymph
#

okay and does anything else like friction or a drag affect its speed?

novel shoal
slender nymph
#

because it sounds like now your speed is too low to overcome those forces since you are no longer resetting the velocity every single fixed update

slender nymph
novel shoal
#

so i just need to make the speed higher?

slender nymph
#

maybe, you didn't bother answering the question i asked

novel shoal
#

i don’t know about that rn

#

i had to close my pc

slender nymph
#

then come back when you can troubleshoot your issue

#

what do you mean by "it just defaults to all of them"

#

also you should consider changing that to a for loop now so you don't have to come back later and fix the for loop whenever you've got it set up. also you do not need to access a gameobject's gameObject property to call SetActive on it. you're already access the gameobject

spiral narwhal
#
public void Rotate(float degrees)
        {
            var transformContainerRotation = _transformContainer.localRotation;

            _transformContainer.localRotation = new Quaternion
            (
                transformContainerRotation.x,
                transformContainerRotation.y,
                degrees,
                transformContainerRotation.w
            );
        }

When I pass Rotate(2f) for example, in the inspector the rotation turns out to be something ridicilous like 164f. No matter if it's rotation or localRotation. Does anyone know how to properly rotate the container?

slender nymph
#

well for one, quaternions are not in degrees

short hazel
#

Quaternion XYZW are not angles in degrees, do not modify them manually

spiral narwhal
slender nymph
#

and even if you were assigning using Quaternion.Euler rotations can be expressed in many different ways so what you see in the inspector may differ from what you set in code

spiral narwhal
#

Maybe my approach is overkill too. I want to change the rotation of hand cards based on their index in the hand. So for example card 1 and 10 have a rotation of -5 and 5, cards 2 and 9 have a rotation of -4 and 4, and so on and so forth.

#
private void RecalculateTransforms()
        {
            var hasMiddle = _handCardViews.Count % 2 is 1;

            if (hasMiddle)
            {
                for (var i = 0; i < _handCardViews.Count / 2; i++) _handCardViews[i].Rotate(2 * i);

                for (var i = _handCardViews.Count / 2 + 1; i < _handCardViews.Count; i++)
                    _handCardViews[i].Rotate(-(2 * i));
            }
            else
            {
                for (var i = 0; i < _handCardViews.Count / 2; i++)
                    _handCardViews[i].Rotate(2 * i);

                for (var i = _handCardViews.Count / 2; i < _handCardViews.Count; i++)
                    _handCardViews[i].Rotate(-(2 * i));
            }
        }

Never mind the unneccessary split between conditions, it's just easier to test right now

slender nymph
#

also if you just want to rotate by a specific number of degrees, you can just use transform.Rotate

#
for(var i = 0; i < weapons.Count; i++)
  weapons[i].SetActive(i == selectedWeapon);
spiral narwhal
slender nymph
#

i would personally not even have those other checks and just parent your weapons to the weapon slots or whatever. then have the weapon slots determine whether anything is equipped there

slender nymph
#

yeah so use Quaternion.Euler like i suggested before

spiral narwhal
#

Ok, thanks

delicate pewter
#

Uhm, why am I getting the error "Type or namespace "FreeTickets" cannot be found..." when im doing super basic stuff...

public FreeTickets fc;

In a different script

#

Not even sure what to show here..

slender nymph
#

do you have a type called FreeTickets

delicate pewter
slender nymph
#

is it in a namespace?

delicate pewter
#

Yes

#

But so is everything else and it works

#

same namespace

slender nymph
#

have you imported that namespace into the other file?

delicate pewter
#

Oh...

#

Ty lol

slender nymph
#

make sure your !IDE is configured so that you can easily fix these issues using the quick actions and so that you can also automatically add using directives

eternal falconBOT
quick edge
#

Yo! Quick question, is it better to use Cinemachine or do my own camera system ? I want to do a simple camera capable of colliding with wall, follow and rotate around the player.

slender nymph
#

cinemachine

serene barn
#

so I have this bullet and it spawns with the key press but unity is saying there's no rigidbody attached to the bullet clone

slender nymph
#

is there a rigidbody attached to the bullet clone?

serene barn
#

it's a clone from a prefab

slender nymph
#

and is there a rigidbody attached to the bullet clone?

quick edge
slender nymph
quick edge
#

Ok perfect

#

Thanks!

ancient island
slender nymph
quick edge
serene barn
slender nymph
serene barn
#
//from bullet
public class Projectile : MonoBehaviour
{
    // start of void (ridigbody)#1
    Rigidbody projectilRidigBobody;
    void Awake()
    {
        projectilRidigBobody = GetComponent<Rigidbody>();
    }
    //end of start

// ----------------------

    //start of Launch
    public void Launch(Vector2 direction, float force)
    {
        projectilRidigBobody.AddForce(direction * force);
    }
    //end of Launch

// ----------------------

    //start of Collision

    void OnCollisionEnter2D(Collision2D other)
    {
        Debug.Log("projectil has touched" + other.gameObject);
        Destroy(gameObject);
    }

    //End of Collision

// ----------------------
}
//from character
  public GameObject projectilePrefab;
   void Launch()
   {
       GameObject projectileObject = Instantiate(projectilePrefab, rigidbody2d.position + Vector2.up * 0.5f, Quaternion.identity);
       Projectile projectile = projectileObject.GetComponent<Projectile>();
       projectile.Launch(LookDirection, 300);

       animator2.SetTrigger("Launch");
   }
   //End of Launch
slender nymph
#

well that error is correct. there is no Rigidbody attached to that object at all

#

there is a Rigidbody2D though which is a completely unrelated component

serene barn
#

because it's a clone

slender nymph
#

no becaues it doesn't have a Rigidbody component

serene barn
#

AHHH

#

ITS BEEN A LONG DAY

swift sedge
#

"RidigBobody" ?

serene barn
#

oh now i cant someone at all until it hits something

serene barn
#

just go with it

#

and it's not colliding with anything

slender nymph
#

does it have a collider

hidden sleet
#

Trying to resolve item saving and loading, but I'm having issues. I've got an item database that contains items with IDs and Ids with items as two separate dictionaries. The player script will call load inventory when spawned which will simply read the file corresponding to the input string, then the database should assign the items and ids. I can see that the inventory is correctly filled with the item, but then in my inventory this line here breaks because the database is null. The database is assigned in the scriptable object for the inventory, but as soon as I run it, it just dissapears and I've got no clue why

serene barn
#

alright its all fixed thanks a lot

slender nymph
eternal falconBOT
hidden sleet
#

not used it before

#

seems like it's all there

slender nymph
#

you're overwriting the entire class inside of LoadInventory with whatever you have serialized. this includes those references to the other objects which you cannot just write to disk like that
https://docs.unity3d.com/ScriptReference/JsonUtility.ToJson.html

If the object contains fields with references to other Unity objects, those references are serialized by recording the InstanceID for each referenced object. Because the Instance ID acts like a handle to the in-memory object instance, the JSON string can only be deserialized back during the same session of the Unity engine.

hidden sleet
#

oh I see, cause of the this it's saving the entire class which loses the reference

queen adder
#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class doortry : MonoBehaviour
{
    public GameObject character;
    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            Debug.Log("collide");
            character.transform.position = new Vector3(25f, 25f, 25f);
        }
    }    
}
#

i get collide msg on log but it doesn't teleport my character

slender nymph
#

are you using a CharacterController

queen adder
slender nymph
tribal minnow
#

hey guys, i need help with the unity starter assets third person controller. the mouse speed goes sooo fast when the fps drops .
how do i fix that ?

short hazel
#

Lower FPS => greater deltatime => increased sensitivity

tribal minnow
tribal minnow
#

ok i will try that

#

thanks

short hazel
#

Seems like the condition above fails

#

It's not detecting your input as a mouse, if it was the multiplier would be 1 as per the ternary expression

hidden sleet
slender nymph
#

well the issue was more so where you load the save and overwrite the assignments that were serialized in the inspector

#

i only linked the ToJson doc so you would understand why that was happening

hidden sleet
#

yeah it seems like the database is sticking there which is nice

#

not sure why this is suddenly happening though

tribal minnow
sacred orbit
#

is it possible to set the value of a public gameobject variable to null through script?

#

cause gameObject = null; doesn't work :/

languid spire
#

gameObject is a property of the script, you cannot set that to null but you can set other GO variables to null

short hazel
# tribal minnow it worked thank you bro

See my next messages because there's an issue with the code (the asset's code?). It was multiplying by deltatime because it did not recognize your input device as a mouse.

float deltaTimeMultiplier = IsCurrentDeviceMouse ? 1.0f : Time.deltaTime;

Do you have a controller plugged in that could affect the value of IsCurrentDeviceMouse? Try to look where that variable is set for more clues

tribal minnow
short hazel
#

(Steering wheels / HOTAS included in the "controllers" devices)

tribal minnow
swift crag
tribal minnow
#

and it does say its a keyboard and mouse

short hazel
#

Hands On Thruster And Stick

#

Aviation thing

swift crag
#

if that's not what you're doing, show your code

sacred orbit
# swift crag what are you trying to accomplish here?

whenever I switch to a different item it changes gameObject variable "heldItem" to the gameobject that you switch to (all this works well and is simplified here so I don't have to explain it) problem is, when you drop an item the heldItem variable doesn't change and can cause some wacky issues, so I want to make that heldItem variable be nothing

swift crag
#

okay, so set it to null

#

what's the problem?

sacred orbit
#

gameObject = null;
doesn't work :/

robust condor
#

Set the variable to null

sacred orbit
#

thats

hidden sleet
#

would this need to have some serialisable tag on it for it to properly serialise into json?

sacred orbit
#

what I am doing

robust condor
#

No

hidden sleet
#

or just the type in the list

robust condor
#

heldItem = null

swift crag