#💻┃code-beginner

1 messages · Page 737 of 1

midnight plover
#

You want to enable the scroll wheel to control your cameras forward Position to Zoom? Could it be rephrased to this?

hardy wing
midnight plover
hardy wing
#

Ya

midnight plover
#

What did you try so far?

shell sorrel
#

can get the scroll delta add it to the camera position

#

if its not smooth enough can do a vector3.smoothdamp

hardy wing
slender vapor
#

anyone know why this keep appearing when i try to install the unity editor?

hardy wing
#

And calcing target position by number of scrolls and lerping to that was my approach

#

Since I didnt try it out as I'm not in the engine rn I just wanted to get feedback if there are better ways in terms of feel.

edgy sinew
rugged beacon
#

i have a Locale locale and locale.code or .locale came up nothing ?

naive pawn
rugged beacon
#

asigned? drag drop?

#

its a class property i dont see how it would change but im reference one rn

naive pawn
#

make sure you assigned the locale itself

edgy sinew
#

Hello guys, can you help me clarify the different routes to have shared Events? I'll start below and please help me fill out the list / correct where I'm wrong. Or suggest something better if it's not on here, please blushie

  1. Event on MonoBehaviour (to share elsewhere, you would need a direct ref to the MB.)
  2. Static Event, static class (this... Always exists? Between scenes, it retains, I think.)
  3. Event on a Singleton (kinda same as above but requires instantiation for example a "Singletons" GameObject in the Scene that holds all the Singleton scripts)
  4. Scriptable Object Events (just need ref to the SO itself, pretty simple drag & drop)
naive pawn
#

what do you mean by "shared" exactly? shared listeners/shared event for the type?

edgy sinew
#

Well, ease of access, subscription, to some Event. For example so multiple GameObjects in the scene can react, or the UI, etc.

#

I'm tempted to just do Static Class & Static Events, but I'm aware that Scriptable Object Events have some advantages over that. But, I don't really know what they are! 🤷‍♂️

shell sorrel
#

i tend to just lean on static events, though no need to also make a static class for it

edgy sinew
shell sorrel
#

well i define the events on the things that would invoke the event

#

if things care about exactly which instance did so, i will just pass that as the first arg on the event

edgy sinew
#

So... It's basically the MonoBehaviour method I described above

grand snow
edgy sinew
#

You need a reference to that specific MonoBehaviour, to work with the Event

edgy sinew
#

Oh because the Event is static?

shell sorrel
#

only need the type to access a static event

edgy sinew
#

So you would do ClassName.MyStaticEvent

#

Because no instance of the class is required, for the static things to exist

#

Ahh okay pretty cool. That's not so bad

grand snow
#
public class Item : MonoBehaviour
{
    public static event Action<Item> OnItemCollected;

    public event Action OnCollect; //per instance
edgy sinew
#

What do we gain going the Scriptable Object route?

#

As I understand, unless we were to do a lookup on Awake by like uhh searching Resources folder or whatever, basically we need [SerializeField] myEventSO anywhere we want to react to the Event

#

And we drag & drop the SO itself before runtime

grand snow
#

the scriptable object way is worse as unity may make a new instance and really confuse things

edgy sinew
#

Wdym by make a new instance? Wouldn't that only happen with ScriptableObject.CreateInstance<MyScriptableObject>();

shell sorrel
#

Static keep it simple, no worries about timing or finding the instance on sub

#

Easy to invoke

grand snow
#

no if the asset is loaded there is not guarantee its the same instance if the asset was "unloaded"

edgy sinew
#

I've never seen an SO duplicate itself. Not sure what loaded / unloaded means but, I'll keep an eye out

#

I'll research more about the benefits of SO Events and report back

brave compass
#

Unity can unload and reload scriptable objects between scene loads if nothing is referencing them, so the non-serialized fields in it, like events, can get cleared.
But I'm pretty sure if you have a subscription you haven't removed, that will count as a reference and it will keep the same instance.

grand snow
#

I dont know if an event on the scriptable object not being null is something that is checked

#

Its handled like an asset after all

edgy sinew
#

Oh, gosh. Well I dont need my scriptable objects re loaded, darn!

#

Wait so… if I have a GameObject with a MonoBehaviour, in 2 different scenes, with same SOs plugged in

#

Then it won’t be reloaded right because there’s always a reference

brave compass
edgy sinew
echo ruin
brave compass
#

I don't see a p oblem

shell sorrel
#

strange, can not repro that

#

custom editor stuff going on around it?

echo ruin
#

No clue. Maybe it will correct itself on reset. I just found it odd

brave compass
#

Is it the v character? What if you try adding another one in the name, overlayOverlayTiles?

echo ruin
#

Seems like it just doesn't like that 'v'

brave compass
#

I feel like I've seen strange issues like this come from misbehaving custom editor stuff. Some editors modify the built-in GUIStyles without reverting.

#

If Unity restart fixes it, it might just be that.

naive pawn
#

so like, it wouldn't show v at all, not just that position

shell sorrel
#

what version?

echo ruin
#

I just changed it back to overlayTiles and now it seems to work fine.
Strange..

naive pawn
#

schrodinger's issue

edgy sinew
#

Hi guys, is this problematic to create a new instance of an InputActions in Awake? Like when it comes to, scene reloads specifically I guess.

        QualitySettings.vSyncCount = 1;
        // Application.targetFrameRate = -1;
        playerInput = new PlayerInput();
    }```
#

I suppose, since the player's input will be relevant the entire game, maybe it should be Static? Perhaps even a Static class not just the member variable.

shell sorrel
#

its fine doing it in awake

naive pawn
#

PlayerInput the component? 🤨

#

is it just a generated class named that

edgy sinew
#

No that's the name generate class yes

naive pawn
#

ah lmao

edgy sinew
#

I keep doing that oops

shell sorrel
naive pawn
#

i'm aware

shell sorrel
#

you can access them either by refs or via this type it creates

edgy sinew
naive pawn
edgy sinew
#

Seems a little weird. Shouldn't I prefer Static in this case?

shell sorrel
edgy sinew
#

Ohh yeah like to support split screen Co-op right?

shell sorrel
#

other reasons too, depending on how controls are setup for different parts of a game

edgy sinew
shell sorrel
#

so if you want to handle thigns that way i would just make InputReader DontDestroyOnLoad

edgy sinew
#

Sorry, can you clarify what exactly happens on scene reload with the Awake() instantiation?

shell sorrel
#

so it survives scene reloads

edgy sinew
#

Oh okay. So that prevents Awake() from like, duplicating the PlayerInput instance? When a new scene opens

#

(Sorry I'm really clueless on this topic)

shell sorrel
#

yes, since calling DontDestroyOnLoad would put it in its own scene that never unloads or gets loaded again

edgy sinew
#

But without DontDestroyOnLoad,

#

does Unity auto destroy the previous scene's PlayerInput instance?

shell sorrel
#

it would be tied to the lifetime events of the scene its in

#

since if the scene onloading the objects you create it in wouldbe gone so it would be gone

edgy sinew
#

Okay so. Unity would be deleting the previous scene's instance and then creating a new one in Awake() of the new scene

#

got it! Thank you uwu

limpid cloak
#

is it possible or adviseable to use both rigidbody and charactercontroller? i want a controllable gameobject to be more responsive than rb addforce would provide, but i would like to make events where the object is subjected to physics

naive pawn
#

no and no

#

they will fight for control over the transform

#

you could have both at separate times if you have specific cutscenes with physics in mind i guess? but you can't use them at the same time, no

shell sorrel
#

character controller is kinda rubbish anyways i would use something like KCC then in your logic for it define how to react to your physics events

naive pawn
#

more responsive than rb addforce
you can also control the velocity yourself, btw.

limpid cloak
limpid cloak
edgy sinew
# limpid cloak definitely true, i just saw that charactercontroller is just less bothersome. i'...

here's my findings bro

  1. Rigidbody non-Kinematic
    Have to use AddForce and AddTorque to maintain Interpolation (welcome PID controllers unless you want slippery movement & overshoot)
    Fully in the Physics system, applying and receiving forces
  2. Rigidbody Kinematic
    Have to use MovePosition and MoveRotation to maintain interpolation
    Only applies forces to Physics objects, does not receive
  3. Character Controller
    Easiest to use, for natural Physics interactions you can add a bit of code, but it's tricky because you have to determine where to inflict or receive force.
#
[Range(0.0f, 800.0f)]
    public float rbCollisionPush = 4.0f;
    void OnControllerColliderHit(ControllerColliderHit collision) {
        if (collision.rigidbody == null) return;
        Debug.Log("Collided with rigid body");
        // TODO look at Collision Normals to determine which direction to push object instead of just using characterVelocity
        // Or use CharacterController collision flags to determine if top, middle, or bottom of the capsule was hit - might yield more basic results
        collision.rigidbody.AddForce(characterTotalVelocityVec3 * rbCollisionPush, ForceMode.Impulse);
    }
#

Here's some basic code that applies a force, from the CC, to a Rigidbody when it's hit.

#

There's way more to do here, like perhaps take into consideration the Normal of the collision that happened, or less complex "which part of the Character Controller" was hit. See image below

eternal needle
limpid cloak
#

i'll try both with rbs and not since frankly i'm mostly exploring what CAN be done. what i do know is that 3d math is terrifying

eternal needle
eternal needle
naive pawn
edgy sinew
naive pawn
#

also, dynamic rbs can use velocity, not just forces

edgy sinew
edgy sinew
#

I said there's more to do, like check the collisionFlags or collision Normal. Etc

naive pawn
limpid cloak
#

first of all i'm going to at least sketch out the action i want, and i'll try to make it happen with either impulse force or with kinematics. thank you all for the advice

edgy sinew
#

I've read that directly modifying .linearVelocity is funky. But some controllers out there, that work great, even switch between Kinematic and non-Kinematic modes.

naive pawn
naive pawn
edgy sinew
naive pawn
#

probably Impulse if you want to have the effect of pushing

polar acorn
#

It's funky as in it won't be realistic, because things in real life don't just become moving all in one go

#

But setting velocity on a rigidbody does exactly what you expect it does. You're just most likely not expecting realism if you're doing it

naive pawn
#

it could be realistic if you have that in mind

edgy sinew
#

In most cases you should not modify the velocity directly, as this can result in unrealistic behaviour - use AddForce instead Do not set the linear velocity of an object every physics step, this will lead to unrealistic physics simulation. A typical usage is where you would change the velocity is when jumping in a first person shooter, because you want an immediate change in velocity.

naive pawn
naive pawn
polar acorn
naive pawn
#

hell, you could have a moving platform that you want at a set velocity

#

you would be setting the velocity then, easiest option

#

it wouldn't be realistic

#

but that's just not an issue

rich adder
eternal needle
# edgy sinew What's so bad about it? It applies a force to a Rigidbody when collided, based o...

you have a magic number 500.0f, then Time.deltaTime used to counteract the magic number which is equally wrong and both can be excluded. and yea as Chris said, this wouldn't be a Force, more likely an Impulse.
it doesnt matter if you say theres more to do, i was always referring to this specific example being bad. It's really just a bad idea to randomly spoonfeed walls of text that no one asked for. it's especially worse when its not correct which is often the case when beginners try to spoonfeed each other with what they've learned in their limited time

#

theres nothing wrong with directly setting the linear velocity, you can achieve the same result as AddForce

naive pawn
#

yeah imma be honest/blunt here.. i get that you're trying to help, but when you are also a beginner, sometimes that just harms instead

fair kettle
#

I just opened a fresh project that was given to me by my professor and it is showing these errors without having done anything. Any clues?

polar acorn
#

Seems like your URP installation is either out of date, corrupted, or missing. Go into the package manager and re download it

naive pawn
#

i'd guess a library reset could be in order as well

edgy sinew
#

I'll go ahead and clean up that code block a bit. Sorry, I'll be more careful

#

Okay I fixed all the things. no magic number, no Forcemode.Force, no Time.deltaTime

eternal needle
naive pawn
eternal needle
#

the default forcemode is Force, you would want to specify Impulse directly

edgy sinew
#

Or do you do your own interpolation.

naive pawn
#

that's the point of the interpolation setting

edgy sinew
naive pawn
#

AddForce just changes the velocity

edgy sinew
#

... 🥺

#

I can't even find anything online on that specifically. Really, setting .linearVelocity directly maintains interpolation of a dynamic RB? notlikethis

#

I'm gonna try it out, hope you're not pranking me stonks

limpid cloak
edgy sinew
#

Right?

naive pawn
#

it does the same thing

naive pawn
#

that's how AddTorque works under the hood

naive pawn
eternal needle
#

if you arent aiming for physics interaction as a result of the player rb turning, you dont need torque or angular velocity at all either. Could just directly set the rotation on the rigidbody

umbral hound
#

can someone help me?

using System;
using System.Collections.Generic;
using DG.Tweening;
using Sirenix.OdinInspector;
using UnityEngine;

public class PlayerDeathManager : MonoBehaviour
{
    [TitleGroup("<< Fade In >>")]
    [PropertyTooltip("The duration in seconds for the screen to fade in")]
    public float m_FadeInDuration = 2f;
    
    [TitleGroup("<< Fade In >>")]
    [PropertyTooltip("The ease setting for the fade in tween")]
    public Ease m_FadeInEase;
    
    [TitleGroup("<< Fade Out >>")]
    [PropertyTooltip("The duration in seconds for the screen to fade out")]
    public float m_FadeOutDuration;
    
    [TitleGroup("<< Fade Out >>")]
    [PropertyTooltip("The duration in seconds for the fade out tween")]
    public Ease m_FadeOutTween;
    
    public List<KillZone> m_KillZones = new List<KillZone>();

    private void Awake()
    {
        AddListeners();
    }

    private void AddListeners()
    {
        for (int i = 0; i < m_KillZones.Count; i++)
        {
            m_KillZones[i].OnEnter += HandleKillZoneOnEnter;
        }
    }

    private void RemoveListeners()
    {
        for (int i = 0; i < m_KillZones.Count; i++)
        {
            m_KillZones[i].OnEnter -= HandleKillZoneOnEnter;
        }
    }

    private void HandleKillZoneOnEnter(object sender, EventArgs e)
    {
        (sender as KillZone).OnEnter -= HandleKillZoneOnEnter;
        Debug.Log("Kill Zone :: Player died");
        ASingleton<ScreenBlockerController>.Instance.ShowScreenBlocker(m_FadeInDuration, m_FadeInEase, () =>
        {
            ASingleton<PlayerController>.Instance.transform.position = ASingleton<GameManager>.Instance.m_RespawnPoint.position;
            ASingleton<ScreenBlockerController>.Instance.HideScreenBlocker(m_FadeOutDuration, m_FadeOutTween);
        });
        (sender as KillZone).OnEnter += HandleKillZoneOnEnter;
    }
}
naive pawn
#

what do you need help with

umbral hound
#

Now, my player does SOMETIMES respawn at the respawn point but not always

#

and I know my logic is triggering because the screen blocker still shows and hides

wintry quarry
umbral hound
#

I am

naive pawn
#

what's with the desubscription and immediate resubscription

umbral hound
#

Like I said, I KNOW the logic triggers

#

it just doesn't set the player position always

umbral hound
wintry quarry
naive pawn
wintry quarry
naive pawn
#

don't desubscribe and then don't resubscribe

umbral hound
#

Oh I saw people doing that in other games. By not doing that, wouldn't that be a violation of some code practice?

naive pawn
#

what would it be violating

#

-# tip: don't blindly follow, dip deeper to find out why

umbral hound
#

Idk what I'm talking about

naive pawn
#

i would guess that maybe it was in a coroutine or similar, and the resubscription was only done after the respawn sequence

slender nymph
#

the only reason you should unsub immediately before subbing is if your code may have already subscribed somehow but you are unsure and you also want it to only be subscribed once

#

in this case it seems pointless as you can just leave it subscribed

umbral hound
#

Okay so I have taken out the resubscription and unsubscribe, and I put a log above the position reset, that DOES log but it doesn't reset

naive pawn
#

have you tried logging where it's trying to respawn the player?

#

the name of the respawn point for example

umbral hound
#

I'll try this

slender nymph
#

that action you pass to the ShowScreenBlocker method isn't perhaps being invoked on another thread, right?

umbral hound
#
using System;
using DG.Tweening;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.UI;

public class ScreenBlockerController : MonoBehaviour
{
    [TitleGroup("<< Screen Blocker Options >>")]
    [SerializeField]
    private CanvasGroup m_CanvasGroup;

    private void Awake()
    {
        m_CanvasGroup.alpha = 0f;
    }

    public void ShowScreenBlocker(float duration, Ease ease, TweenCallback onComplete = null)
    {
        m_CanvasGroup.DOFade(1f, duration).SetEase(ease).onComplete += onComplete;
    }

    public void HideScreenBlocker(float duration, Ease ease, TweenCallback onComplete = null)
    {
        m_CanvasGroup.DOFade(0f, duration).SetEase(ease).onComplete += onComplete;
    }
}
wintry quarry
umbral hound
#

Okay so I DID log the respawn position, even when it doesn't reset the player's position there, it DOES log it as a vector3

slender nymph
#

if it has a CharacterController you need to be sure to disable that when you teleport it

umbral hound
#

OH

#

Okay

#

That might be in

#

it

rich adder
umbral hound
#

I know, didn't think to

naive pawn
#

you can press up (arrow keys) to quickedit the last message

#

or use sed if you're into that

rich adder
#

what is "sed" ?

naive pawn
#

it's a command line tool short for __s__tream __ed__itor, there's one commonly known expression usually in the form s/a/b/ where a is replaced by b in the input text
you can use a basic version of that form in discord (the real one uses regex, i believe discord just does text replacement? haven't tested)
https://www.gnu.org/software/sed/manual/sed.html

rich adder
#

ohh nicee. TIL

thorn kiln
#

So, I'm having a bit of an issue. When my character jumps on a crate, it's supposed to instantiate a bone powerup in it's space and then destroy the crate, but it's only doing it sometimes, most of the time it just doesn't make instantiate the bone. This is the code I'm using.

        if (other.TryGetComponent(out CrateWeakPoint crateTrigger))
        {
            Instantiate(powerupPrefab, crateTrigger.transform.position, crateTrigger.transform.rotation);
            Destroy(crateTrigger.crate.gameObject);
            var velocity = playerRb.linearVelocity;
            velocity.y = 0;
            playerRb.linearVelocity = velocity;
            playerRb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
        }```
#

If it never did it, I'd say the code is totally broken, but the fact it does it sometimes is... weird

wintry quarry
rich adder
#

how are you doing detections?

thorn kiln
#

OnTriggerEnter(Collider other)

wintry quarry
#

add Debug.Log to the code for the bone pickup and the crate collision

thorn kiln
#

Hmm, hadn't considered that

wintry quarry
#

i bet they're both running

wintry quarry
#

you can see the bone is there for one frame

#

(at 9 seconds in the video)

thorn kiln
#

Yeah, I just tried running into a enemy right after jumping on an "empty" crate and it destroyed them, so I'm picking up the bone

#

Frustrating

#

That needs to not happen

wintry quarry
#

one approach would be to basically enable the bone's collider only after a certain amount of time has passed

thorn kiln
#

Nghhhh, that's a bit much for my skill level

#

I could probably do it, but it'd be messy

wintry quarry
#

you can use DOTween for it

thorn kiln
#

See, I don't even know what that is

wintry quarry
#

or just a coroutine

wintry quarry
thorn kiln
#

Yeah, I know about coroutines and timers, a little. It's how I'm doing the powerup.

rich adder
#

ohh thats good 🙂

thorn kiln
#

Thye're a little messy. I still need to sort out my powerups code so that picking up a new powerup resets the timer.

rich adder
#

wdym? messy in what way?

thorn kiln
#

Spread out around the script

rich adder
#

I mean you don't need to all cram it in the same script lol make a component just dedicated to enabling the collider

thorn kiln
#

Makes it difficult for me to keep track in my head what's going on and where

rich adder
#

A Component per feature/responsibility usually keeps things nice and neat

#

so like you can make it modular where this component just runs the timer and does something after, you can plug a UnityEvent or something so it can be used for other things to run on timer ends

#
public UnityEvent OnTimerEnd;
IEnumerator MyTimedAction(){
        yield return new WaitForSeconds(timer); //changed in inspector
        OnTimerEnd.Invoke();// run something after its done -- assigned in inspector
    }```
#

overkill but can be used for timers so you dont have to create it in a bunch of scripts

slender nymph
rich adder
#

yeah tbh I prefer through code this way ^^

#

but if you want UnityEvent can be easy so you dont want to deal with Sub and Unsub yourself
things like .enabled can be toggled through inspector / unity event

thorn kiln
#

Just trying to figure out where I should put everything. Things need to be in the scene to do stuff, and currently the code to generate the powerup is on my playercontroller, just because all the stuff that happens when I collide with things has been easier to organize from there.

slender nymph
#

generating powerups shouldn't be the responsibility of the PlayerController. you need to try and separate things out into different objects/components otherwise debugging is going to end up being an absolute nightmare

rich adder
#

scanning a file that has 500 lines that do different things aint fun...been there..done that...fuck all that..

thorn kiln
#

I know, I started making this prototype a while ago though and copying things from the pathway, which seems to be sub-optimal but functional in pretty much everything it teaches you

rich adder
#

yeah they're meant more to get the concepts down

#

clean code comes later on usually , but its good to start early so later on you dont tell yourself "I shouldve done this other way cause now this is a mess to debug"

thorn kiln
#

So I should just make the box collider off by default and then use a coroutine to turn it on after like, 1 second

rich adder
#

simplest way yea

#

cute quote in that pdf

CODE IS LIKE HUMOR . IF YOU
HAVE TO EXPLAIN IT, IT ’S BAD
– Cory House, software architect and author

earnest wind
#

hey guys, is there any way to tell if someone is focused on a slider in ui?

#

i know the way to do it for input field on tmp but slider doesnt have a .isFocused property

rich adder
earnest wind
#

couldnt find anything on internet

rich adder
#

wouldve been too hard to just give us OnFocus and OnLoseFocus events ffs.

earnest wind
thorn kiln
slender nymph
rich adder
thorn kiln
#

Eh, true. I was thinking I don't have any scripts on my powerup, but looks like I do

rich adder
thorn kiln
#

I'm just averse to having so many scripts, because I know I'm gonna forget where everything is. Also, if I start referencing stuff in a bunch of them I'm gonna end up creating a lot of interdependency and stuffs more liable to break.

#

Already feels like I have too many

rich adder
#

you should not be worrying about the quanitity , because again.. you dont want monoliths

#

monoliths dont scale well in the long run

wintry quarry
thorn kiln
#

It's not a big enough project that I need to worry about that

wintry quarry
#

Well I mean if you end up with a lot of scripts, which you seemed worried about

thorn kiln
#

Im literally just finishing off the "personal project" the programmer pathway has you start then never finish

rich adder
slender nymph
polar acorn
rich adder
#

ya fr

thorn kiln
#

Eugh, collider enabler works, now I'm realizing the powerup spawns too high

#

That's a pain to fix

slender nymph
#

damn am i a psychic

thorn kiln
#

That's not an issue with where I'm arranging my code, just where I'm telling it to spawn

#

Which is at the crates position

slender nymph
#

yes, but that was the hypothetical example i used

thorn kiln
#

Well you saw a video of my game and the code I was using, so it's not exactly the prophetic

slender nymph
#

you're taking a joke way too seriously

earnest wind
#

how i manage them

#

is just make a folder for scripts in every scene folder

#

and then u have the general one which is scripts that can be seen in more than 1 scene and so on

#

once scene has so many scripts that i had to make categories inside based on what they are used in

#

but yeah, right now it wont be a proble

thorn kiln
#

Yeah, with a one scene game, not a big issue

earnest wind
#

and even if it becomes, its not hard to get rid of it

earnest wind
thorn kiln
#

No, I just said the opposite?

grand snow
#

I just use logical folder names and asm defs

#

If on a team then ideally things are organised in a way that suits the project so people can locate things easily

spiral oracle
#

god tier programming

rich adder
spiral oracle
#

I couldn't make Square a monobehavior class

#

so I had to make a separate one for what I wanted to do

#

and I just named it that because the square's name is data technically

rich adder
#

gotcha.. I usually use MB when I need components but for data itself usually its a SO or Struct / Poco

spiral oracle
#

like in the Square script I'm writing to the variable squareName in an instance of the SquareData class and then another script reads from it

plush bronze
#

Hi! I just joined Unity for the first time and wanted to see if making games is actually fun and it is! I made this with just google (no AI) and with some skills I had, does anyone want to tell me tips n tricks for starting?

thorn kiln
#

Is there a way to destroy a particle effect after it's finished playing? I can't just instantiate and destroy on the next line cause it'll never finish playing

rich adder
thorn kiln
#

Oh, that's... immensely easier than what I was thinking

rich adder
thorn kiln
#

I guess it makes sense it would be made easy in the game engine

rich adder
#

mhm. callback one is also very usful to run additional logic with it

thorn kiln
#

What does callback do?

grand snow
#

Too bad its a message and not an event

rich adder
#

true its a weird workflow but its best we got :\

grand snow
#

thankfully newer stuff uses events like it should have from day 1

grand snow
#

i just mean unity features in general

rich adder
#

ohhh true

grand snow
#

I guess it was done this way to work in js + boo too
but since those were ditched things can be designed for c# properly

dense goblet
#

just need quick help, Im trying to make a if statement that looks for the first value in a list, Im assuming its something like "Listname[1]" or something?

shell sorrel
#

define looks for

#

also first is index 0

dense goblet
#

the if statement would search for the value of (for example) the first listed item

shell sorrel
#

ok but are you looking to see if it has a first element or looking to see if that value is a certain value?

#

like something like if (list[0] == "MyString") {

dense goblet
#
Parameter name: index
System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <59bd7c40c082431db25e1e728ab62789>:0)
GameManager.Update () (at Assets/Scripts/GameManager.cs:25)

#

heres my script here ```using System.Collections.Generic;
using System.Linq;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
using static UnityEditor.Progress;

public class GameManager : MonoBehaviour
{
public GameObject Enemy;
public GameObject GameManagerObject;
public List<int> randomRoomOrder;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
List<int> randomRoomOrder = new List<int> { 1, 2, 3, 4};
randomRoomOrder = randomRoomOrder.OrderBy(i => Random.value).ToList();
Debug.Log("randomRoomOrder: " + string.Join(", ", randomRoomOrder));
}

// Update is called once per frame
void Update()
{
    //randomNumber = Random.Range(0, 4);
    Debug.Log(randomRoomOrder[0]);






    if (Input.GetKeyDown(KeyCode.O))
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }
}

}```

#

am I not making the list properly?

shell sorrel
dense goblet
shell sorrel
#

in start you have a type name infront of it, which is creating a new randomRoomOrder just in your start method

#

instead of using the field randomRoomOrder

#

so the one you are accessing in Update is not the same one, and its never been initialized

dense goblet
#

I understand

ivory bobcat
#

You've created a new randomRoomOrder

List<int> randomRoomOrder = new List<int> { 1, 2, 3, 4};

dense goblet
#

so I should be able to refrence it like other values?

#

when I try that I get a The name 'randomRoomOrder' does not exist in the current context so I assume not

shell sorrel
#

in start remove the List<int> part

dense goblet
shell sorrel
#

with nothing

#

just needs to be this randomRoomOrder = new List<int> { 1, 2, 3, 4};

#

you already declared randomRoomOrder above in the class

#

because you incuded the type again, that cuased it to redeclare it in the scope of start

#

instead of just writing to the one that exists already

dense goblet
#

I understand now, thank you so much

#

settled on this actually ```using System.Collections.Generic;
using System.Linq;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SceneManagement;
using static UnityEditor.Progress;

public class GameManager : MonoBehaviour
{
public GameObject Enemy;
public GameObject GameManagerObject;
public List<int> randomRoomOrder = new List<int> { 1, 2, 3, 4 };
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
//List<int> randomRoomOrder = new List<int> { 1, 2, 3, 4};
randomRoomOrder = randomRoomOrder.OrderBy(i => Random.value).ToList();
Debug.Log("randomRoomOrder: " + string.Join(", ", randomRoomOrder));
}

// Update is called once per frame
void Update()
{
    Debug.Log(randomRoomOrder[0]);
    





    if (Input.GetKeyDown(KeyCode.O))
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }
}

}

#

just make it in the begining like that instead of in start since it can't access it in start

shell sorrel
#

you can access it in start just fine

#

but because you had the type name infront of it, you just created a new thing with the same name that only start can see

#

instead of putting your new list into the existing randomRoomOrder field on the object

#

lines that start with a type or var declare a new variable in the current scope, which can shadow other things with the same names from outer scopes

thorn kiln
#

So, until now, the only way I've been shown how to handle main menu and game over screens is to add a bunch of conditions to if statements to stop the game doing things while these are active, but I know that can't possibly be the most efficient way to do it, especially once your game has a lot more than like, 3 things happening, going and adding if statements with "&& isGameOver" to everything would be incredibly inefficient

ivory bobcat
#

So was there a question?

thorn kiln
#

I guess what's another way to stop the game for main menu or game over screens?

shell sorrel
#

are better ways, but if you mean " incredibly inefficient" performance wise do not worry about that, its a rounding error worst case perf wise

ivory bobcat
#

Well, regardless you'll have to have some sort of condition for scenes to change. If you're referring to polling from update or an event system, the later would be more advance, clean, complicated etc

thorn kiln
#

Nah I just mean coding-wise. Adding a ton of if-statements to your code doesnt seem like a professional way to handle it.

ivory bobcat
#

No one will ever see it.

shell sorrel
#

so how most would do it would be breaking there game into states or phases

#

and triggering stuff like the UI to change via events

thorn kiln
#

Well no, but usually when it comes to something like this, there's usually a way to make it so you don't have to repeat something throughout your code to make it work

thorn kiln
#

Hmm, when I use private GameObject player; my enemies follow me wherever I go on the map, but if I use public GameObject player; they only move to my initial position

shell sorrel
#

look into what else changed

#

also how does player get set?

#

if its private and you are not using [SerializeField] its no longer set in the inspector if that was your intent

thorn kiln
#

Eh, it's too late at night for my brain to worry about it right now actually

#

I'll just change it back for now

#

I'll try and muster some brain power and figure out how to stop my enemy moving when gameover is true (or to only move when gameover is false)

shell sorrel
#

disable the component that moves enemies when gameover becomes try

#

or check if its true in its update and return early

thorn kiln
#

Yeah, Im trying to check if it's true, I'm just having trouble referencing it

#

In my OnCollisionEnter, it's as easy as player.gameOver = true;, but in update, it won't let me reference it

shell sorrel
#

i would not consider gameOver to really be a property of the player

#

would have some sort of game state manager that keeps track of that, which is easy for things to reference

thorn kiln
#

Well in my game, it currently is, so don't worry too much about that

shell sorrel
#

maybe even as a singleton

ivory bobcat
grave frost
echo ruin
#

I get an IndexOutOfRangeException by picking the spriteRenderer.sprite = overlayTiles[0]; and I'm wondering if it's because None (Sprite) is not a valid sprite?

#

Never mind. I had just accidentally added the script to the object twice, so one array was empty

hardy wing
# ivory bobcat No one will ever see it.

Not a good reason to use a bad implementation. Not saying what Josh talked about is bad but if there are easy improvements that don't decrease your code's quality, then why not do it?

hardy wing
eternal needle
hardy wing
#

But you're probably right

wintry panther
#

im making a 2ds platformer endless runner, but my player rigidbody keeps getting stuck on the ground objects at the seams between each ground object. i tried to use a composite collider but still the player gets stuck after a while

#

maybe it has to do with my sprites im using?

#

maybe i should try using tiles over prefab objects for the ground?

#

im spawning in the ground objects 1f units beside each other with the right pixel per unit for the ground sprite. shouldnt they combine into one collider?

ivory bobcat
teal viper
ivory bobcat
#

Where they're wanting to use a composite collider with tiles

#

Unfortunately I don't have too much knowledge with this

hardy wing
willow iron
#

So I have this movement script

void Update(){
if (movementEnabled == true)
        {
            HandleMovement();
            HandleRotation();
        }
}
void HandleMovement()
    {
        float vertical = Input.GetAxis(horizontalMoveInput) * walkspeed;
        float horizontal = Input.GetAxis(verticalMoveInput)  * walkspeed;
        
        Vector3 speed = new Vector3(horizontal, 0, vertical);
        speed = transform.rotation * speed;
        controller.SimpleMove(speed);
    }```
Now i have a seperate script to simulate entering and exiting a locker

if (!locker && releasekey)
{
move.movementEnabled = false;
transform.position = Lockerssfs.GetComponent<Locker>().enterPoint.position;
transform.rotation = Lockerssfs.GetComponent<Locker>().enterPoint.rotation;
locker = true;
} else if (locker && releasekey)
{
move.movementEnabled = true;
transform.position = Lockerssfs.GetComponent<Locker>().exitPoint.position;
transform.rotation = Lockerssfs.GetComponent<Locker>().exitPoint.rotation;
locker = false;
}


The code works fine... 50 pecent of the time
im assuming its something strange with character controller that i dont know about since ive never used it before
any suggestions?
ivory bobcat
#

You might want to describe the working and non working behaviors

willow iron
frosty hound
#

Where are you setting releasekey to false?

#

If it's carrying over the next frame, it will trigger the locker again.

willow iron
#
if (Input.GetKeyDown(KeyCode.E))
        {
            LockerInteract();
            releasekey = false;
        }

        if (Input.GetKeyUp(KeyCode.E))
        {
            releasekey = true;
        }

yeah i still dont know how input works in unity so i have this hacky method of doing it

ivory bobcat
willow iron
#

ill get to implementing that and see if it works

frosty hound
#

You're only setting releasekey to false when the player presses the key though?

wintry panther
#

maybe i shouldnt use the physics system?

#

i just want the player to run to the right automatically forever, with new ground objects sapwning infront

frosty hound
#

Characters typically use capsule or sphere colliders, not box, for that very reason of hitting seams.

wintry panther
#

and have 3 mechanics. jumping, sliding under objects, and fliping the gravity

#

i tried using the circle collider but the player bounces very slightly when hitting a seam

#

is there no way to stop the bounce?

frosty hound
#

Make sure your general scale of things isn't very tiny, which is a common issue with using sprites.

wintry panther
#

my pixel per unit is 16

frosty hound
#

Yes, but if the scale of things shrunk down? What is that compared to a default cube which is 1 unit big?

willow iron
wintry panther
#

so using a circle collider 2d is the best option?

frosty hound
#

Yes

#

Are these sections you're spawning in premade? Can you not prebake the composite colliders into them?

wintry panther
#

sec let me clean up the code

#

okay im calling this everytime a new ground object is made:

{
    //print("test");
    CompositeCollider2D composite = GetComponent<CompositeCollider2D>();
    composite.GenerateGeometry();
    //composite.gameObject.GetComponent<Rigidbody2D>().sharedMaterial = `new PhysicsMaterial2D { friction = 0.1f, bounciness = 0 }; // Reduce sticking
}```
#

so basically grabbing the composite collider and generating the geometry

#

code is messy right now since im just trying to get it to work

frosty hound
#

And your character is using a ridigbody? What detection mode is it set to?

wintry panther
#

not sure if the composite collider is actually updating

wintry panther
#

ah it works now! i forgot to set the box collider of the ground object to merge for the composite operation

chilly vigil
#

But I have a Godot version that has all the files. It is only the unity version that I deleted of my game by pressing crt d on my keyboard ⌨️ I thought it would duplicate it.

lethal shuttle
#

Looking for help in setting up an isometric depth sorting system for drawing sprites in front/behind walls

#

I've tried a couple of methods and wasn't able to figure anything out

past ivy
#

hello everyone, someone please tell how to share a project made in Unity with other developers !?

lethal shuttle
#

github is a good way to share projects

#

you should be able to find lots of information on how to set up a github repository

past ivy
#

for editing the project as a team !

raven zephyr
#

who can help me make a game

eternal needle
eternal needle
radiant voidBOT
# eternal needle !collab

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**

past ivy
eternal needle
lethal shuttle
#

so this is my current debugging- the yellow tile wall visualizes walls that should be drawn behind the player. the green visualizers show walls that should be drawn in front of the player

I am having trouble with manipulating the order in layer property for the player and the walls

past ivy
eternal needle
#

i dont use UVC, most people here dont. no matter which one you choose, first consult google

past ivy
#

my teammate added me as a user but I'm not able to see anything of the project

teal viper
#

And did you pull them to your local environment?

past ivy
teal viper
teal viper
past ivy
teal viper
misty nymph
#

Hi! I'm currently going through the Creative Core tutorials (https://learn.unity.com/pathway/creative-core), it's great! Still I like to envision "my game" alongside it, which is a Civilization clone in its essence (hex-grid, 3d, procedurally generated). I'd love to have one thing clarified though: In an attempt years past I worked with planes which had ~50x50 hex tiles on them and I used texture splatting to merge the tile types (grass, sand, ...) with each other. Later I'd add bump mapping and other fancy effects to it. My question is: Does this vision sit right? Is that how things are done? Or should I e.g. use DOTS to or some other fancy batching & instancing technology I haven't learnt yet to draw each hex separately?
Having that cleared up would help throughout the tutorial: How to bake lighting, which systems to use, do I need tesselation, etc.

sage wyvern
#

I need help, idk how to make a lock on system with cinemachine and i can't find any up to date videos which can help me.

cobalt sierra
thorn kiln
#

I'm having an issue. When my enemy collides with my player, if the player has a powerup, it's supposed to destroy them, which it does do, but if they don't have a powerup it's supposed to set gameover to true, which it doesn't do. So I'm a little confused why only half the if-statement is working.

    private void OnCollisionEnter(Collision collision)
    {
        if (collision.gameObject.TryGetComponent(out PlayerController player))
        {
            if (player.hasPowerup == true)
            {
                Destroy(gameObject);
            }
            else
            {
                Debug.Log("You are ded.");
                gameOver = true;
            }
        }
    }```
#

Hmm, wait, no ,thats not true

#

It's setting the clone to gameover but that's not changing anything in the game

midnight plover
#

Guess you figured it out 😉

thorn kiln
#

I guess I should reconfigure things and put gameover in the scene manager. I guess the issue is that clones don't work for this?

midnight plover
#

You are mixing several states here. CollisionEnter is happening on another object, if I understand you calling player via trygetcomponent. SO you are setting gameOver on your object where the collision method is happening. What is that object?

#

And who or what should react to gameOver being true? How are you accessing it?

#

You might read about events and have one source of truth for your game, so you know what your actual state and not letting several objects handle the state 🙂

thorn kiln
#

It should stop my players movement

    void Update()
    {
        if (!enemyScript.gameOver)
        {
            MovePlayer();
        }
        ConstrainPlayerPosition();
    }```
midnight plover
grand snow
#

why is this gameover var on the enemy?

thorn kiln
#

I couldn't tell ya

grand snow
#

ideally you would do something like player.Die() and then let the player object control its state

plush bronze
#

can anyone help me with collisions?

grand snow
naive pawn
grand snow
#

The better design would be:

  • enemy collides with player
  • enemy tells player to take some damage/die
midnight plover
#

just to clarify, enemyScript is just one instance of your class in your scene. If you have mulitple enemies, they all hold their own state of gameOver unless you are making a static value out of it. But that would be counterintuitive because the gameOver state is aglobal game state, not an enemy one

naive pawn
thorn kiln
#

Yeah, accurate

#

I'll end up doing that occasionally because I'm just writing it out how I'm thinking it in my head

plush bronze
midnight plover
naive pawn
plush bronze
# naive pawn how exactly are they "off"? we aren't psychic, you're gonna have to be more desc...

that's the movement script if you are wondering:

// Forward
        if (keyboard.wKey.isPressed)
            rigidBody.transform.Translate(0, 0, MovementSpeed * Time.deltaTime);
        // Backward
        if (keyboard.sKey.isPressed)
            rigidBody.transform.Translate(0, 0, -MovementSpeed * Time.deltaTime);
        // Left
        if (keyboard.aKey.isPressed)
            rigidBody.transform.Translate(-MovementSpeed * Time.deltaTime, 0, 0);
        // Right
        if (keyboard.dKey.isPressed)
            rigidBody.transform.Translate(MovementSpeed * Time.deltaTime, 0, 0);

and I am using a RigidBody

midnight plover
naive pawn
#

you're fighting the rigidbody over control of the transform

grand snow
plush bronze
pastel iron
grand snow
hexed terrace
plush bronze
naive pawn
naive pawn
plush bronze
grand snow
#

you set drag correctly on the rigidbody

naive pawn
#

and there is linear damping and friction that will reduce it

plush bronze
#

is there a way to max that?

naive pawn
#

you would not want to max that

plush bronze
plush bronze
naive pawn
#

there is also an option of setting the velocity

#

make sure you're working in FixedUpdate if you do AddForce with continuous forces as well

plush bronze
naive pawn
#

not "better", just different

plush bronze
naive pawn
#

yeah inputs are frame-bound

plush bronze
#

alrighty, so:

Movement in FixedUpdate
Input in Update
and not change position but the velocity?

grand snow
naive pawn
plush bronze
thorn kiln
#

Okay, I jury-rigged it, it's working now, enemies and players stop when they collide and gameover is now true

naive pawn
plush bronze
#

and when I wanna use it Ill read it?

naive pawn
#

not optimization, no. it's to make a coherent/consistent system

grand snow
#

example from something i did recently

//Movement
Vector3 input = inputs.gameplay.move.ReadValue<Vector2>();

//Change speed
input *= MoveSpeed / Time.fixedDeltaTime;

//Make local
input = rigidBody.rotation * new Vector3(input.x, 0f, input.y);

rigidBody.AddForce(input, ForceMode.Force);
naive pawn
plush bronze
grand snow
grand snow
naive pawn
#

that's not what my concern was about

#

but i see it's being used as an acceleration now rather than a deltaPosition

grand snow
#

it was something i did ages ago that i recently changed a tad to use force instead of velocity so I just fudged it a bit
nothing important anyway was just for fun

naive pawn
#

i guess it does, kinda...

grand snow
#

I probably tried it, stuff seemed to work and that was that 😆

naive pawn
#

i think it does work, im just having a hard time figuring out the values lol

balmy vortex
#

hey so like I have an enemy in my project that I want to move towards the player but I'm not sure how to actually get the angle it needs to move in

#

everything else is pretty easy but ya

teal viper
balmy vortex
#

wdym

grand snow
#

if the enemy and player are on the same "plane" (a flat floor) we just need a direction from the enemy to player

teal viper
#

You're gonna need a vector to move the object, not an angle.

grand snow
#
Vector3 direction = enemyPos - playerPos;
direction.Normalize();
teal viper
#

You're not allowed to work your game until then.

balmy vortex
#

wow

grand snow
#

That's right the game police will get ya

naive pawn
#

(but also should be playerPos - enemyPos if you want the direction from the enemy to the player)

grand snow
#

Yes my bad I did it backwards.
It's targetPos - myPos @balmy vortex

naive pawn
#

always get caught up on that myself lol 😆

balmy vortex
#

player position - enemy position = angle from enemy to player

#

ya?

naive pawn
#

not an angle, but a direction vector (once normalized)

balmy vortex
#

oki

naive pawn
#

you have the right idea, but it's important to make these distinctions, because they mean very different things mathematically

grand snow
#

We can produce a rotation from a vector3 but that is an additional step

naive pawn
#

(you should learn vector math on its own though, fwiw - once you internalize it, it lets you understand what you're doing a lot more)

balmy vortex
naive pawn
#

imagine position vectors as arrows pointing from the origin to some point in space
the length of that arrow along each axis is the size of that dimension in the vector

geometrically, adding vectors looks like putting the vectors together, "tip to tail"
negating a vector looks like reversing the arrow
thus subtracting a vector, say a - b looks like reversing b and then adding that to a, tip to tail
that ends up being equivalent to an arrow pointing from b to a

#

you could also view it as changing the origin - a - b is asking "what is a, relative to b?"
like 5 - 3 -> 2, you could view it as 5 is to 3 what 2 is to 0 (0 being the "origin")

#

this will probably make a lot more sense if you understand vector math itself

thorn kiln
#

Why do I not have LoadScene showing up?

grand snow
#

Did you make your own class with this name?

thorn kiln
#

Possibly? Yes, I did

gusty stone
#

Hi,
Why does it appear as "Not Connected" and "UNKNOW" even though my device is connected?
I am new to VR and it would be nice if someone could help me.

grand snow
umbral hound
#

Please ping me

thorn kiln
#

Okay, renamed things, works now

sage wyvern
cobalt sierra
umbral hound
#

Oh, got it, I know exactly what's causing it

#

this right here

private void GetMovement(Transform transform)
{
    if (m_CharacterController.enabled)
    {
        Vector3 vector = transform.right * m_MovementInput.x + transform.forward * m_MovementInput.y;
        m_MovementDirection.x = vector.x;
        m_MovementDirection.z = vector.z;
        // Insert sliding here
        m_MovementDirection = m_MovementDirection.normalized * CurrentSpeed;
        if (m_CharacterController.isGrounded)
        {
            if (m_GravityPower < -1f)
                m_GravityPower = -1f;
        }
        else
        {
            m_GravityPower -= m_Gravity;
        }
        m_MovementDirection.y = m_GravityPower;
        CollisionFlags collisionFlags = m_CharacterController.Move(m_MovementDirection * Time.deltaTime);
        if (m_GravityPower < 0f)
            m_GravityPower = 0f;
    }
}
#
if (m_GravityPower < 0f)
  m_GravityPower = 0f;
naive pawn
#

is m_GravityPower also flickering? (use the debug inspector)

umbral hound
#

Why I wonder why

#

No

naive pawn
#

not m_Gravity, mind you

umbral hound
#

Just m_MovementDirection.y

#

oh yes

#

GravityPower is in debug going from 0 to -3

naive pawn
#

it seems like you keep applying gravity and then stopping

#

what's with the m_GravityPower <= 0f anyways? that's a normal situation, but you're resetting down velocity there

umbral hound
#

Okay I changed it ```cs
private void GetMovement(Transform transform)
{
if (m_CharacterController.enabled)
{
Vector3 vector = transform.right * m_MovementInput.x + transform.forward * m_MovementInput.y;
m_MovementDirection.x = vector.x;
m_MovementDirection.z = vector.z;
// Insert sliding here
m_MovementDirection = m_MovementDirection.normalized * CurrentSpeed;
if (m_CharacterController.isGrounded)
{

        }
        else
        {
            m_GravityPower -= m_Gravity;
        }
        m_MovementDirection.y = m_GravityPower;
        Debug.Log($"Y Gravity: {m_GravityPower}");
        CollisionFlags collisionFlags = m_CharacterController.Move(m_MovementDirection * Time.deltaTime);
        if (m_GravityPower < 0f)
            m_GravityPower = 0f;
    }
}
naive pawn
#

also note that Physics.gravity is acceleration, so you need a deltaTime here

m_GravityPower += Physics.gravity.y * m_Gravity;

umbral hound
#

But it's still doing the same thing

#

yeah I tried but

#

it doesn't let my player jump properly

naive pawn
#

you would have to increase the m_Gravity to compensate, i believe

naive pawn
#

you need to apply gravity even when it's grounded

umbral hound
#

Okay

#

So what do I do about that? Like code wise

naive pawn
naive pawn
umbral hound
#

Oh so I just do this, just without the last if

private void GetMovement(Transform transform)
{
    if (m_CharacterController.enabled)
    {
        Vector3 vector = transform.right * m_MovementInput.x + transform.forward * m_MovementInput.y;
        m_MovementDirection.x = vector.x;
        m_MovementDirection.z = vector.z;
        // Insert sliding here
        m_MovementDirection = m_MovementDirection.normalized * CurrentSpeed;
        if (m_CharacterController.isGrounded)
        {
            
        }
        else
        {
            m_GravityPower += Physics.gravity.y * m_Gravity * Time.deltaTime;
        }
        m_MovementDirection.y = m_GravityPower;
        Debug.Log($"Y Gravity: {m_GravityPower}");
        CollisionFlags collisionFlags = m_CharacterController.Move(m_MovementDirection * Time.deltaTime);
        if (m_GravityPower < 0f)
            m_GravityPower = 0f;
    }
}
#

Whenever my player jumps though he just kinda suspends in mid air, he doesn't go down. And the gravity power doesn't go down either, just kinda fluctuates

#

OKAY

#

GOT IT

#

Thanks @naive pawn

#

wait

#

no, my player doesn't move now?

#

Okay had to take out the normalization, thanks

naive pawn
#

huh? you should have normalization

umbral hound
#

No idea why but I am like super slow

#

I found out normally I'm able to move around, but after I jump, it slows stuff down

#

Please ping ne

teal viper
shell sorrel
#

you have 2 things calling Move that could be happenign in the same frame overwriting what the previous has done

#

you also end up normalzing the movementDirection even when you are adding your jump direction to it

#

which means the movement on the xz plane would be less

static terrace
#

I made something in Unity. And I made the same thing in Java and without using an engine and it was way smoother, like it was both pixel art and the Java game seemed way smoother. I firstly thought that Unity is like this. But then I noticed that X values change the position a lot. Like 1 is a huge jump upwards, and in Java 100 is not even a lot. Is this a reason? When it's falling using my own and Unity's physics, my own is smoother

grand snow
#

the position shown in the unity inspector (and logged) has reduced precision to make it easier to read

#

there should be no issue unless your positions are super big or are doing something else bad with physics

static terrace
#

I am using RigidBody2D

#

I didn't change anything in the RigidBody

#

Or is it just FPS in unity is lower?

#

Note: Both games were run on an Android (Android Module)

grand snow
# static terrace Or is it just FPS in unity is lower?

You need to share more info for us to help. You can consider using interpolation, increasing the physics step frequency in the project and only applying force in FixedUpdate().
The game fps is not linked to physics processing frequency

static terrace
#

Okay I will try looking into the values that I could change in the RigidBody 2D

#

Thanks!

tiny dagger
#

hello haveing some issues with navmesh any help is appreicated

hexed terrace
#

!ask

radiant voidBOT
# hexed terrace !ask

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.

-# For more posting guidelines, go to #🌱┃start-here

tiny dagger
#

ive even tried codeing my own ai

hexed terrace
#

Read all the bullet points, not just the first one.

tiny dagger
hexed terrace
#

ok, what does the very last bullet point in the bot msg tell you to do? The one with ❔

charred monolith
#

guys when do i use mathf.PI

keen dew
#

Whenever you want

charred monolith
keen dew
#

That question doesn't make much sense. It's pi, it's used for calculating circumference and area of circles among other things. You don't need to plan beforehand when to use it. If you ever happen to need it you know it's there

charred monolith
polar acorn
polar acorn
#

Do you know what Pi is

charred monolith
teal viper
#

Time to learn math then

charred monolith
charred monolith
keen dew
#

If you want to calculate how to move a car based on how fast the wheels are spinning ask that (with details) and maybe pi is part of it, or maybe not

bright hull
#

As you can understand, the object that I pick, doesn't move smooth, I couldn't find a solution can someone help?

slender nymph
#

please share your code. nobody wants to scrub through a video trying to decipher what your code is doing

radiant voidBOT
eager elm
#

showing your code in video format is a new one 😄

bright hull
rich adder
rich adder
# bright hull

also you outta show the actual rigidbody inspector / settings

#

MovePosition is mainly meant for kinematics btw

eager elm
bright hull
bright hull
rich adder
bright hull
#

NOpe.

#

How to do that? I'm a bit newbie.

rich adder
polar acorn
bright hull
#

Doesnt fall.

polar acorn
#

At least this one was a screen recording and not a cell phone video

slender nymph
#

worst way i've seen to date is showing code in a gif

bright hull
#

Now it worked.

rich adder
#

movePosition is mainly used on kinematics according to the docshttps://docs.unity3d.com/6000.2/Documentation/ScriptReference/Rigidbody.MovePosition.html

bright hull
bright hull
final oxide
#

Hello! I have this project where arrows are being shot and sticking to walls and objects using a raycast at the tip of the arrow. I have this inconsistency where the arrow sometimes goes through the wall and the raycast doesn't detect anything because the arrow is going too fast. I have set the arrow's rb detection mode to continuous and the wall doesn't have a rb so I kept every setting as is.

I've thought of starting the raycast at the tail of the arrow so I can make it bigger and let it have more time to detect but I am not sure if that's a good idea in the long term. I've done a bit of research and I was wondering, is the Job System something that would help me fix this? I saw people are using it to detect collisions for bullet hell type games but in my scenario I only have a single arrow being shot every 2 seconds so it isn't as frequent.

wintry quarry
#

in genral if you're using raycasts for collision detection the collision detection mode on the rb is irrelevant

final oxide
wintry quarry
#

you're using this arbitrary constant of 1.75 as the distance

final oxide
#

I was just messing around to see if setting it longer worked

wintry quarry
#

show the full script so we can see how the arrow moves

final oxide
#

Im simply adding a force aligning it with my crosshair

wintry quarry
#

this isn't the full scirpt.

#

it's not clear what startingPos is, for example

#

but basically I would expect something like this:

// FixedUpdate for physics, not Update
void FixedUpdate() {
  if (Physics.Raycast(rb.position, rb.rotation * Vector3.forward, out RaycastHit hit, rb.velocity * Time.fixedDeltaTime, layersToHit)) {
    // handle collision
  }
}```
final oxide
#

Sorry Its handled in two different scripts so I tried putting the parts that are related to shooting the arrow

wintry quarry
#

I just wanted to see the full script of the arrow

#

or btoh

oblique ridge
#

sooo, unity doesn't automatically setup visual studio to work together by default?

slender nymph
#

!ide

radiant voidBOT
wintry quarry
oblique ridge
#

didn't have these options until i manually went to the package manager and downloaded the visual studio editor pkg

rich adder
#

Unity cannot assume you will be using Visual Studio if you're on an OS that doesnt use VS

slender nymph
rich adder
#

but yeah the hub installs VS with the proper workloads but you still need to select it and stuff

oblique ridge
rich adder
oblique ridge
#

it's because i used browse to add the devenv.exe manually

#

but of course only manually downloading the package worked

rich adder
#

you just need to try Regen Project Files and open script from unity, then check VS make sure it loaaded

oblique ridge
#

but everything works now

rocky canyon
#

aye did the finally remove the old one?

#

cant seem to find it anymore.. it used to show alng side

#

if they did.. and they default to the one that works for both thats awesome!

full axle
#

I need some help I don’t understand number 2 or number 8

wintry quarry
slender nymph
full axle
rich adder
#

and they were never heard from again..

feral sapphire
#

How can I apply "on click" changes to a prefab? I cant select a empty object (manager) to the prefab. and I also tried putting the prefab onto the Hierachy and added it to that one and then clicked "overrides - apply all" but it changes nothing. as seen in the picture there is differences there, but the left one will never update no matter what I do. it updates if I changes the color but not the "on click"

rich adder
feral sapphire
grand snow
#

are you in a prefab stage? (when you open the prefab to edit)

rich adder
feral sapphire
grand snow
#

If those 2 unity event subs will not apply then they surely point to SCENE instance objects

rich adder
grand snow
#

The instances of BreadAppears and Scriptmanager specifically

full axle
feral sapphire
#

so having a prefab to spawn individual things in the scene is pointless then?

slender nymph
grand snow
#

This is why the changes will not apply as they are not able to be stored in a prefab asset

full axle
polar acorn
rich adder
slender nymph
rich adder
#

you have to explain whats happening vs what you expect to happen for starters

polar acorn
summer wren
#

Is it common to become frustrated over coding and Unity Editor? Lol.
Sometimes I become super annoyed and have to keep going until it is fixed.

feral sapphire
rich adder
polar acorn
#

Prefabs don't exist in the scene

#

So adding an on click to it won't matter

polar acorn
#

You need to add an on click to the instance you create from it

feral sapphire
full axle
naive pawn
polar acorn
summer wren
slender nymph
rich adder
#

(i mean thats if you move it via physics ofc)

naive pawn
feral sapphire
polar acorn
full axle
full axle
rich adder
slender nymph
rich adder
naive pawn
slender nymph
full axle
polar acorn
full axle
polar acorn
#

Maybe go back into the lesson

grand snow
rich adder
#

damm i need those art skills

slender nymph
naive pawn
rich adder
#

what kinda class teaches coding shit and not allow googling issues..sounds terrible teacher

naive pawn
#

the internet is a massive resource

polar acorn
#

If this is some kind of test then us answering would be cheating. Ask your teacher.

naive pawn
#

way better than us, usually - because we got a lot of our info from the internet too

full axle
naive pawn
slender nymph
naive pawn
rich adder
#

the whole point is for you to learn how to figure this stuff out

feral sapphire
rich adder
#

problem solving is like 90% of this field

naive pawn
#

real talk - you gotta learn to help yourself. using google is the most basic form of finding information in this day and age

rich adder
#

if you dont learn how to problem solve, what you even doing

full axle
full axle
grand snow
full axle
polar acorn
slender nymph
polar acorn
rich adder
#

maybe I can become a teacher too.. how are these quacks teaching...

polar acorn
#

This is kind of a fundamental gap in knowledge

slender nymph
polar acorn
feral sapphire
summer wren
polar acorn
naive pawn
#

@full axle if you're missing the basics, we can't practically help you.
you need a certain foundation to be able to understand and apply the answers we give
if you want us to just give you an answer and then blindly copy it without learning, you won't be able to apply the knowledge forwards and you'll still need help in the future for similarly simple tasks

feral sapphire
#

but it only spawns as it is, with a random range on the screen. but has no variables attached to it, which I thought I could do via prefab xd

polar acorn
grand snow
#

do i need to draw another cool picture?

feral sapphire
#

now it suddenly "works"

rich adder
feral sapphire
#

it has the variables now once spawned in

dark spear
#

Hello, I have this problem. The character will only move horizontally with the A and D keys. However, the direction it is facing is not forward, it automatically rotates itself. How can I fix this?

rich adder
dark spear
#

I didn't do it with code, I used script graph

#

Do I need to write to this channel?

rocky canyon
#

no visual scripting channel

feral sapphire
dark spear
#

okey thanks

grand snow
feral sapphire
#

but now my things spawn in with the correct "onclick" actions, but now I just have to figure out why its not "doing anything" :D.

#

I noticed once I was refering to the object, I forgot to select my manager and locate tht reference

#

Im sure everyone here can tell me whats wrong in this script. I cant see the "you hit 1 bread" or the "hits" increasing once hitting the bread that spawns. im sure you would be like.. ah no this is so outdated...

radiant voidBOT
naive pawn
#

my eyes..

feral sapphire
naive pawn
#

sunglasses, maybe

feral sapphire
#

its the "onclick" action on the actualt spawned object

rich adder
polar acorn
feral sapphire
polar acorn
feral sapphire
naive pawn
#

what's the error?

feral sapphire
naive pawn
feral sapphire
naive pawn
#

pay attention to your suggestions, make sure you're importing the right thing

#

(on that note, you also shouldn't need the UnityEngine. on the quaternion where you instantiate)

feral sapphire
#

I didnt even import that one myself so no ide where it came from, maybe from another "solution"

naive pawn
#

you selected it when autocomplete suggested it

rich adder
feral sapphire
naive pawn
#

cool, then check where it's supposed to be called from

polar acorn
rich adder
#

this is a code channel

worn bay
rich adder
#

you good

feral sapphire
polar acorn
feral sapphire
#

for example if ur in a 3d map you cant select 2d objects or so etc xd

dreamy scarab
#

hi

#

im guessing that i have a beginers question

feral sapphire
#

nvm, I cant make a object from the canvas into a prefab as it just turns it all invsibile xD.

naive pawn
radiant voidBOT
# naive pawn !ask https://dontasktoask.com

:thinking: Asking Questions

:mag: Search the internet for your question!
:book: Use the API Scripting Reference and User Manual and this troubleshooting site for commonly posted issues.
:wrench: Attempt to debug your issue.
:thought_balloon: Find an appropriate channel by reading the name and description in #🔎┃find-a-channel
:grey_question: And don't ask to ask, ask a full question illustrating with screenshots if needed.

-# For more posting guidelines, go to #🌱┃start-here

polar acorn
rich adder
#

the prefab usually puts it in a canvas so it can be previewed

dreamy scarab
#

there is a right way to do that?

feral sapphire
naive pawn
polar acorn
dreamy scarab
#

i have a custom class that saves 2 min max sliders to create a rect on the screen

rich adder
dreamy scarab
#

i couldnt find a direct way to set the rect data from a min max slider than creating another rect with that info then replacing things

feral sapphire
naive pawn
rich adder
polar acorn
dreamy scarab
#

i can, but first i had to convert the values.

naive pawn
naive pawn
dreamy scarab
#

i know, i didnt do the corrections yet

feral sapphire
rich adder
polar acorn
dreamy scarab
naive pawn
#

oh yeah, it is readonly. i didn't notice that note in the docs, mb

feral sapphire
dreamy scarab
#

nah

naive pawn
#

you can just do some math then if you don't want the refRect

polar acorn
rich adder
polar acorn
#

Just a screenshot of the full unity window with this invisible object selected

feral sapphire
polar acorn
dreamy scarab
#

i dont have a problem using a "copy" from a created rect... i just needed to know if there is a better way

#

i can do the math to create the rect

#

i just dont wanna to that😅

feral sapphire
dreamy scarab
#

it was a pain in the ass to create the preview on node correctly to convert again i guess it would be the same

polar acorn
polar acorn
dreamy scarab
#

i cant directly... the values from the class comes from a 2 min max sliders

#

one to vertical value, other to horizontal value

full axle
feral sapphire
naive pawn
dreamy scarab
#

i know

#

the problem cames when i have to convert from the preview i made

#

so, let me elaborate a little

naive pawn
#

yeah we do not have any context on what you're doing

polar acorn
feral sapphire
#

now it works

polar acorn
#

The .rect = might not work if balao is a property instead of a variable

#

but the .Set should work fine

feral sapphire
naive pawn
polar acorn
dreamy scarab
#

i made a custom node system to make a dialogue system.

currently i made a way to make a preview to replace character position and size...
then i realized that i fucked with the popup-dialogue ballon.

then i had to make a preview editor to the ballon as well...

the character is a vector2 for position and a float for size...
i tryed the same form the rect ballon but one of my coworkers asked to do the size of the ballons with sliders...

with 4 sliders was a lot strange to modify the it. so i changed to a min max slider...

then we got here

#

the pink square ****

#

currently im re drawing the preview/editor to the game

feral sapphire
#

how do I make so it spawn under the canvas as a child and not as a "object" below canvas (not on the canvas) ?

polar acorn
slender nymph
#

the Instantiate method has an overload that allows you to specify a parent object

feral sapphire
#

okay

summer wren
#

I know this is more UI issue and willing to write a script for it if need be.
How to have the TMP Input Field follow the text of the user rather than it cutting out through the objects boundaries? (It isn't set as "Trunicate")
The code will be easy. Just don't want to have to create a script for a little thing if it can be done in Editor.

hexed terrace
#

sounds like you want the inputfield to change size, growing with the length of the input text.. look into the layoutgroups, layout element, content size fitter

summer wren
hexed terrace
#

that last sentence is not understandable

kind skiff
#

I am trying to use unity ecs but based on the tutorial that I am watching it asks me to add game object entity into my gameobject which will convert the monobehaviors into the components of an entity

#

I'm not sure whether it is version problem or I did the setup wrong

#

But for some reason I can't find the GameObjectEntity thing

kind skiff
summer wren
#

Can we ask about NodeJS here? Not about coding help, but a question about something.

grand snow
#

is it unity related? i presume not

summer wren
#

It can relate to it but yeah not a part of it. All good.

edgy sinew
naive pawn
naive pawn
edgy sinew
#

Hey guys, what is your #1 technique to achieve smooth camera rotation? ⭐
I've tried smoothing lookStickX and lookStickY like with Mathf.SmoothDamp, independently. And I've tried combining them to use Vector2.SmoothDamp too

I haven't tried doing any curve.Evaluate() yet but, maybe that'll be better.

#

Oh darn maybe the Unity inputactions asset can do smoothing in the pre-processors.

craggy monolith
#

hey everyone! i made a cool app for Quest 3 that i’ll opensource soon. looking for help with some coding and design! tried to make a ReadyPlayerOne \ Dr Strange reality portal
if you want early access to the APK + Realtime Video2Video model, drop an emoji and i’ll DM you

naive pawn
#

isn't there a Quaternion.SmoothDamp function? apparently not

naive pawn
feral sapphire
#

I have another question, Now that I manage to get my object to spawn correctly, under a parent and such, how do I make them "dissapear" once clicked? I cant simply ".setActive(false)" because they are from within a prefab and not a specific object per say. I can only stop them from further spawning but the ones who have appeared will always stay and not get deleted. how can I solve that?

craggy monolith
edgy sinew
polar acorn
feral sapphire
naive pawn
#

!collab

radiant voidBOT
# naive pawn !collab

:loudspeaker: Collaborating and Job Posting

We do not accept job or collab posts on Discord.
Please, use Discussions to promote yourself as job-seeking, advertise commercial job offers, or look for non-commercial projects to participate in:
• ** Collaboration & Jobs**

polar acorn
naive pawn
polar acorn
#

as I said, call it on the objects you want to deactivate

feral sapphire
# polar acorn ...then deactivate the clones

yea i get that, but I cant see the clones til the game starts as it spawns in aafter some time. when I deactive the "reference" of the clones, it deactives that one but not the "clones" who already has spawned

edgy sinew
polar acorn
naive pawn
#

you mean with wronglerp?

edgy sinew
naive pawn
#

no, i mean a wrong usage of lerp

edgy sinew
#

oh, yeah exactly

naive pawn
feral sapphire
polar acorn
#

That's how you disable an object

#

If you call it on the object you want to disable, it'll disable it

feral sapphire
naive pawn
#

the name is irrelevant

polar acorn
naive pawn
#

you need references to each one anyways if you want to manage them later

feral sapphire
#

how else am i gonna know what to disable lol

polar acorn
#

How do you know which one you want to disable

naive pawn