#💻┃code-beginner

1 messages · Page 275 of 1

flint falcon
#

what does direction.normalized do exactly

rich adder
# flint falcon what does direction.normalized do exactly

When any vector is divided by its own magnitude, the result is a vector with a magnitude of 1, which is known as a normalized vector. If a normalized vector is multiplied by a scalar then the magnitude of the result will be equal to that scalar value. This is useful when the direction of a force is constant but the strength is controllable (eg, the force from a car’s wheel always pushes forwards but the power is controlled by the driver).

flint falcon
#

I was using

#

if (Input.GetKey(KeyCode.W))
{
rb.velocity += direction.normalized * acceleration * Time.deltaTime;
}

#

and my space ship would just go flying

rich adder
#

you keep adding onto the current vel

flint falcon
#

i switched it to

rich adder
#

should prob be rb.velocity = direction.normalized * acceleration

flint falcon
#

ok dont want to do that

#

let me give that a try

#

cause im now using

#

if (Input.GetKey(KeyCode.W))
{
// Convert transform.up to Vector2

rb.velocity += rb.velocity += transform.up * acceleration * Time.deltaTime;
#

but i have a ambiguous error

#

that comment is old

rich adder
#

yes if your rigidbody is 2D

#

you cannot do V2 + V3

summer stump
rich adder
#

ah yeah prob this

flint falcon
#

not even sure for new and just trying to learn hands on

summer stump
flint falcon
#

no

#

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

#

can i post the whole code it isnt long

summer stump
#

!code

eternal falconBOT
summer stump
#

Also copy the actual error.
It wasn't what I was thinking

flint falcon
#

{
public float acceleration = 5f;
public float deceleration = 2f;
public float maxSpeed = 10f;

private void Update()
{
    
    Vector3 mousePosition = Input.mousePosition;
    mousePosition = Camera.main.ScreenToWorldPoint(mousePosition);

    Vector2 direction = new Vector2(mousePosition.x - transform.position.x, mousePosition.y - transform.position.y);

    transform.up = direction;


    

    Rigidbody2D rb = GetComponent<Rigidbody2D>(); // Cache the Rigidbody2D component

    // Accelerate when pressing W
    if (Input.GetKey(KeyCode.W))
    {
        // Convert transform.up to Vector2

        rb.velocity += rb.velocity += transform.up * acceleration * Time.deltaTime;

       
    }

    // Decelerate when pressing D
    if (Input.GetKey(KeyCode.S))
    {
        rb.velocity -= rb.velocity.normalized * deceleration * Time.deltaTime;

    }

    // Limit the speed of the spaceship
    rb.velocity = Vector2.ClampMagnitude(rb.velocity, maxSpeed);
}

}

rich adder
#

i think the error is them doing vector2D + Vector3D

flint falcon
#

that didnt do what i ment

eternal falconBOT
flint falcon
#

sorry!

rich adder
#

the rigidbody2D velocity is vector2, transform.up is Vector3

flint falcon
#

I thought i copied the link

rich adder
#

so its ambiguous + operation

flint falcon
#

Severity Code Description Project File Line Suppression State
Error CS0034 Operator '+=' is ambiguous on operands of type 'Vector2' and 'Vector3' Assembly-CSharp C:\Users\nick\Shambles Ship\Assets\Scripts\Followmouse.cs 32 Active

summer stump
#

Oh no worries. I was jumping back and forth and honestly forgot I did that here earlier even though it was like a second ago lmfao

flint falcon
#

or did I just do this all wrong?

rich adder
flint falcon
#

lol yup i could tell by the way my player moved

rich adder
#

like i said if you don't want it to keep increasing speed don't keep adding the current vel/speed to itself, twice..

#

for example rb.velocity = transform.up * acceleration

#

or rb.velocity = direction * acceleration

flint falcon
#

rb.velocity = transform.up * acceleration worked

#

error gona just some re-order errors

rich adder
flint falcon
#

what do you mean? (im super new to this and if you don't feel like explaining I understand)

rich adder
#

but keep inputs / mouse direction in Update

#

use floats / vector 2 to store the inputs from Update in variable to use in FixedUpdate

#

also doing this inside Update is kind of bad on performance
Rigidbody2D rb = GetComponent<Rigidbody2D>(); // Cache the Rigidbody2D component

flint falcon
#

put it out side update

rich adder
#

at very least it should be once in Awake () where rb stored in the class not locally too

flint falcon
#

and I broke everything.... I think I have some reading to do

rich adder
flint falcon
#

im embarresed to even show it. It's a combination of message boards, tutorials, and chat gpt

rich adder
#

why is FixedUpdate nested inside Update..oh no..

flint falcon
#

yeah im realizing that. Did alot better without it

rich adder
#

this is def an compile errror
private Rigidbody2D rb = GetComponent<Rigidbody2D>();

#

is your IDE not configured ?

#

should be underlined red

flint falcon
#

oh it is

#

I moved it there when you said dont put it in update

rich adder
#

said the function should be in awake since it only runs once

#

but rigidbody variable should be stored in the class yes, outside of a method

#

you cannot perfom a method on fields when you declare them

sullen epoch
#

Hi there sorry if I'm cutting in, I'm looking to improve my Debugging techniques and safe to say its already going off to a flying start 🙃

for some reason when i draw my lines they are aligning to (1, 0, 1) in world space instead of being local to my game object, however Debug. Log shows that localNodePos is converting the the coords. i tried researching to find out why this is happening but couldn't find anything

 void Update()
    {
        for (int i = 0; i < nodePos.Length; i++) {
            Vector3 localNodePos = transform.InverseTransformPoint(nodePos[i]);
            Debug.DrawLine(transform.position, localNodePos, Color.red, 0.0f, false);

            Debug.Log(localNodePos);
        }
    }
eternal needle
flint falcon
#

everything is now red

rich adder
#

you are randomly changing things without having any fundamentals

#

it will break things

flint falcon
#

good point

#

i have some more reading to do

flint falcon
#

ty

sullen epoch
eternal needle
hushed hinge
#

anyone thinking?

sullen epoch
rich adder
eternal needle
sullen epoch
#

Ahhh I see now, I thought the direction vector inside the parameter would need to be normalized & the distance would need to be manually calculated. thanks for your help

#

for DrawRay

inland cobalt
#

How might applying a velocity to a 2D rigid body randomly break? I’m not sure what cause it, but I’m currently setting an objects velocity with rb.velocity. And when I inspect the rigid body component after the velocity has been applied it shows that it has the expected velocity, yet it doesn’t move anywhere. There’s nothing obvious that it could be colliding with either, so I’m stumped to be honest, anyone know why this may be?

inland cobalt
rich adder
#

not cropped. the entire thing

inland cobalt
rich adder
#

the alpha is set to 0

#

oh nvm trail renderer..

flint falcon
#

@rich adder i fixed it

inland cobalt
#

yeah that's not the problem, i can see it.

I don’t get how an object can have a velocity yet be stationary regardless, that makes zero sense

vale karma
#

what would i search if I wanted the feature that supermarket sim has where it places an object on the slot you click?

#

basically a box on a rack

rich adder
inland cobalt
hushed hinge
rich adder
#

maybe splitting your code up would help disabling certain features

hushed hinge
#

uhhhh... my heard is literally spinning around by this

rich adder
#

welcome to gamedev 😈

vale karma
#

i loveee state machinessss

hushed hinge
#

I thought it was something like freeze position and then unfreeze position type of thing?

rich adder
#

if(chargingJump) return;

//rigidbodyMovement

sage folio
#

hey when you are loading another scene do you have to deload the one you are currently in? when i try to load another scene it just puts it in the hierarchy, here is my code: https://hatebin.com/zywhfrojad

rich adder
#

do you know what that is ?

sage folio
#

no, i'm not fully familiar

rich adder
#

so why is it in the code ?

sage folio
#

oh

#

oh thats helpful

#

thank you!

rich adder
sage folio
#

heh i actually checked that at first, i just missed that part

rich adder
#

if you omit the second parameter for loading mode, it defaults to Single

sullen epoch
#

i am so confused as to why I'm getting this error :/

swift elbow
sullen epoch
#
public class PlayerContol : MonoBehaviour
{
    
    public Rigidbody rb;
    public Transform[] nodePos = new Transform[4];
    public LayerMask mask;
    public float springRestPos = 1f;
    public float springForce = 10f;
    void Start()
    {
        rb = GetComponent<Rigidbody>();
    }

    void Update()
    {
        for (int i = 0; i < nodePos.Length; i++) {

            Vector3 localNodePos = nodePos[i].position;

            RaycastHit hit;
            if (Physics.Raycast(localNodePos, Vector3.down, out hit, Mathf.Infinity, ~mask)) {
                float offset = springRestPos - hit.distance;
                Debug.Log("Position of node " + i + ": " + nodePos[i].position);

                if (offset > 0) {
                    Vector3 force = Vector3.up * offset * springForce;
                    rb.AddForceAtPosition(force, localNodePos);
                    Debug.DrawRay(hit.point, Vector3.up * offset);
                    Debug.Log("pass");
                }
            }

            //Debug.DrawRay(transform.position, localNodePos, Color.red, 0.0f, false);
        }
        Debug.Log(nodePos.Length);
    }
}
swift elbow
#

if you have one

sullen epoch
#

its not set up as a prefab atm, its just a game object with 4 empties inside it

sour ruin
#

Hi, I've got a design issue: my player wants to interact with world objects some of which have purely self contained logic (like a door that opens and closes) where others have a combination of self contained logic but also interact back with the player (like a piece of equipment that would need to be picked up or anything else that otherwise affects player state). My solution thus far is to have an interactable interface with a query method that passes a player reference to the I_Interactable object. This I_Interactable object then has the option of calling public methods on the player using the passed reference. The only public parts of the player are the methods that interactable objects can call; see the example where a player interacts with a piece of equipment which then calls the players RequestEquipmentSlot. Is this an acceptable way of doing this? To scale for other interactable objects with callbacks I just need to add more methods to player, is this acceptable? I feel this is a common concern that arises so are there standardised ways of doing this? Is there perhaps a way of specifying in the InteractQuery of I_Interactable that should it call any functions, it can only call functions of the signature (this, InputAction.CallbackContext)?

rich adder
#

search hierarchy t:scriptname

polar acorn
swift elbow
sullen epoch
#

i just deleted the cube and reapplied the script and the error was gone

#

and now im thinking i probably applied it twice to the same object

#

.... i did 🫠

#

on that note think its time for bed 🫡 thanks all for the assistance

topaz mortar
#

I'm currently using a lot of UI buttons with the On Click method in the editor linked to my script, will that work on steam deck, mobile, ...?
Is the click converted to a touch screen tap?

teal viper
flint heath
#

I am trying to make a character move around the screen but with no gravity so without a rigidbody. Could someone pls give an example of how I could get started in doing this? all the tutorials I've seen use myRigidBody.something * something or whatever

#

like, if i want my character to move to the left, i know i would have to start with something like this, but where do I go from there?

rich adder
#

you can just disable the gravity

flint heath
#

that

#

ok

#

yeah i guess i could do that

rich adder
#

3D uncheck it, 2D gravity scale 0

flint heath
pallid sand
#
            Screen.SetResolution(resolution.width, resolution.height, false);
            Debug.Log($"ِCurrent resolution height {Screen.currentResolution.height} and width {Screen.currentResolution.width}");```
pallid sand
rare basin
#

Where are you testing it? Hopefully not in the editor

simple token
#

Im trying to drag my GameUI canvas into this Script variable, But it either says "type mismatch" or gives me the crossed out circle:

keen dew
#

Can't drag scene objects into prefabs

simple token
#

Ohh gotcha, appreciate it!

hollow zenith
#

I am stuck on moving UI element on x axis slightly back and forth:

      // Update
        Vector2 pos = new Vector2(transform.position.x + xOffset, transform.localPosition.y);
        transform.localPosition = pos;

Trying different things, but localPosition seems to work best, but only if I create Vector2 out of .position.x, if I use localPosition.x then UI flies off somewhere.
But even with the above, its still flying off just slower 😐

Moving it in the inspector requires me to move it by 100px on x axis to move a bit, but with the code above it moves it by 100px per second, even tho xOffset is between -3 and 3(so the idea is to move it back and forth 3px)
What do I do to move UI element properly?

#

I might need to use RectTransform.anchoredPosition

#
   rectTransform.localPosition += (Vector3)pos;
   rectTransform.anchoredPosition += pos;

This works 😐

exotic hazel
#

In this video the stone at the start is mass placed through terrain.The script isnt running icant touch it for somer reason.Then i place the same stone through inspector then the code runs i can touch it .the code doesnt run on mass placed objects can someone help

#

do i need to create a script to spawn the prefabs?

exotic hazel
#

im here i need to do so that on the spawncoords if the texture is GroundTexture execute a code.How do i do so

modest quarry
#

i have one [SerializeField] private Field field and a static function that uses this field but since i cannot make the field static what shold i do

eternal needle
#

it helps if you state your actual use case, so people can suggest better

modest quarry
modest quarry
eternal needle
#

all of them depend on what you're doing. static functions are generally supposed to have no relation to an instance of the script

modest quarry
#

Okay

modest quarry
#

any workround keeping IsValidItem static?

modest quarry
keen dew
#

You really should describe what your actual goal is but this is what singletons are usually used for

modest quarry
keen dew
#

If there are multiple instances then how would you know which validItemList to use?

modest quarry
#

yup thats gonna be constant for all

keen dew
#

Then why can't you make it static?

modest quarry
#

make what static? the serialized field?

languid spire
keen dew
#

Yes, the thing that you asked about

languid spire
#

that way you can have the static varaible and yet still serialize it

mortal burrow
#

Hi, I have been working in a camera following script to make the camera go at the same speed as the player (the speed increases with time) but, if the player gets stuck, the camera still has to move. Also, the camera has to follow the y cord of the player so if the player jumps, the camera also does.

The problem I have is that when both things are in the same script, the camera follows the player, but the player does a blinking (I can do a video if needed). And if I do it in a different script, when reading the speed from the player movement script, throws "NullReferenceException 'Object reference not set to an instance of an object'"

To move the camera I use this (image)

modest quarry
keen dew
#

well you obviously have to create the list and fill it with whatever you want

modest dust
#

A fast and easy (maybe not so pretty) solution would be just

private void Awake()
{
  if (static_isInitialized)
  {
    return;
  }

  static_isInitialized = true;
  static_validItemList = instance_validItemList;
}```
eternal needle
modest quarry
modest quarry
languid spire
eternal needle
mortal burrow
eternal needle
north kiln
teal viper
teal viper
#

These variables can't even be null. They're value types

#

You must be misunderstanding something

slender sinew
north kiln
#

The variable I noted is clearly null

#

Regardless, we shouldn't have to go off images. Stack traces should be provided, same with line numbers

mortal burrow
north kiln
mortal burrow
mortal burrow
north kiln
#

Neither of those things are PlayerMovement

modest dust
# mortal burrow

Your Player is assigned, but what about PlayerMovement. It won't magically know which instance to use to access these fields

mortal burrow
modest dust
#

and make it private if you're using SerializeField

empty dagger
#

how do I specify that the player isnt touching a wall? the bool that lets you walljump is staying turned on when i leave the wall, idk how to make it turn off

mortal burrow
modest dust
#

You don't assign the script, you assign an instance with that component

empty dagger
mortal burrow
teal viper
hexed terrace
#

Maybe the wall check is still happening and returning true, setting the bool back to true straight after being set false

empty dagger
#

it gets set to true when the player isnt grounded and is touching a wall, and it gets set to false when the player jumps off a wall, but that's not working and theres also no way to set it to false if the player doesnt jump and just leaves the wall

hexed terrace
#

so, go through your code and find out where that is happening.. and tweak the wallcheck

empty dagger
#

idk what I could change, it's just "if contact.normal.y < 0.1f, walljump = true"

teal viper
eternal falconBOT
empty dagger
teal viper
empty dagger
#

where would I use that?

teal viper
#

In your code. It would be called when you stop colliding with the wall(or anything else)

empty dagger
#

i wouldnt know how to specify im leaving the wall

teal viper
empty dagger
#

I'm confused

empty dagger
#

is there no way to just write a line of code that says "else if there's no contact.normal.y, bool = false"

naive nest
#

can someone help me, i go to build my game it loads and after it loads i go to my folder and nothing is there
and right after it builds my pc freezes for a second

naive nest
modest quarry
hidden sleet
#

If I have this class labelled as abstract, with a virtual method in it, with a class that derives from this one that overrides said virtual method, will calling SaveInventory in this case in the abstract class just do what the method in that abstract class does or the method that is overriden? ```cs
public abstract class InventorySO<T, I> : ScriptableObject where T : InventoryItem, new() where I : class
{

public void Start(){
SaveInventory()
}

public virtual void SaveInventory()
{

}
}```

public class ProcessedInventorySO : InventorySO<InventoryPlainItem, ProcessedItemSO>, ISerializationCallbackReceiver
{
public override void SaveInventory()
{
    string json = JsonUtility.ToJson(new ProcessedInventorySaveClass(inventoryContainer), true);
    if (inventoryContainer.Count != 0)
    {
        File.WriteAllText(Application.persistentDataPath + "/ProcessedInventory.json", json);


    }
}
}```
mortal burrow
modest dust
#

But if you want some base functionality in an abstract class, then you can always just do this:

public abstract class AbstractBase
{
  public void GeneralMethod()
  {
    // Base stuff
    // ...
    CustomImplementation();
  }
  
  protected abstract void CustomImplementation();
}``` 
And not care about calling any base method
empty dagger
#

Oh do I not need to specify what each collision is?

#

yeah that worked, thanks, I didn't know it worked like that

empty dagger
#

is there a way to make it so the player falls slower while a certain bool is active? I keep trying to look it up and the only results are how to change the game's physics completely which isnt what I want

hazy crypt
#

Ive done this

#

Lemme see how I did it one seond

empty dagger
#

okie cool

hazy crypt
#
//gravity 
        rb.AddForce(-Vector3.up * gravityForce);
#

mine is just like tbhis

#

So set you normal rigidbody gravity to the "slow" one and then add an additional gravity force when not slow

#

Guys im having a problem with a countdown timer

#
if (countinTimer > 0)
        {
            Time.timeScale = 0f;
            countinTimer = countinTimer -= Time.fixedUnscaledDeltaTime;
        }
        else
        {
            Time.timeScale = 1f;
            timerTime = timerTime += Time.deltaTime;
        }
#

I want it to countdown for 3 seconds, then start counting up

#

Its a speedrunning game

#

the counting up is working fine, but the countdown jumps from 3s to -1.5 on the first frame that the game is played

long steppe
#

creating a main menu for my first project (following a tutorial), trying to get the start game button to load the main scene where the gameplay happens: i've created a script with a function that starts the gameplay scene, added an on click thingy to the button in the inspector and attached the aforementioned script, but when i go to assign the function of it, it doesn't show up, any help?

oak ginkgo
#

@slender nymph Is this the place I'd ask for support?

slender nymph
#

is your issue code related? if so, read the channel name and description and decide for yourself

oak ginkgo
#

regular douche then aint ya, it might be, or it might be something wrong with something else like layers or something. I don't know, thats the point

#

I don't know enough about coding to know if thats the issue, or if its something else I've gotten wrong

slender nymph
#

well you've not provided any useful details about your issue so i have no idea what it is. but you've also just guaranteed that i won't help so good luck

oak ginkgo
#

Sounds like I don't want your help with your attitude lmao

long steppe
burnt vapor
#

If only they would actually share the issue instead of making a scene

halcyon geyser
#

Hard task for some

hidden sleet
#

Trying to set a breakpoint in this method but it says it won't be hit. Is there any particular reason why? ```cs
public class ProcessedItemDatabase : ScriptableObject
{
public ProcessedItemSO[] items;
public Dictionary<ProcessedItemSO, int> ItemToId = new Dictionary<ProcessedItemSO, int>();
public Dictionary<int, ProcessedItemSO> IdToItem = new Dictionary<int, ProcessedItemSO>();

public void CreateDatabaseDictionaries()
{
            ItemToId = new Dictionary<ProcessedItemSO, int>();
    IdToItem = new Dictionary<int, ProcessedItemSO>();

    for (int i = 0; i < items.Length; i++)
    {
        ItemToId.Add(items[i], i);
        IdToItem.Add(i, items[i]);
    }
}

}

hidden sleet
#

Ah, actually it unassigned the scriptable object in the editor, that's probably why

#

the fact that it does that whenever I change the script is a bit annoying I will say

burnt vapor
#

It should not unassign it as far as I know

#

Your script has an id and that's the thing Unity assigns, so for some reason it has to unassign it

#

Perhaps you have code that does this?

hidden sleet
#

Well there have been many occassions where changing a scriptable object has just unnasigned every instance of that in the inspector

twilit cliff
#

Hey, I have used the following method to play the crash sound when the bullet prefab collides with enemy prefab object that's instantiated and the volume of the sound is way too low.... I believe, since these two objects are being instantiated and not in the Scene view like a player object, the method used has reduced the volume of the crash sound, and I can barely hear on speaker, below is the line of code I used, can someone please help me do better...

AudioSource.PlayClipAtPoint(crashSound, other.transform.position);

slender nymph
#

since these two objects are being instantiated and not in the Scene view like a player object
instantiating an object puts it into the scene.
but perhaps you should pass in a higher volume as the third parameter if the default of 1 is too low

#

ah wait scratch that last bit, 1 is the highest it can be

#

so perhaps the issue is that you want to use an actual existing AudioSource component in the scene so you can adjust its 3d sound settings rather than just using the default

twilit cliff
#

I just want the sound to be loud and clear as other sound that I have attached to Player object which plays with very good volume, but for the enemy and bullet prefab, I had to use the above mentioned method since they are not in the Scene view like player and they are just being instantiated and I believe because of this reason, I can use the following method for player since it exist in the Scene view: AudioSource.PlayOneShot(crashSound, 1f);

But when I try to use the same method under Bullet Script, it isn't working since the bullet and enemy objects are instantiated only after the game starts and not in game scene...

slender nymph
#

enemy objects are instantiated only after the game starts and not in game scene
again, instantiating the objects puts them in the scene

#

you do not need to use the static PlayClipAtPoint method if you just get some reference to an existing AudioSource

empty dagger
#

Does anyone know how I'd make the sprite flip based on if it's touching a wall to the left or right of the camera? My wallslide sprite is facing to the right so it only looks right if the wall I'm touching is to the right (or front) of the camera, I need it to flip to the other side if I'm touching a wall to the left

slender nymph
#

get the normal of the surface your object is touching, then you can use Vector3.Dot to determine how close to the direction your object is facing that normal is, if it is within some threshold of the direction your object faces then you don't need to flip, otherwise flip the sprite

empty dagger
#

how do I get the normal of the wall I'm touching? I tried looking into this earlier since I needed the walljump to be opposite to the wall direction but I just couldn't figure it out at all, ended up giving me a headache

slender nymph
#

how are you determining that you are touching a wall in the first place? because however you are doing that will determine how you get the normal

empty dagger
#

thats the script for the walljump

slender nymph
#

so you are using OnCollisionStay. you can get the first point of contact from the Collision and get the normal from that

empty dagger
#

do I add something to the OnCollisionStay part then?

slender nymph
#

yes, that is the only place you can access that Collision info

#

you're also already accessing the normal for each contact point . . .

empty dagger
#

i dont really know how to apply it to other things

#

im not even sure what the first step here would be

quick ruin
#

trying to transition to FP, how do I get the bullet to rotate towards the center of the screen (bulletEnd)

wintry quarry
#

one simple way is just something like:

myCamera.transform.position + myCamera.transform.forward * distance```
#

or a cuter way: myCamera.transform.TransformPoint(Vector3.forward * distance)

dapper forge
#

Hey, I can usually drag the game window from the Unity Engine to another screen. But when I get over the edge it's back to the right. How can I drag it back to another desktop?

pallid sand
polar acorn
dapper forge
#

Thanks this worked for me

#

But is this new ?

cunning rapids
#

I don't think so

pallid sand
#

Guys i have problem with changing my game resultion the first debug showing the desird resolution but after doing screen.SetResulution nothing changed could it be relate to display mode or somthing can somone help me

#
            Screen.SetResolution(resolution.width, resolution.height, false);
            Debug.Log($"ِCurrent resolution height {Screen.currentResolution.height} and width {Screen.currentResolution.width}");```
modest dust
#

Also test it out in a build, not the Editor

covert crown
#

can anybody help me? when I write some line of code, some of the words won't highlight. should it be a problem, and if it is, what can I do to fix it?

eternal falconBOT
cunning rapids
#

For vscode you need to install the necessary dotnet sdk and install the unity extension.

covert crown
#

how do I find the preset

summer stump
covert crown
#

Oh k

#

It turns out I didn’t use Visual studio as my external script editor, do I regenerate project files?

cunning rapids
#

Yes, for good measure

cunning rapids
#

It's called an extension

summer stump
cunning rapids
#

Oh

#

Well the "preset" is in the start menu when you install vs

covert crown
#

Alright

cunning rapids
#

Just click on "Unity compatibility" or whatever its called

#

I haven't used vs in a while

summer stump
#

Are you talking about the Unity workload?

cunning rapids
#

Yes

summer stump
#

Ok, that is part of the guide

cunning rapids
#

I'm aware

summer stump
#

Preset was just confusing because neither the workload nor extension are called that.
Don't wanna make things confusing when they are already following a guide

frigid sequoia
#

Not, really code, but pretty sure my script is what is causing this... My healthbar is... dissapering from the Canvas, just after the shake effect that moves the whole UI when taking damage

cunning rapids
summer stump
cunning rapids
carmine sierra
#

How can I detect a single mouse click rather than every frame that the mouse is held down

frigid sequoia
#

But it only affects the healthbar and if I move it slighty it shows again, as if I was covered by a mask that makes it transparent there or something like that... But I don't know what is causing that...

carmine sierra
frigid sequoia
frigid sequoia
carmine sierra
cunning rapids
wintry quarry
carmine sierra
wintry quarry
carmine sierra
#

I just used fire1 and renamed it

wintry quarry
#

You have it set to key or mouse button

#

not gonna work for a joystick

carmine sierra
#

what do i set it to

wintry quarry
#

Joystick

carmine sierra
#

I just need a mouse click

wintry quarry
polar acorn
wintry quarry
carmine sierra
#

thanks anything else?

cunning rapids
wintry quarry
cunning rapids
wintry quarry
#

L is a weird name for it

carmine sierra
#

l as in left click

cunning rapids
#

An axis can be any default trigger

carmine sierra
#

yesss it works

#

thanks

cunning rapids
cunning rapids
carmine sierra
#

how would I go about rotating a prefab before it has spawned or set it's rotation before spawning

wintry quarry
carmine sierra
#

yeah

cunning rapids
#

So just modify that parameter

#

To the rotation you want

carmine sierra
#

why is it 4 numbers

#

(0, 0, 0, 1)

#

apparently thats the normal one?#

wintry quarry
#
Quaternion.Euler(x, y, z)```
carmine sierra
#

ooohhhh

wintry quarry
#

Or Quaternion.AngleAxis(angle, axis)

carmine sierra
#

and i can use that as the rotation parameter instead of quaternion.identity?

wintry quarry
#

You can use any Quaternion as the rotation parameter

cunning rapids
#

Yes

#

Quaternion.identity is the default rotation. Or just 0,0,0

#

Instantiate(Prefab, PrefabPos, Quaternion.identity);

modest quarry
#

is void Start() the first frame when loaded into a scene?

cunning rapids
#

Yes

carmine sierra
#

yeah i got it working thanks so much

cunning rapids
modest quarry
#

and void Awake() is?

burnt vapor
#

Basically the Monobehaviour's constructor

burnt vapor
#

Runs before any Start methods, useful for assigning data before running it

modest quarry
#

Ahh okay

#

Thanks

cunning rapids
#

Start is for every time the script instance is loaded

flint falcon
modest quarry
#

okay thanks

flint falcon
#

was watching this as you asked\

modest quarry
#

lol

carmine sierra
#

whats the simplest way to detect mouse hovers on ui elements

flint falcon
slender nymph
scarlet skiff
scarlet skiff
#

oh ok

cunning rapids
summer stump
carmine sierra
cunning rapids
#

Yes. My bad

cunning rapids
exotic hazel
#

Hey guys.I used for loop and sample height to spawn a stone on a terrain.I used the same way to spawn rabbits just without a for loop.But this time the stone spawned like 200 units in the air or inside the ground.I couldnt get the correct Y coordinates

cunning rapids
slender nymph
exotic hazel
burnt vapor
#

Do they spawn in the air because you used such massive numbers?

exotic hazel
exotic hazel
burnt vapor
#

I'm not sure what the problem is. Do you want them to fall down?

exotic hazel
#

for how many times the loop is to be repeated

exotic hazel
#

i mean on the ground

cunning rapids
exotic hazel
#

they are the X and Z coordinates

#

not the Y coordinates

#

The Y coordinates is to be found through this

burnt vapor
#

Try logging what Ycoords is set to

#

And perhaps check what transform.position results at, and see if these are proper coordinates you expect them to be

#

My guess is that this is not what you expect

exotic hazel
#

lemme try

#

they are gonna log Y coords 10000 times to lemme lwoer em down

cunning rapids
burnt vapor
cunning rapids
exotic hazel
#

i spawned 10 rocks 1 of them spawned at y lvl 0 and rest all of them at Y lvl 182 for some reason

exotic hazel
burnt vapor
cunning rapids
#

Ah right. My bad

exotic hazel
#

but then wont it run the code to get the Y value everytime it repeats

exotic hazel
burnt vapor
#

My guess is that they should just replace transform.position with SpawnCoords but it doesn't hurt to teach basic debugging

exotic hazel
#

oke let me try

#

i did just copy the rabbit spawner code

scarlet skiff
#

why wont they show up in the inspector?

polar acorn
#

static

cunning rapids
scarlet skiff
#

alr ty'

burnt vapor
exotic hazel
#

I put on spawncoords now it gives totally random coordinates

scarlet skiff
#

my plan is to put all the references to the player one script, then have all the spawners take it from there so i dont have to manually assign that everytime, and also maybe eventually make the spawners a prefab, so ye

swift sedge
scarlet skiff
#

would i need a singleton pattern for this?

scarlet skiff
modest dust
#

Singleton, static properties

polar acorn
#

If you can make this object a singleton, that probably means you can make all of the contained classes singletons instead. If those objects are not good candidates for singletons, neither will this one be

maiden yarrow
#

i'm making a first person game so ofc I made my cursor dissapear. but I want to add a new one that's always centered how do I do so?

#

basically what I want is a crosshair

rocky canyon
#

you just create a canvas and put an image centered

flint falcon
scarlet skiff
#

right?

polar acorn
scarlet skiff
polar acorn
humble fable
#

What is this error?

#

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

public class PipeSpawnScript : MonoBehaviour
{
public GameObject pipe;
public float spawnRate = 2;
private float tomer = 0;

// Start is called before the first frame update
void Start()
{
    spawnPipe();
}

// Update is called once per frame
void Update()
{
    if (timer < spawnRate)
    {
       timer = timer + time.deltaTime;  
    }  
    else
    {  
       spawnPipe();
       timer = 0;
    }  
}

void.spawnPipe();
{
Instantiate(pipe, transform.position, transform.rotation);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PipeSpawnScript : MonoBehaviour
{
public GameObject pipe;
public float spawnRate = 2;
private float tomer = 0;

// Start is called before the first frame update
void Start()
{
    spawnPipe();
}

// Update is called once per frame
void Update()
{
    if (timer < spawnRate)
    {
       timer = timer + time.deltaTime;  
    }  
    else
    {  
       spawnPipe();
       timer = 0;
    }  
}

void.spawnPipe();
{
Instantiate(pipe, transform.position, transform.rotation);
}
}

eternal falconBOT
slender nymph
eternal falconBOT
eternal falconBOT
polar acorn
humble fable
#

I started today

slender nymph
polar acorn
#

for how to configure your IDE

humble fable
#

What is an IDE

swift sedge
polar acorn
#

The thing you type code in

swift sedge
#

it has syntax highlighting, intellisense, project management, build tools, etc

scarlet skiff
#

idk anymore

carmine sierra
#

the documentation for all these things doesnt help me get what im meant to do with them

humble fable
#

I've done it now

polar acorn
swift sedge
humble fable
#

C#

rocky canyon
#

alot of ppl dont know the term IDE when beginning

#

to them its just a code editor

humble fable
carmine sierra
#

how can I detect a mouse hover over a button/image ui

#

cause it already detects as it highlights

swift sedge
#

before learning the unity API, you need to know C#, to learn C# you need an IDE and know what an IDE is

rocky canyon
carmine sierra
#

ohh thanks

slender nymph
carmine sierra
#

and is point enter the correct one

crimson sinew
lethal bolt
#

where do i open det animation rigging i have downloaded it?

swift sedge
#

VS Code is a text editor but has syntax highlighting and intellisense tho...

cunning rapids
humble fable
rocky canyon
humble fable
#

It's just errors

rocky canyon
#

you have to install the net SDK

carmine sierra
lethal bolt
humble fable
swift sedge
#

or look up the docs

carmine sierra
lethal bolt
cunning rapids
humble fable
polar acorn
humble fable
#

But i still don't understand

swift sedge
humble fable
#

I have

swift elbow
carmine sierra
humble fable
#

Do you have a tutorial?

slender nymph
frigid sequoia
# frigid sequoia Give me a sec, I am with something else, I will explain it better in a moment

Ok so in order: 1 is the interface in edit mode; 2 is the layout; 3 is the UI in game before getting glitched; 4: is the bar missing after taking damage and doing the shake effect; 5 is me changing the resolution to reload it and now it shows; if I take damage again is goes missing again. 6 is me moving the main layout container a bit, it makes this weird mask-like effect, it does no affect anything else in the UI aside from the healthbars

slender nymph
#

in the pinned messages . . .

dreamy urchin
#

Guys, I've been workin on it for like a week (my first game) and all drawings are made by me (I suck at drawing 😦 ), can you suggest something to add because I don't have a lot of ideas rn, maybe with some help I'll know what to do

rocky canyon
#

check ur spellings homie.. you have tomer you have timer you have spawnPipe() void void.

#

its all over the place

dreamy urchin
#

sorry

swift elbow
polar acorn
# humble fable

Take a look at your spawnPipe function. Do you notice a problem that none of the other methods have

swift elbow
#

If you make and play an animation it would be a lot easier

rocky canyon
#

Tween it

carmine sierra
#

if i am using destroy on a variable does it also destroy the variable

#

itselg

#

not just it's contents

slender nymph
#

wdym by "destroy the variable"? the Object.Destroy method just destroys a UnityEngine.Object. it does nothing at all to your variables

rocky canyon
#

pretty sure u cant destroy a variable at runtime

carmine sierra
slender nymph
#

yes that is Object.Destroy

frigid sequoia
#

This is what causes the shake, it worked before

#

I don't think I have changed anything...

scarlet skiff
#

i cant reference objects that are in the scene when it comes to singleton patterns 🫠

wintry quarry
slender nymph
frigid sequoia
wintry quarry
frigid sequoia
carmine sierra
#

just want to confirm that this is valid

#

placing is a bool

slender nymph
#

why wouldn't that be valid

carmine sierra
#

cause my script is bugging

swift elbow
wraith valley
#
GetComponent<Renderer>().material.color
#

Does that mean take a rendering component?

carmine sierra
#

ill try it

vocal marlin
#

https://paste.myst.rs/2se0wu71
can someone tell me why only the heavyAttack input actually does all the stuff in my coroutine, it's acting really weird

wraith valley
#

How do you do this?

carmine sierra
vocal marlin
wraith valley
carmine sierra
#

its called halycyon theme

wraith valley
#

Thanks

slender nymph
wraith valley
swift elbow
vocal marlin
slender nymph
cunning rapids
#

I'm pretty sure you have to shake the health bar along with the background

#

It looks like the background overlaps the bar

harsh vault
#

Idk why but when I press the A and D keys sometimes the character defaults back to the idle state but moves while in idling

tender stag
#
SetEquipment(GetEquipment(GetCurrentEquipment(cell).itemData).inventory, true);```

```private void SetEquipment(GameObject gameObject, bool active)
{
    if(gameObject != null)
    {
        gameObject.SetActive(active);
    }
}```
#

i get a NullReferenceException: Object reference not set to an instance of an object on this line if(gameObject != null)

polar acorn
tender stag
#

its on if(gameObject != null)

rich adder
polar acorn
#

That line cannot throw that error

tender stag
#

the thing is the gameObject i pass in

#

can be null

polar acorn
#

Did you make sure to save all your scripts and clear the console?

tender stag
#

wait no its this one

#

gameObject.SetActive(active);

#

sorry

rich adder
#

why is your local var named gameObject :\

tender stag
#

that was just for testing

polar acorn
# tender stag `gameObject.SetActive(active);`

Okay, that one can be null. I think it's due to Unity's weird == null override thing that's been confusing as hell for like ten years. Try if (gameObject is not null) instead. Also change the name of that variable

tender stag
#

u know the model i pass into the method

#

it can be null

#

like this SetEquipment(GetEquipment(GetCurrentEquipment(cell).itemData).clothingModel, true); returns either a null value or a game object

polar acorn
#

Right. And Unity does some fucky stuff iwth GameObjects and == null, which is why I'm suggesting you use is not null instead

polar acorn
slender nymph
slender nymph
polar acorn
tender stag
#

oh wait

#

its here

polar acorn
# tender stag

Can you share the !code of EquipmentManager (use a bin with line numbers)

eternal falconBOT
rich adder
#

yea..

slender nymph
# tender stag

yeah that makes more sense. there are several objects on that line that could be null

polar acorn
# tender stag

So, after we asked you twice what line it was on you gave us two different answers, neither of which were correct

tender stag
#

sorry about that

polar acorn
#

Why did you not just actually check instead of guessing twice

harsh vault
#

Would I need to post the code in links if its up to about 70 lines of code?

tender stag
#

can how i simplify this tho?

tender stag
polar acorn
slender nymph
# tender stag

that's not the null part though. that final item wouldn't be what throws.

polar acorn
#

Store GetCurrentEquipment(cell) in a variable. Then store the itemData in another. And so on

slender nymph
#

it is either cell, GetCurrentEquipment(cell) or GetEquipment(GetCurrentEquipment(cell).itemData that is throwing an NRE

#

also for the love of god break that up into multiple lines so you can reuse the objects and so it is more clear what exactly is throwing

tender stag
#

heres the full code

#

dont look at UnequipEquipment because i need to redo it

harsh vault
slender nymph
#

you probably need to check your transition settings in the animator

polar acorn
#

Use the input vector for everything

gleaming kraken
#

what's the difference between IsTrigger being checked and not being checked?

polar acorn
flint falcon
#

I have a movement system for 2d space ship that follows the mouse for direction. but if you stop moving the mouse and it reaches it than to sprite shakes back and forth. how can i go about stopping that

gleaming kraken
#

I see, thank you

polar acorn
rich adder
flint falcon
#

@rich adder and those videos have been a huge help im still working through them

#

i fixed the nonsense from last night since I didn't even realize those were functions you were telling me

tender stag
#

alright this works

#

thanks

harsh vault
slender nymph
# tender stag

please learn how to use local variables so you aren't calling the same exact method 3 times

polar acorn
# harsh vault Ohh ok thank you!

It looks like you can pretty cleanly set that animator parameter to horizontal.magnitude, assuming the parameter is a float and can accept decimals

stone pilot
polar acorn
# tender stag

Please for the love of Gaben store that GetEquipment result in a variable you're using it three times

rich adder
#

lord gaben

gleaming kraken
#

isn't lord gaben the creator of steam

frigid sequoia
frigid sequoia
#

I don't know how anything could be in front....

gleaming kraken
# rich adder

i am very much so confused on why you chose to send a picture of you replying to me and yet it meant you sent it as text but I wasn't pinged twice and only once for this reply, am I going insane?

rich adder
#

so I got lazy and sent the SS of it

maiden yarrow
#

I want to make something that stores an array of prefabs how do I do so?

summer stump
slender nymph
rich adder
maiden yarrow
maiden yarrow
rich adder
slender nymph
maiden yarrow
rich adder
slender nymph
polar acorn
summer stump
rich adder
#

oh oops

#

PrefabType doesn't exist ofc it wont work

flint falcon
#

im working it out now and going slow

summer stump
# maiden yarrow it won't spawn them

Use the suggested Transform[]
Or use a component that exists. Like I have a Unit[] of prefabs for my various Units that I can spawn. This means I MADE a class called Unit. Thus the type exists

maiden yarrow
flint falcon
slender nymph
cunning rapids
# rich adder

Valve created steam. Gabe newell is the founder if valve

maiden yarrow
#

I understand how an array works. but now how instantiate works😭

rich adder
summer stump
#

Instantiate WAS fine if cardSprites was a variable

slender nymph
rich adder
summer stump
#

The ONLY thing you need to do is access the array properly

maiden yarrow
summer stump
summer stump
#

Not transform

rich adder
harsh vault
summer stump
#

cardSprites[0]

harsh vault
#

Do I gotta set it?

summer stump
#

@maiden yarrow You have to access an array by its variable name, not the type of course.
Again, this is a basic c# issue with arrays.
Not related to Instantiate

https://www.w3schools.com/cs/index.php

polar acorn
#

just use the value

rich adder
harsh vault
polar acorn
#

Yeah that should be fine

harsh vault
polar acorn
cunning rapids
#

Even though they're both true

polar acorn
cunning rapids
#

Ah my bad

scarlet skiff
#

does this

#

refer to this?

swift crag
#

Camera.main looks for a game object tagged with MainCamera and tries to get a Camera from it

#

(the camera is cached, so it doesn't literally do a find-with-tag and a get-component every time you use it)

scarlet skiff
#

alright cool

#

so yes, but doesnt update

swift crag
#

are you having a problem?

swift elbow
flint falcon
#

@rich adder nope i failed back to my videos

scarlet skiff
tender stag
#

how can i refresh a canvas through script?

swift elbow
swift elbow
tender stag
#

and other canvas components

#

i need them to update

#

in a specific moment

flint falcon
#

tried creating a dead zone and turning the rb.velocity to 0

#

wait a second i need to use the magnitude I think

crimson ibex
#

Hello. I am unable to build "Mobile 3d" template on an android device. I can successfully build regular 3d templates on android. Error thrown :-

Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.20f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\build-tools\32.0.0\package.xml. Probably the SDK is read-only

I have installed adaptive performance. This is empty "Mobile 3d" template , via Unity Hub. And I can build non-mobile teplates on android (without and with adaptive performance)

swift crag
tender stag
#

i'll show u in a minute

swift crag
rich adder
#

use link

flint falcon
#

!code

eternal falconBOT
flint falcon
rocky canyon
#

<i wish more ppl would kill their embeds>

tawny hedge
#

hi, im having a bit of an issue with triggers, objects are passing through each other, everything seems to be correct in the code, but nothing in the event or script is actually triggering, this was working before i started trying out the new input system, i must've ticked, removed, or unticked something to produce this problem but can't for the life of me figure out what the issue is! 😂

swift crag
#

This will walk you through the possible causes.

tawny hedge
#

thank you, ill give it a read and go through now

rich adder
#

also thought you mentioned a sprite, if you don't want it to move instead of setting vel 0 just make bool and exclude input

tender stag
#

u see how its not getting updated?

#

i had to minimize the window

#

for it to update

swift crag
#

that sounds more like a problem with your UI layout

#

for example -- perhaps you've got ContentSizeFitters in places they do not belong

flint falcon
flint falcon
#

most likely being my fault at the time

swift crag
#

That UI on the right should be layout groups all the way down

#
  • Inventories <-- VerticalLayoutGroup
    • Inventory <-- VerticalLayoutGroup
      • Title
      • Grid <-- GridLayout
#

bah, sec

rich adder
tender stag
swift crag
tender stag
#

oh

swift crag
#

Do you mean to have one very large scroll area?

#

so that you scroll up and down to go through different kinds of inventory grids

tender stag
#

i could just have this

#

and it would work

#

but i want the categories

#

like Chest, Legs

#

etc

#

thats why i had it like this

#

with extra content size fitters

swift crag
#
  • ScrollRect <-- ScrollRect, no layout group
    • Mask <-- Mask, no layout group
      • Content <-- ContentSizeFitter, VerticalLayoutGroup
        • Head <-- VerticalLayoutGroup
        • Title <-- no layout group, just a TextMeshPro to display the word "Head"
        • Grid <-- GridLayoutGroup
          • Grid Cell <-- no layout group, just an image or whatever
swift crag
#

The default "Scroll View" preset is roughly what you need

tawny hedge
#

for some reason some boxes were unticked

swift crag
#

you just need to throw in the content size fitter and the vertical layout group on the "Content" object

#

The ContentSizeFitter reszies its own object to fit the content in its children.

#

The VerticalLayoutGroup asks its children about how much space they want, then asks for at least that much (plus more for spacing, margins, etc.)

#

It's vital that you have layout groups all the way down.

tawny hedge
swift crag
#

If each category has a ContentSizeFitter, then it will try to resize itself

tender stag
#

im so confused

swift crag
#

rather than just asking its parent for the space it needs.

tender stag
#

so remove the content size fitters?

flint falcon
swift crag
flint falcon
swift crag
#

You should read about auto-layout here

rich adder
#

which is very useful for only needing direction for example as it keeps it consistent

flint falcon
rich adder
tender stag
#

its still giving me the warning

#

on the content size fitter

#

its because of the scroll rect

#

when i disable it its gone

swift crag
#

go to GameObject -> UI -> Scroll View

#

observe how that is laid out

#

You are missing the intermediate "Viewport" object.

buoyant knot
#

in general, that menu will set up a bunch of gameobjects in a default config that should be functional

rich adder
swift crag
#

note that this is a #📲┃ui-ux problem, so we should move the question there

#

it's not a code problem

gleaming kraken
#

oh wow

flint falcon
rich adder
buoyant knot
vivid igloo
#

https://youtu.be/f6KaJHUfE2M?si=2ZpexB-kt8U3_Myr

Can anyone halp me download the package in this video?

Learn how to optimize the performance of your game by automatically combining meshes, significantly reducing draw calls using the free HLOD tool from Unity. Hierarchical Level of Detail is a great tool to boost the FPS of your game, especially when you have large view distances with complex geometry!

💸 Ongoing sales 💸
⚫ Check out the latest Hum...

▶ Play video
flint falcon
#

Now I understand! My test screen was so small I couldn't see it but that makes perfect sense now

buoyant knot
#

if your displacement vector is 5 meters right, then the normalized vector is (1,0) dimensionless

rich adder
#

just link to the spot or just screenshot it

vivid igloo
buoyant knot
rich adder
vivid igloo
rich adder
flint falcon
buoyant knot
#

and the program doesn’t understand units, only numbers. so you need to keep track of units

rich adder
vivid igloo
flint falcon
#

Hahaha yeah probably

#

I'm going to figure it out

rich adder
flint falcon
#

@rich adder give me a hint

vivid igloo
#

And thats it

buoyant knot
#

yeah, so if your canvas is rescaled based on 720 p, and your screen is 1080p, then a distance of 10 unscaled pixels on your canvas (canvas space) is 10 * 1080/720 pixels in screen space. Canvas has a method to give the current ratio.

rich adder
#

or just download the repo

vivid igloo
rich adder
spiral narwhal
#

There's literally an entire how to download section in the repo readme 😭

rocky canyon
#

download the zip

#

pull the folders into ur project.. (check documentation) to set up anything thats missing

#

or else learn github and just clone it

#

ah, yea may be best to just clone it.. readme says theres submodules needed for a fully working project

formal raptor
#

for smart strings in localization, how to set a number to appear unsigned?

spiral narwhal
#

Make it smart and then format it to be Math.Abs

formal raptor
#

I am using the signal to decide if the number will jump to left or right

#

I will try this

spiral narwhal
ionic zephyr
#

Hi guys I am having trouble with my ability system, I dont really know how to face it, the thing is I want each of my characters to have different habilities (take pokemon attacks as an example), How could I program that, any ideas? Ive been stuck with this almost for a week please help

rich adder
#

an ability system isn't trivial

#

look into scriptable objects as well

modest dust
ionic zephyr
ionic zephyr
flint falcon
#

Ahhhh

ionic zephyr
modest dust
#

But generally there are a lot of resources online

#

Which you can learn from

ionic zephyr
ionic zephyr
#

and If it is possible you can help me

modest dust
ionic zephyr
#

Okay, thanks, let me tell you

#

I have an "ActivateAbility" interface with which I´ll describe the effect of each hability in separate scripts with classes that describe these abilities. Example: class Fireball:IEffects {ActivateAbility(){//ability behaviour}

ionic zephyr
#

the goal is to create a system in which every character has access to 3 unique habilities which are managed by a boostManager I already created

swift crag
#

Ability systems are complicated because you need a consistent way to interact with many different kinds of abilities

#

Think about a MOBA, like Dota 2

#

There are self-targeting spells, unit-targeted spells, point-targeted spells, and vector-targeted spells

#

personally, I dealt with this by just making one kind of "spell" that listed the ways you were allowed to use it

#

and one kind of "Spell Target" class that covered all of the bases

#

it'd just throw a runtime error if you did it wrong

#

e.g. if I tried to cast a unit-targeted spell with a SpellTarget that didn't actually have a unit in it

#

I'm going through something similar again in my current game (a survival horror game, not an RTS)

#

each "thing" in the game is an Entity with Modules attached to it

#

and Modules give you a list of Activities they let you carry out

silk night
#

Hey, im trying to generate a class on the fly by a codegenerator, this is my template:

        public static readonly string ComponentEnum = @"using UnityEngine;
    public enum Component : int 
    {
        Test,
{0}
    }
";

Now i try to do string.Format on it but it seems it sees the template as malformatted because it has curly braces, any way to solve that?

swift crag
#

most of the Activities just tell the Entity's state machine to enter a state provided by the module, like "Try to go into the 'Open Door' state"

#

At some point I'm going to start adding abilities that aren't just "press F to pay respects", and I'm not really sure how i'm going to handle things like area-of-effect targeting!

#

It's difficult stuff.

#

the Modules are given references to whatever other Modules they need to carry out the ability

#

so a module for picking up an item holds a reference to an IK module

#

(inverse kinematics, for reaching out and touching a target)

#

I've been trying to get as much as possible out of my Entity class

ionic zephyr
spiral narwhal
ionic zephyr
silk night
ionic zephyr
spiral narwhal
#

Let me know if that works, I'd be interested. Haven't used format in a while :)

silk night
#

Oh yeah, {{ worked

spiral narwhal
#

Cool!

silk night
#

Thanks

rough valley
#

Can I ask here for help?

pallid sand
#

some one know how to make grid cell size changed based on resolution ?

slender nymph
#

why would you need to change the size of your grid based on resolution?

#

what you probably want to do instead is actually just change the orthographic size of the camera so it always sees the same amount of content no matter the resolution

pallid sand
modest dust
# ionic zephyr Ive thought of making one script for each ability but I dont know how to assign ...

My brain isn't working at full speed today, but here's how you could possibly do it:
Ability - ScriptableObject with an EffectWrapper[] array, could be maybe unwrapped into a [SerializeReference] IEffect[] but not necessary
IEffect - interface with an Apply(ICaller caller) method
ICaller - interface with any kind of properties and methods you'd need when making different effects implementing the IEffect interface
EffectType - enum, used to select the kind of effect the ability has (could be for example Projectile, Kick, Punch, etc)
EffectWrapper - a wrapper for [SerializeReference] IEffect, with an additional field of EffectType used in OnValidate() or (preferably?) ISerializationCallbackReceiver to instantiate a correct type of effect into your IEffect field

Then just make an Ability[] array for your characters - or a special class/struct with a fixed amount of Abilities if every character has the same amount of these - and assign your Ability SOs into these fields.

I don't know if it's the prettiest way there is, but it should work and be flexible enough to introduce a variety of different abilities. Analyze it and decide if it works for you or not

silk night
swift crag
#

one option is to just completely commit to everything being an "ability"

#

although, that doesn't really work if you don't have any experience yet

#

but it's what I've gone for multiple times in the past

#

Almost everything in an RTS I was prototyping was an ability

#

building a house, mining a resource, attacking an enemy, using a spell

prime relic
#

I need help with an issue, hopefully an easy one, can someone help please?

silk night
slender nymph
prime relic
#

I added crouching for my character using the Unity Input Action System. I created an OnCrouch method to manage the input actions and an IsCeilingDetected method to detect ceilings and keep the character crouched when one is detected. everything seemed to work fine: pressing the crouch button made the character crouch, and it stayed crouched when under a ceiling. However, I encountered an issue: when I moved away from under the ceiling with the crouch button released, the character remained crouched until I tapped the crouch button once (The Crouch button is hold not toggle). So the character becomes stuck in the crouched state if the collider detects a ceiling, and it wouldn't stand back up automatically when leaving from under the ceiling with the crouch button released until I tap the crouch button once. I can't seem to figure it out no matter how much I squeeze my brain.

Here's the code: https://hastebin.com/share/mucowunipu.csharp

ionic zephyr
slender nymph
rough valley
polar acorn
prime relic
swift crag
#

you just need to do that every frame, not only the instant that you let go of crouch

ionic zephyr
rough valley
swift crag
#

you can set a bool to indicate if the player is trying to crouch or not

polar acorn
slender nymph
rough valley
#

Learn how to make a 2D tower defence game using Unity. Welcome to part 2 of our 2D tower defence tutorial, in this video we focus on adding an Enemy AI and Enemy Pathfinding to our game using Unity!

Next Video: https://youtu.be/5j8A79-YUo0
Previous Video: https://youtu.be/WH8b2ihk_YA
Playlist: https://www.youtube.com/playlist?list=PLfX6C2dxVyLz...

▶ Play video
slender nymph
#

timestamp 8:30

modest dust
polar acorn
formal raptor
#

that makes the number into one digit minimum, so it never adds more digits or sign

ionic zephyr
modest dust
cloud spire
#

hi, inspector likes to select all list bluse when i try to change 1 value.
is it a some problem?
i just made poblic nonReordable list a i dunno what's wrong with it

rocky canyon
prime relic
swift crag
#

no, because OnCrouch is supposed to be called when you press or release the button

modest dust
# ionic zephyr sorry, I still dont get it

ICaller can have a ShootProjectile(int amount) method, which could be invoked from within an effect such as

class ProjectileEffect : IEffect
{
  [SerializeField] int m_amount; // Just an example  

  public void Apply(ICaller caller)
  {
    caller.ShootProjectile(m_amount);
  }
}```
#

How ShootProjectile is implemented is up to the character

#

Could be a single projectile or a few from each hand

swift crag
#

Move the logic that checks for an obstruction out of OnCrouch. Make OnCrouch just set a bool that tells you if the player wants to crouch.

#

Check if you can actually do what the player wants in Update.

indigo wagon
#

anyone feel like guiding me on where to look at how to create a grid for A* pathfinding using code?

prime relic
wraith valley
#
public class NewBehaviourScript : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.E)) GetComponent<Renderer>().material.color = Color.black;
        if (Input.GetKeyDown(KeyCode.Space)) GetComponent<Renderer>().material.color = Color.white;
        if (Input.GetKeyDown(KeyCode.Tab)) GetComponent<Renderer>().material.color = Color.green; Debug.Log(transform.position);

        if (transform.position.y < 5) Debug.Log(transform.position);
       
        if (Input.GetKeyDown(KeyCode.O)) transform.position.y = 5;
      
    }
}
#

Help please

#

Doesn`t work

polar acorn
wraith valley
wintry quarry
#

that's not valid C#

#

Is your IDE configured?

polar acorn
# wraith valley

You cannot both get and set an individual component of a vector. You need to either set the entire position at once, or store it in a variable, modify it, and put it back

wraith valley
rough valley
polar acorn
wraith valley
#

1 minute

fair steeple
#

Hey, I'm trying to learn the new input system and can't get it working, I set up the controls on the manager, set up the component and wrote the function OnDown but it's not printing anything

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

public class LocomotionState: State
{
    public PlayerStateManager stateManager;
    bool started = false;
    ControlsGame controlsGame;
    private void Start()
    {
        controlsGame = new ControlsGame();
    }
    public override State RunCurrentState()
    {
        if (!started) StartState();
        UpdateState();
        return this;
    }
    void StartState()
    {
        started = true;
    }
    void UpdateState()
    {
        stateManager.commonStateLogic.MoveWithInput();
    }
    void OnDown()
    {
        print("OnDown");
    }
}

wraith valley
wintry quarry
wintry quarry
#

you changed nothing

rocky canyon
#

u cant set a single property of transform

polar acorn
# wraith valley

You cannot both get and set an individual component of a vector. You need to either set the entire position at once, or store it in a variable, modify it, and put it back

rocky canyon
#

that means .x, .y, or ,z

flint falcon
polar acorn
wintry quarry
wintry quarry