#💻┃code-beginner

1 messages · Page 411 of 1

hasty sleet
#

Efficient in what manner? In terms of making it easier/faster to create lots of these scenes?

eager spindle
#

yep, I dunno if its gonna be a lot of load rendering those 3 scenes

#

maybe its some AAA magic but idk how it runs so efficiently while having stuff like that

hasty sleet
#

When I say "Scene", I actually mean it in a cinematography sense; you don't actually need a whole separate Unity scene to do this. I don't think it would be very taxing performance-wise if the rest of the scene is relatively quiet.

#

In terms of development speed, you can attach cameras to each of these characters as prefabs and it would expedite the setup process.

#

You can also consider controlling the UI canvas through code and having a prefab for the tri-split or dual-split cutscene view to efficiently switch between gameplay and different cutscenes. This might help keep it modular.

#

And as always, it's best to avoid premature optimization. Try an initial approach before considering whether you should take steps to further optimize it. It might be unnecessary

native hill
#

oh my god Quaternion.Euler is being a giant ass to me

#

i cant get how to use it correctly

#

its confusing

#

i just tried making something quick with it, that helped a bit

languid spire
#

what is confusing?

native hill
#

im not even sure

#

i want to figure out how to use it correctly and when i would need it

languid spire
#

You would need it when you want to apply a rotation using Euler angles, you know what Euler angles are, right

native hill
#

its x y and z right?

languid spire
#

kinda. you know a circle has 360 degrees, those degrees are Euler angles

native hill
#

oh okay

#

sorry for the late responses

#

i found out about Quaternion.Euler when i was looking at camera movement scripts

#

ive been trying to understand why it was used and stuff

languid spire
#

so, imagine you have a line going from your head to your feet, that is the Y axis. If I want a rotation that just turns around I can make a Quaternion

Quaternion q = Quaternion.Euler(0,180,0);
transform.rotation = q;
native hill
#

oh okay

#

yeah that makes more sense, ill try using it and see if i could see how it was used

eternal needle
native hill
#

yeah I’m realizing now why it was used in camera movement

#

thank u for helping me

weak talon
#

hello, i am making fps shooter and my camera is jittery

the player is a parent to the camera and when i move the camera (like rotation) it is fine but only when i start moving and rotating the camera the camera movement is very jittery

the rigidbody is interpolate, movement is in fixedUpdate as it is rigidbody movement, and cameramovement is in lateupdate
please help (tell me if you need to see any code)

wanton otter
#

restart scene button works only once after applying dontdestroyonload()

any ideas why that is?

ivory bobcat
void raptor
#

I have a button with event system and is interactable but i doesnt work, the button should activate the inventory gameobject

#

Can someone help me with this bug?

eager spindle
scarlet hull
eager spindle
#

check if theres any UI elements overlaying it

scarlet hull
#

i lost some stuff with github anyone knows how to revert

#

with gituhb desktop

eager spindle
# scarlet hull

you want to delete changes? theres a point where you just re-clone the repo

#

never seen that error

scarlet hull
#

my scene got deleted in unity

#

and i want to revert back to an older commit

wanton otter
void raptor
languid spire
scarlet hull
#

where do i click

#

i creted a new branch how to stash

languid spire
#

if you created a new branch why are you still in main?

scarlet hull
#

i tried getting there but it gives me an error

acoustic echo
#

Push changes and move to new branch

scarlet hull
#

pushed but nothing changed

broken cargo
# scarlet hull

It has merge conflicts. You should resolve them or discard

acoustic echo
#

Copy the scene file, remove it (in repo), make a commit and push it, place scene back and commit and push again

broken cargo
scarlet hull
#

when making a commit do i commit nothing?

broken cargo
# scarlet hull

Discard the changes, and go through latest commits and find the last one that works. Copy the scene file from there and commit it to the master. You will probably lose some changes but it is the easiest way

acoustic echo
#

You should commit file removal from repo and paste again the scene file, that usually fixes stuff for me

#

I don't know how but it does

broken cargo
# scarlet hull none work

if every commit has a corrupted scene file there is no way to restore it. Check if you can resolve the merge conflict manually (rarely works for me) or just delete the scene file and recreate it from scratch

full kite
#

Hello guys! I have this script and all I want is for my gameobject to take my sprite that I putted in the Inspect using SpriteRenderer. Im using the same exact script above and its working but now it seems like it doesnt. Did I make a mistake or anything?


   
   private void Create (int level)
   {
       GameObject myGameObject = new GameObject("Lvl" + level);
       SpriteRenderer renderer2 = myGameObject.AddComponent<SpriteRenderer>();
           
       renderer2.sprite = CamilaLvl2;```
#

On The Sprite Renderer, the Sprite doesnt take the image

strong hemlock
#

I'm using Visual Studio Code and I don't get suggestions when I type something (Here I'm typing time.deltaTime), is there a way to activate it?

eternal falconBOT
strong hemlock
cosmic dagger
#

If it was working before, check that you don't have any errors . . .

full kite
#

Like the Sprite thing is empty

frank zodiac
#
transform.Translate(new Vector2(0.0f, InputManager.GetInstance().GetMove1Value() * ySpeed));
transform.position = new Vector2(transform.position.x, Mathf.Clamp(transform.position.y, -250f, 250f));

trying to clamp my y movement but it wont work. it just snaps to -250 for some reason

broken cargo
broken cargo
frank zodiac
broken cargo
broken cargo
#

So check with Debug.Log or with debugger what are the actual values in the code

lavish jolt
#

How can I make field serialize like on image in other script.
This doesn't work:

[SerializeField] Action action;
broken cargo
lavish jolt
weak talon
#

hello, i am making fps shooter and my camera is jittery

the player is a parent to the camera and when i move the camera (like rotation) it is fine but only when i start moving and rotating the camera the camera movement is very jittery

the rigidbody is interpolate, movement is in fixedUpdate as it is rigidbody movement, and cameramovement is in lateupdate
please help (tell me if you need to see any code)

broken cargo
teal viper
#

You should only be moving and rotating your character via the rb methods and properties, like velocity, forces and torque

idle ginkgo
#

how can i log the time on console

#

to keep track of how long it took to jump

#

i want to sync it with animation

teal viper
idle ginkgo
#

oh ok thanks

weak talon
weak talon
full kite
#
public Sprite CamilaLvl2;    
private void Create (int level)
    {
        GameObject myGameObject = new GameObject("Lvl" + level);
        SpriteRenderer renderer = myGameObject.AddComponent<SpriteRenderer>();
        renderer.sprite = CamilaLvl2;
    } ``` Does anyone know why in the runmode, sprite in the SpriteRenderer of the GameObject  isnt assigning with the Sprite "CamilaLvl2"?
broken cargo
full kite
weak talon
full kite
#

it is assigned to a Sprite

broken cargo
broken cargo
weak talon
full kite
#

in the runtime, Sprite Field is null

teal viper
full kite
#

in the code, I assigned the Sprite Field with an Image but it doesnt match

broken cargo
full kite
full kite
broken cargo
# full kite

Can you check if the CamilaLvl2 is null in the runtime? Not the sprite in SpriteRenderer

broken cargo
#

With debugger. Or just how you check the sprite field in the inspector

weak talon
#

this is the hierachy of the player
the camera is in the caamholder

and the player rigidsbody and capsule collider in inspector

broken cargo
full kite
#

while runtime

#

on canvas

#

like on the script while running

broken cargo
# full kite

Try to verify with debugger. If the sprite is not null SpriteRenderer should get it. Unless you have two components and look at the wrong one

full kite
#

Im trying rn to call the function that does this thing in the Start function to see if its a problem with the function itself

#

But the code gets right everything, like adds all the other script and marks all the things except this thing

#

And im not quite sure why cause i did this thing earlier in this program and it worked

broken cargo
#

Try it on the empty scene

full kite
#

It worked

#

But only

#

when i assign it in start

#

not when I need

#

I cant destroy a gameobject and then add another one?

broken cargo
full kite
broken cargo
broken cargo
full kite
#

Testing, it doesnt have anything to do with the destroy function

#

Like even if its not destroying those 2 its not working

teal viper
#

And the camera just in case

full kite
#

Would you want from me to share the code that I call this function?

#

Or make a mp4 and show it to you?

atomic holly
#

Hello,
When I create a SO with this script, the object creates correctly but Unity send me this error :
No script asset for Weapon. Check that the definition is in a file of the same name and that it compiles properly.
What I do wrong ?


using UnityEngine;

[CreateAssetMenu(fileName = "New Item", menuName = "Inventory/Item")]
public class Item : ScriptableObject
{
    public int id;
    public string itemName;
    public string description;
    public Sprite itemImage;
}
[CreateAssetMenu(fileName = "New Weapon", menuName = "Inventory/Item/Weapon")]
public class Weapon : Item
{
    public int damage;
    public int reach;
    public int cadence;
}
[CreateAssetMenu(fileName = "New Armor", menuName = "Inventory/Item/Armor")]
public class Armor : Item
{
    public int armor;
}
teal viper
# weak talon

Is the code from the second screenshot on the character?

weak talon
#

YA

#

sorry

#

yeah it is

teal viper
#

Well, what did I say about rotating the character only via the rb?

broken cargo
broken cargo
weak talon
teal viper
#

You can use MoveRotation.

solar arrow
#

is multipy by delta time needed in fixedUpdate function?

full kite
# broken cargo You can show your code
public Sprite CamilaLvl2;
    
    private void Create (int level)
    {
        GameObject myGameObject = new GameObject("Lvl" + level);
        SpriteRenderer renderer = myGameObject.AddComponent<SpriteRenderer>();
        renderer.sprite = CamilaLvl2;
        bc2d = myGameObject.AddComponent<BoxCollider2D>();
        rb2d = myGameObject.AddComponent<Rigidbody2D>();

        rb2d.gravityScale = 0;
        bc2d.isTrigger = true;
    }
    
    private void OnTriggerStay2D (Collider2D collision)
    {
        string thisGameobjectName;
        string collisionGameobjectName;

        thisGameobjectName = gameObject.name;
        collisionGameobjectName = collision.gameObject.name;

        if (mouseButtonReleased && thisGameobjectName == "Lvl1" && collisionGameobjectName == "Lvl1")
        {
            mouseButtonReleased = false;
            Destroy(gameObject);
            Destroy(collision.gameObject);
            Create(2);
        }
    }```
#

CamilaLvl2 is assigned

broken cargo
weak talon
solar arrow
broken cargo
full kite
broken cargo
swift crag
# solar arrow depends on what?

If you have a value that represents a change over time, and you're using it to change a value, you must multiply by Time.deltaTime

#

Velocity times time equals distance.

#

FixedUpdate runs 50 times per second, rather than a variable number of times per second

full kite
swift crag
#

But the principle is unchanged: you must convert a "per second" value into an absolute value.

#

Also, in FixedUpdate, Time.deltaTime gives you the same value as Time.fixedDeltaTime, so you can just use the former

swift crag
#

You need to have a working IDE first

#

Visual Studio, VSCode, and Rider all work here

#

You know your IDE (integerated development environment) is working if it's highlighting errors and suggesting autocompletions

full kite
#

Does Debugger work on the Android Platform?

broken cargo
full kite
#

and after play what should I press?

broken cargo
broken cargo
full kite
#

Ok so first one is to put VSC up on the External Tools

wooden minnow
#

if i add a gameobject to a list of gameobjects would the list direct to the original object or create a copy of it?

List<GameObject> drones = new List<GameObject>();
GameObject parent = GameObject.Find("drones");

for (int i = 0; i < parent.transform.childCount; i++)
{
    GameObject child = parent.transform.GetChild(i);
    drones.Add(child);
}```
broken cargo
full kite
wooden minnow
swift crag
#

there are two big kinds of types:

  • value types: you hold the data directly, and you copy it to give it to someone else
  • reference types: you hold a pointer to the data, and you copy the pointer to give it to someone else
full kite
#

First one is this thing : Specify the External Script Editor in Unity

#

Then : Debug in the Unity Editor

broken cargo
full kite
#

Im using VSC

#

so yeah im using it

#

and im trying to mentain the exact same steps but im still clueless about the other steps

#

So I should Debug in VSC

broken cargo
full kite
#

I have to write everything manually

#

so that means my debugger isnt setted up

broken cargo
broken cargo
full kite
#

I installed the Unity extension for VSC

icy shadow
#

Hi. I made a movement system that I want to experiment with in another project, what's the best practice way of making and managing my own library/package in Unity?
Like a Git submodule maybe??

foggy saffron
#

Ayo o/ I need to talk this out because I'm over looking something simple.. I have two colliders meeting (crate & scoreCounter) and both are marked " Is Trigger" One collider is static and has a script to increase a score when a collider marked with the (crate) tag interacts as a trigger.

The void Start works but nothing after does

https://paste.mod.gg/crirsxvcccov/0

wintry quarry
full kite
#

so basically @broken cargo,I installed Unity extension

#

And right now, Im more clueless about the following step

broken cargo
full kite
#

And now I can add breakpoints and stuff

#

Where is that Debug button?

broken cargo
foggy saffron
full kite
#

and NET5 doesnt work

#

Like nothing pops up

swift crag
broken cargo
# full kite

You still haven't finished the setup. Follow the instructions further

swift crag
#

er, !vsc

#

😭

#

!ide

eternal falconBOT
swift crag
#

the "VS Code" instructions there walk you through everything you need to do

full kite
# eternal falcon

and after following these I should be able to press the Debug thing thta is above the extensions, and then see something that is related to UNity above

#

Right? @broken cargo

broken cargo
full kite
#

I cant see anything that is related with it

#

with the Debug

#

When Ill reach that state, can I still contact you further?

#

With the debug thing that pops up?

foggy saffron
#

so I can assign a TextMeshProUGUI to a gameobject in the Hierarchy but I can't use the same thing on a prefab in the Project window?

swift crag
#

some corrections..

#

you can't assign a reference to a "gameobject"

#

you're dragging a reference into a field of a component in the inspector

#

it is true that the component is attached to a game object, though

swift crag
#

Therefore, assets can't reference scene objects.

foggy saffron
#

hmm Im using cratescorewall gameobject with a big collider wall to detect passing instantiated gameobjects with collider boxes and a tag (crate) to raise a score. The script to detect this is on the cratescorewall gameobject

but the other colliders are a player projectile and moving crates.. all of which are instantiated. So nothing is in the scene until spawned or triggered.

stuck palm
#

Can you write code within the game and have it execute?

verbal dome
#

You would need some kind of in-game scripting language

#

From what I've seen, many games use LUA

#

Or if you just want simple commands then you can make your own console that you type into and parse strings which execute pre-defined code

swift crag
#

Lua is popular because it can be embedded into your game

#

it's totally separate from your game code

verbal dome
#

I'm going to need something for my dialogue/sequence system

#

Already started making my own tokenizer+parser but I kind of died inside

swift crag
#

time to learn about context-free grammars

#

(:

verbal dome
#

I'll look into that 👍

swift crag
#

Note that you can almost certainly avoid writing a parser yourself

#

Quite a few useful grammars are context-free

#

I believe C# is context-free

#

(you've activated an unskippable cutscene; i had to learn this well enough to explain it to undergraduates)

#

Depending on what you're trying to do, you might even be able to get away with a regular grammar

#

which you'd parse with...a regular expression! ✨

bitter stone
#

Heyo, im asking for help regarding character rotation with the new input system.
I´ve made a character controller, and can use WASD without any problems. When i try to run it with the code for rotation however, everything breaks. Im still able to move forward without any problem, but once i move right, left, or backwards the character glitches around. My current code is down below along with a video showcasing the issue. Thanks in advance!
(For context, I want to rotate the player in the direction it is currently moving)

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

public class Mover : MonoBehaviour
{
    [SerializeField]
    private float MoveSpeed = 3f;

    [SerializeField]
    private int playerIndex = 0;

    private CharacterController controller;

    private Vector3 moveDirection = Vector3.zero;
    private Vector2 inputVector = Vector2.zero;

    private void Awake()
    {
        controller = GetComponent<CharacterController>();
    }

    public int GetPlayerIndex()
    {
        return playerIndex;
    }

    internal Mover FirstOrDefault(Func<object, bool> value)
    {
        throw new NotImplementedException();
    }

    public void SetInputVector(Vector2 direction)
    {
        inputVector = direction;       
    }

    void Update()
    {
        moveDirection = new Vector3(inputVector.x, 0, inputVector.y);
        moveDirection = transform.TransformDirection(moveDirection);
        moveDirection *= MoveSpeed;

        controller.Move(moveDirection * Time.deltaTime);

        if(moveDirection != Vector3.zero)
        {
            transform.forward = moveDirection;
        }
    }
}
ripe shard
swift crag
umbral rock
#

why does this not work?

int Number = 6

string StringNumber = (string) Number? he says i cant convert it? but i can convert a double to int?

swift crag
languid spire
#

Number.ToString()

umbral rock
#

why do u need to do that and not with double to int?

swift crag
languid spire
#

because a string is not a numeric type

umbral rock
#

hmmm okay, got it

ripe shard
swift crag
ripe shard
#

But it would be so nice to be able to maintain a nice dsl… question is just: how?

swift crag
#

A tangent: I made a binary format to export vertex attributes from Blender to Unity

#

I wound up using Kaitai Struct to define the binary format and debug it

#

I didn't use it to generate a parser, though.

#

But it was very useful to codify the format in one place and to be able to check that the files I was producing were valid

ripe shard
#

Interesting

#

Maybe solving the maintenance problem must be part of the design

#

it’s probably more doable for data exchange formats and markup than for stuff that describes procedures

swift crag
#

yeah, it's easy when all of your files are being machine-generated

#

making changes to the format doesn't require any manual labor beyond re-exporting

ripe shard
#

indeed, and that’s the only situation where I’ve ever made custom formats.

#

making something for humans is no fun 🤩

#

they get annoyed when you change stuff 🤦‍♂️

swift crag
#

as I continue to make major changes to how systems work, I can only imagine how much worse the process would be if other people depended on my game code

prime horizon
#

Guys, I need help. I'm learning to use the 2D Tilemap, and I get this bug. The IsGrounded funtion returns True when my character is on the ground, as expected. But the Y velocity when my character moves to the right stays higher than 0, which make Unity think my character is Jumping, while the IsGrounded is still true. The animation then flicks between running and jump animation. This only happens when my character run on the tilemap, not on other game objects.
This is the code if you want to know https://gdl.space/zaximetini.cs

wanton kraken
#

anyone know what the issue is with my code on my bullet prefab? just trying to draw a super simple raycast and then visualize it, but nothing is happening.

    void FixedUpdate()
    {
        RaycastHit2D ray = Physics2D.Raycast(transform.position, transform.up, MaxDistance, LayerMask.GetMask("Scene"));
        Debug.DrawRay(transform.position, transform.up * MaxDistance, Color.green);

        if(ray.collider != null){
            print("Object Hit at " + ray.collider.name+ "!");
        } else {
            print("Collider hit nothing :C)");
        }

    }
swift crag
#

so nothing is being logged at all?

wanton kraken
#

it keeps saying nothing is being hit, and no raycast debug is being drawn

swift crag
#

perhaps MaxDistance is zero

wanton kraken
#

nope, set it to 100

swift crag
#

is it actually set to 100 on your prefab, though?

#

a field initializer that sets the field to 100 won't matter if the prefab has that field set to 0

wanton kraken
#

yes, it is

#
MaxDistance = 100f;
swift crag
#

If MaxDistance is a serialized field, then that doesn't mean it's 100 on your prefab. Go look at it in the inspector.

wanton kraken
#

i did, and i set it to 100 there as well

#

hence my confusion!

swift crag
#

Is transform.up pointing into the screen, perhaps?

#

that would mean your object is rotated by 90 degree on the X or Y axes

wanton kraken
#

i'm not sure, should i try changing it to transform.forward?

swift crag
#

Select an instance of the bullet prefab in play mode and look at the handles.

#

Make sure you're set to pivot + local

#

The blue arrow should be pointing into the screen. The red and green arrows should be parallel to the screen.

wanton kraken
#

oh, i just had the gizmo off i think. looks like i'm slow

swift crag
#

press W to get the move handles

wanton kraken
#

yep, i'm seeing them

#

being a unity noob has it's drawbacks. now i need to make the bullets follow the raycast

swift crag
#

Show me a screenshot of the bullet.

wanton kraken
#

the bullet in the inspector? in game?

swift crag
#

both the inspector and the scene view

#

the entire editor window, really

wanton kraken
swift crag
#

you've collapsed the Transform part, which is very important

wanton kraken
#

my mistake, one moment

swift crag
#

and I'm looking for an actual instance of the bullet while the game is playing

wanton kraken
#

everything is set to 0 other then scale, which is .25 on all axis

#

ah ok

swift crag
#

since you could be changing its rotation when you instantiate it

wanton kraken
#

sure

swift crag
#

shoot a bullet, pause the game, select the bullet, and then screenshot the entire window

wanton kraken
#

seems alright to me

swift crag
#

the entire editor window

wanton kraken
#

mkay

swift crag
#

with the bullet selected, with the "move" tool selected (press W)

wanton kraken
#

like i said, it's alright

#

don't mind the placeholder graphics

swift crag
#

Okay, the handles are pointing in reasonable directions

#

You have gizmos off, so you're not going to see the DrawRay lines

wanton kraken
#

they're back on now, my mistake

swift crag
#

Do the lines appear now?

wanton kraken
#

yep, like i said before

#

all good!

swift crag
wanton kraken
#

now i need to code the bullets to follow the raycast, as well as destroy and trigger on any collision

swift crag
#

I didn't realize you'd started seeing the DrawRay lines there

wanton kraken
#

yep, i just didn't realize i needed to turn them on. thanks for the help, friend! i'll probably need more sooner rather then later

rich adder
wanton kraken
#

sir yes sir, implementing it now

#

it doesn't like ray.directionRayCastHit2D does not contain a definition for it

swift crag
#

that's a Ray, not RaycastHit2D

#

but yes, your ray is a RaycastHit2D

#

(you should name it hit)

#

Your code doesn't create a Ray, so just use transform.up

frank zodiac
#

what?

wanton kraken
#

ah, i see, thank you

swift crag
wintry quarry
frank zodiac
#

it was working before

#

then now it gives me an error

wintry quarry
frank zodiac
frank zodiac
wanton kraken
#

thank you for your help, friends. now begins the difficult part. from where the raycast collides with the scene, i'm going to need it to create a new raycast for the bullet to follow afterwards- this is because a core mechanic of my game is bouncing bullets off walls. i figure i'll need some mathf trigonometry sort of code, any suggestions?

swift crag
#

nah

#

Vector2.Reflect

#

you give it an incoming vector and a normal vector (you get the latter from the RaycastHit2D)

wanton kraken
#

oh, word? that'll save me some time

#

i'll do some looking into on that

swift crag
#

you should have a look at the static methods of Vector2/Vector3 and Quaternion

wanton kraken
#

on it!

lethal bolt
#

Why dosent the character stand up 750 for the hips and 200 for the rest?

#

It does what its suppose to do but not standing up

swift crag
#

why should it stand up at all?

#

does it work with larger force values?

lethal bolt
#

No ig i just forgot to lock rotation on the hips?

swift crag
#

i have no idea what your ragdoll looks like or what you're doing

#

so it's kind of hard to tell you anything

lethal bolt
#

I have made an active ragdoll

wanton kraken
#

why does this not work? i'm a bit confused on how i can calculate the reflection when i can't get the direction of the bullet (rhymes!)

Vector2 reflectionDirection = Vector2.Reflect(hit.direction, hit.normal);
swift crag
#

You already know the direction of the bullet

#

You used it to do the raycast

swift crag
wanton kraken
#

yeah, i changed it to 'hit' to be more clear

swift crag
#

RaycastHit2D does not have a direction field becaus that would be redundant

wanton kraken
#

yeah, i suppose that makes sense

#

i'm just confused as to what i would put in the first part of Vector2.Reflect

swift crag
#

the direction the bullet is going

#

again, you already know what it is

#

you used it for the raycast, didn't you?

wanton kraken
#

i used transform.position, and transform.up

rich adder
#

you're basically typing it 3 times now

wanton kraken
#

right, i'm trying to. just not sure how exactly to update said variable with the direction of the bullet

#

i can't use transform.rotation or something

rich adder
#

wdym just use the drection of your raycast but Im saying make it a variable

swift crag
#

Literally just use transform.up

#

That's the direction you fired the raycast in

rich adder
#

raycast, drawray and now bullet have typed 3 transform.up you are accessing up property 3 times

swift crag
#

I don't understand what the problem is

wanton kraken
#

oh, i was misunderstanding something

swift crag
#

transform.up is a Vector3; it'll get implicitly converted to a Vector2 when you pass it into Vector2.Reflect

wanton kraken
#

i get it now. my mistake

wanton kraken
rich adder
wanton kraken
#

i see, that's definitely cleaner then mine

rich adder
# wanton kraken i see, that's definitely cleaner then mine

all I'm doing is storing the direction so you don't have to access the same thing 2-3 times. What's more important though is you only have to "track it" in one point, obviously its no big deal with transform.up but its good habit to not repeat code, try to cache(store) stuff

wanton kraken
#

yep, i've implemented that into my code as well. right now i'm trying to figure out how to do the bounce

#

something like this on collision?

            Vector2 reflectionDirection = Vector2.Reflect(direction, hit.normal);
            direction = reflectionDirection;
            transform.Translate(direction * Time.deltaTime * BulletSpeed);
rich adder
wanton kraken
#

just a simple private void OnCollisionEnter2D(Collision2D collision)

rich adder
#

is the bullet rigidbody ? don't use translation

wanton kraken
#

it is rigidbody, good point

rich adder
#

stick with velocity

wanton kraken
#

will do

rich adder
#

also I would normalize the incoming direction then multiply it again by bullet speed so you have consistent reflect speed

wanton kraken
#

okay, i'll try that. you think this should happen in the if statement earlier in the code, or on collision? probably on collision i figure

rich adder
#

OnCollision is a good spot yes

#

used similar technique on Pong

wanton kraken
#
    private void OnCollisionEnter2D(Collision2D collision)
    {
        life--;
        if(life < 0)
        {
            Destroy(gameObject);
            return;
        }
            print("Collision!");

    }
#

not printing collision, i wonder why

steep rose
rich adder
#

valid

steep rose
#

you dont need that

rich adder
#

what

#

its a statement you certainly do need that

wanton kraken
#

i defintiley do, no?

rich adder
#

yes

steep rose
#

i have never used a ; for adding or subtracting a float

frosty hound
#

Then you've never worked in c#

rich adder
wanton kraken
#

sir yes sir

#
   void FixedUpdate()
    {
        Vector3 direction = transform.up;
        RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, MaxDistance, LayerMask.GetMask("Scene"));
        Debug.DrawRay(transform.position, direction * MaxDistance, Color.green);
        Bullet.velocity = (direction * BulletSpeed);
        

        if(hit.collider != null){
            print("Object Hit at " + hit.collider.name+ "!");

        } else {
            print("Collider hit nothing :C)");

        }

    }
#

it's my first time working with raycasts, so i'm still figuring it out

rich adder
wanton kraken
#

yep

rich adder
#

where are you grabbing Bullet and why is it a field

wanton kraken
#

before void Start, "public Rigidbody2D Bullet;"

rich adder
wanton kraken
#

how do you mean? this is the prefab for the bullet

rich adder
#

are you not instantiating them ?

wanton kraken
#

of course i am

#

that happens in a different script

rich adder
#

im so confused then why is Bullet prefab here

wanton kraken
#

the movement script for the bullet is inside of the bullet prefab

#

always has been

rich adder
#

not the movement for the bullet. You said instantiation is in a diff script

wanton kraken
#

it is.

   void Update()
    {
        if (Input.GetKeyDown(KeyCode.R) == true) {
            Fire();
        }
    }

    public void Fire()
    {
        GameObject bullet = Instantiate(BulletPrefab, transform.position, transform.rotation);

    }
#

that's in the spawner object

rich adder
wanton kraken
#

i don't? all that the spawner script does is check for keypress and spawn the bullet at it's location and rotation, the script inside of the bullet is what creates the raycast and moves to it (which works atm)

rich adder
#

but you're not moving *this * bullet

#

you're moving the prefab

wanton kraken
#

when the prefab spawns a clone in, the script is attatched to the clone, and it moves itself

#

it's working perfectly fine atm

wanton kraken
#

dude. there is a script on the prefab titled "BulletScript" which moves the bullet

rich adder
#

ok don't get snippy lol show that code

#

notice how i wrote it btw

wanton kraken
#

sir yes sir

#

i'm jst a tad confused lol, i of course appreciate the help

rich adder
wanton kraken
#

not really dawg! i've got one to spawn in the bullet on keypress, everything else happens in the script attached to the bullet

#

here's the whole thing, since you asked

using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEditor;
using UnityEditor.Experimental.GraphView;
using UnityEditor.SearchService;
using UnityEngine;

public class BulletMover : MonoBehaviour
{

    public Rigidbody2D Bullet;
    public float BulletSpeed;
    public Collider2D BulletCollider;
    public float MaxDistance = 100f;
    public int life = 3;
  

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

    }

    // Update is called once per frame
    void FixedUpdate()
    {
        Vector3 direction = transform.up;
        RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, MaxDistance, LayerMask.GetMask("Scene"));
        Debug.DrawRay(transform.position, direction * MaxDistance, Color.green);
        Bullet.velocity = (direction * BulletSpeed);
        

        if(hit.collider != null){
            print("Object Hit at " + hit.collider.name+ "!");

        } else {
            print("Collider hit nothing :C)");

        }

    }


    private void OnCollisionEnter2D(Collision2D collision)
    {
        life--;
        if(life < 0)
        {
            Destroy(gameObject);
            return;
        }
            print("Collision!");

    }


}
rich adder
#

ok I see so the raycast is not on a weapon but the bullet itself..

wanton kraken
#

yep, that's what i was trying to say lol

rich adder
#

I didn't understand the purpose sorry so I thought it was a weapon

simple kite
#

Unity is great game engine isn't it ?

wanton kraken
#

no worries dude! i appreciate it

rich adder
#

so the bullet does move? and what happens when it hits wall does it stop

wanton kraken
wanton kraken
steep rose
#

does the raycast hit?

rich adder
wanton kraken
#

10 atm

rich adder
#

make sure Continuous detection is enabled for collision mode

wanton kraken
rich adder
#

and do walls have colliders

wanton kraken
#

which is odd considering that i specifically tell it to collide with the scene

wanton kraken
rich adder
#

you mean the walls / environment

wanton kraken
#

nono, i mean the tag named "scene"

#

which is attatched to the walls

#

not the best name now that i think of it lmao

rich adder
#

Layermasks are not tags

steep rose
#

layermask or tag?

#

you set it to layermask

wanton kraken
#

nono i mean layer

#

jesus i need to use the right words lmao

rich adder
#

bullet and a wall

steep rose
#

did you try making raycast longer?

wanton kraken
#

yes, it's plenty long

#

the tilemap for walls have a collider attached to them

rich adder
#

if the bullet is not colliding at all raycast isn't the issue

wanton kraken
#

the raycast should stop when it hits a wall though, no? it goes right through

rich adder
#

if thats what u mean

wanton kraken
#

alright, noted

rich adder
#

the only thing you would see is Console logs printing
print("Object Hit at " + hit.collider.name+ "!");

wanton kraken
#

true

rocky canyon
#

print my man?

rich adder
#

are those printing, also try showing both inspectors (walls and bullet)

wanton kraken
#

hold on, i have an idea to fix it. i think i set some of this up wrong

rich adder
wanton kraken
#

hm, not sure. i have the obstacles set to the layer 'obstacle', and the bullet, 'bullet', and so forth and so on. but despite naming obstacle in the raycast parameters, it doesn't collide

rich adder
#

you're not showing what I asked 🤷‍♂️ we're on the same problem

wanton kraken
#

alright, i'll do that then

#

here you are

rich adder
#

also your Layer is Obstacle but your script is looking for "Scene"

wanton kraken
#

no, i changed it

#
RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, MaxDistance, LayerMask.GetMask("Obstacle"));
#

yet it still doesn't collide

rich adder
#

the physical bullet should be colliding regardless of raycast

#

show the rigidbody2D settings on the tilemap

#

also your collider isn't set to Used by Composite

wanton kraken
#

nothing to show, it's set to static

steep rose
#

could we see the bullet collider?

wanton kraken
#

mhm

rich adder
#

oh boy..

#

its a trigger no shit its not colliding

rocky canyon
#

double lifting as well

steep rose
#

yeah i saw that

#

also why did the word "uh" get blocked by the server

wanton kraken
#

didn't you guys tell me to set it to trigger? lmao

rich adder
#

I never did

rocky canyon
wanton kraken
#

that fixed it, nice

rich adder
#

that has 0 to do with collisions

#

its only used for detections of colliders (it doesn't physically stop any objects)

wanton kraken
#

i see, gonna take a short walk, will be back later to continue failing

rocky canyon
#

hell ya

rich adder
#

failure is how you build skills up

rocky canyon
#

only if u learn from them 😉

steep rose
#

fact

rich adder
#

tru

rocky canyon
#

is unity6 lts yet? 😅

#

i wake up wondering every morning

#

literally cant wait.. im having anxiety

rich adder
#

what feature are you waiting for most to use in lts

rocky canyon
#

i just want to port my production project to it

#

not waiting on a feature per say

rich adder
#

i only see better improvements on hdrp mostly

#

visually at least

rocky canyon
#

ya, i like the UI more tbh

#

and i figure it wont get reverted.. soo i just want to get my bulk working in there

rich adder
#

yeah its nicer than before with the bigger tabs/buttons

rocky canyon
#

mmhmm it def feels cleaner than i used to be

rich adder
#

wish they could improve the compiling speeds though and switch to Core already

rocky canyon
#

i keep hearing that.. but i haven't noticed it being any slower than my 2022 projects

rich adder
#

I think the speeds would improve greatly if we are on newer .net

swift crag
#

it's not any slower, but it'd be nice for it to be faster :p

rocky canyon
#

i strongly concur

swift crag
#

so are they gonna have to call it CoreBehaviour after the switch 🤔

rocky canyon
#

if my project gets bad enough i just disable everything and manually compile

#

or restart the PC that always speeds it up 50% minimum

rich adder
#

CoreBehaviour has a nice ring to it

steep rose
#

is there any way to add a vector to a vector?

rocky canyon
#

yes?

swift crag
#

have you tried it?

rich adder
#

just add them?

rocky canyon
#

lol

swift crag
#

perhaps you tried to add a Vector2 and a Vector3

rich adder
#

you cant multiply them but you can add/subtract

steep rose
#

unity doesnt like the way i do it

rocky canyon
#

show how u do it

steep rose
#

ah

rich adder
#

probably what fen said

swift crag
#

explain what you tried to do and what the error is

steep rose
#

i multiplied it

#

mb\

rich adder
#

oh

rocky canyon
#

ya, thats different

steep rose
#

yes

rich adder
#

in 2d i always work with 3D vectors just cause of that annoyance with having to cast it or you get error

rocky canyon
#

u can plug in majority of the 2d stuff into a 3d vector.. soo why not

full kite
#
public Sprite CamilaLvl2;    
private void Create (int level)
    {
        GameObject myGameObject = new GameObject("Lvl" + level);
        SpriteRenderer renderer = myGameObject.AddComponent<SpriteRenderer>();
        renderer.sprite = CamilaLvl2;
    } ``` Does anyone know why in the runmode, sprite in the SpriteRenderer of the GameObject  isnt assigning with the Sprite "CamilaLvl2"?
#

where the script is, its assigned a image to it

#

But in runtime, the image is not assigning

#

I really need help

rocky canyon
#

so that screenshot is the Sprite Renderer that you add during runtime?

full kite
#

indeed

#

its during the runtime

swift crag
#

to make sure that your CamilaLvl2 field isn't mysterious getting set to null

rich adder
rocky canyon
#

this find out whats going wrong

full kite
#

Ill show you exactly the entire script, and when I call it

#
private void Create (int level)
    {
        GameObject myGameObject = new GameObject("Lvl" + level);
        SpriteRenderer renderer = myGameObject.AddComponent<SpriteRenderer>();
        renderer.sprite = CamilaLvl2;
        bc2d = myGameObject.AddComponent<BoxCollider2D>();
        rb2d = myGameObject.AddComponent<Rigidbody2D>();

        rb2d.gravityScale = 0;
        bc2d.isTrigger = true;
    }
#
    {
        string thisGameobjectName;
        string collisionGameobjectName;

        thisGameobjectName = gameObject.name;
        collisionGameobjectName = collision.gameObject.name;

        if (mouseButtonReleased && thisGameobjectName == "Lvl1" && collisionGameobjectName == "Lvl1")
        {
            mouseButtonReleased = false;
            Create(2);
            Destroy(gameObject);
            Destroy(collision.gameObject);
            
        }
    }```
#

and when I call it

rich adder
full kite
#

what do you mean by that

#

in the hierarchy?

rich adder
#

the inspector, you only showed a cropped version of the field CamilaLvl2

full kite
#

Canvas

rich adder
full kite
#

indeed

#

so this is a problem here as I can see

rocky canyon
#

UI elements don't use Triggers

rich adder
#

UI objects should probably not have any physics components..

full kite
#

Ok so basically

#

The Canvas has the script

#

in the canvas it exists 2 game objects

#

that use the ontriggerstay2d

rich adder
#

but why

rocky canyon
#
public class ButtonClicker : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler
{
    bool isHovering;

    public void OnPointerEnter(PointerEventData eventData)
    {
        isHovering = true;
        Debug.Log($"Hovering over: {gameObject.name}");
    }

    public void OnPointerExit(PointerEventData eventData)
    {
        isHovering = false;
    }

    public void OnPointerDown(PointerEventData eventData)
    {
        if (isHovering) // redundant
        {
            Debug.Log($"Clicked on: {gameObject.name}");
        }
    }

    public void OnPointerUp(PointerEventData eventData)
    {

    }
}
``` for UI you need a system like this
full kite
#

They also have the script

#

so eachgameobject has the sscript also

rich adder
full kite
#

no

#

im trying to detect collision between two gameobjects

#

that also has the script in them

rich adder
#

but why are they in a canvas ?

#

thats why i wanted to see inspectors

full kite
#

because I store all of the gameobject in canvas?

rocky canyon
#

why?

rich adder
#

at this point it would help us to see the entire hierarchy with inspectors...

full kite
#

this is tehe hierarchy

#

so those Lvl1 are the objects

rich adder
#

i know they are objects, those are all gameobjects

#

what is the purpose of those objects

full kite
#

wait wait wait a bit

rich adder
full kite
#

on the inspector field

#

on the gameobjects part of script

#

all of them are empty as they used to

#

this is the inspector of the gameobject

rich adder
#

jesus almighty

#

I seem camila here isn't assigned?

rocky canyon
#

array[] has left the chat

full kite
#

how can I assign the "Camilalvl2" to a image of a script inside of the script

rich adder
#

ever heard of an array

full kite
rocky canyon
full kite
#

i wasnt able to make that thing

rocky canyon
#

you mean you weren't able to debug the values?

full kite
full kite
rich adder
#

to assign anything you need =

full kite
#

to setup the debugger

summer stump
rich adder
# full kite

is this the script that has private void Create (int level)

rocky canyon
rocky canyon
#

just put the variables inside the ()s

safe radish
#
                uOffset = (adjPos.x % tilingFactor) * tileSize;
                vOffset = (adjPos.y % tilingFactor) * tileSize;
                break;
            case Direction.East:   //X+
                uOffset = (adjPos.z % tilingFactor) * tileSize;
                vOffset = (adjPos.y % tilingFactor) * tileSize;
                break;
            case Direction.West:   //X-
                uOffset = (adjPos.z % tilingFactor) * tileSize;
                vOffset = (adjPos.y % tilingFactor) * tileSize;
                break;
        }

        uvs.Add(new Vector2(uOffset, vOffset + tileSize));
        uvs.Add(new Vector2(uOffset + tileSize, vOffset + tileSize));
        uvs.Add(new Vector2(uOffset + tileSize, vOffset));
        uvs.Add(new Vector2(uOffset, vOffset));```  left some cases out to make the message shorter, how can i correct the offsets for z- x+ and y-? this work for the other 3 directions
rich adder
summer stump
#

It will help a LOT

delicate portal
#

How do I start a walking sound fx when walking? I'm having tries which do work in a way... But not perfect. What is the solution?

rich adder
rocky canyon
#

different solutions available

summer stump
rocky canyon
#

you can do it w/ animation events..

delicate portal
rich adder
#

yes animation event

rocky canyon
#

or u can do it with a timer / distance traveled

full kite
rocky canyon
#

yea navarone.. how he do it 👀

rich adder
full kite
#

firstly I need to assign to the new created gameobjcet the script, which I did, but how do I assign the image to the script

summer stump
full kite
rich adder
#

from what you shown it was empty

#

assign it in the inspector?

full kite
rich adder
full kite
#

cause that gameobject is being created inside of the game

rocky canyon
#
    renderer.sprite = CamilaLvl2;
    Debug.Log(renderer.sprite != null ? "Sprite assigned successfully." : "Failed to assign sprite.");```
rich adder
summer stump
full kite
rich adder
#

the one you use to pass to the instantiated one

rocky canyon
#

where tf is the condition?

full kite
#

how can I do it

rocky canyon
#

if what?

delicate portal
rich adder
full kite
#

i cant assign it to the inspector cause I donlt have the inspector when Im not in run time

delicate portal
rich adder
summer stump
#

As for silence, that is normal. Add some ambience and you won't notice

full kite
#

Let me clarify it

delicate portal
full kite
#

Im pressing a button

#

a gameobject spawns

delicate portal
full kite
#

I assign to the gameobject the script

summer stump
full kite
#

then i want to create another gameobjcet

#

bam, doesnt work

rich adder
#

your system is overcomplicated because its poorly written

#

redo it, so you understand it

summer stump
full kite
#

my main question rn is how to

#

put to that field an image

#

inside of the script

delicate portal
rich adder
summer stump
delicate portal
summer stump
delicate portal
#

I have the function setup, I was just curious about the method you use these

#

A stop method would stop the two fxs tho

summer stump
delicate portal
rocky canyon
#

to have multiple sources for footsteps.. ya i agree..
but multiple sources in general makes alot of sense.. and is common

delicate portal
summer stump
rocky canyon
#

yup, i was clarifying for him

summer stump
rocky canyon
#

always mate 👍

#

no ego..

delicate portal
#

I understood what you were saying mate 😆
Althought I was never into sound design...

rocky canyon
#

hey, theres plenty of assets for footsteps

#

maybe grab some and reverse engineer em

rocky canyon
#

i fumble my way thru audacity.. make a clip and then OneShot() that thang

delicate portal
rocky canyon
rocky canyon
summer stump
#

I'm definitely bad at making it clear haha

rocky canyon
#

i have an audiomanager that has references to all types of sources that play different things

#

(menu sounds, boom sounds, player sounds, etc) then they all have OneShot() methods.. and i just pass in the clip from the script im calling upon the AudioManager from

delicate portal
#

I just have like... Random sources

rocky canyon
#

until u name/ categorize/ and assign them somewhere

#

and then they're structured and not-random 🙂

frank zodiac
#
foreach (char c in line.ToCharArray())
{
    bool specialCharacter;

    if (c == '?' || c == '.' || c == ',' || c == ':' ||
    c == ';' || c == '!' || c == '-')
    {
        specialCharacter = true;
        yield return new WaitForSeconds(interpunctuationDelay);
    }
    else
    {
        specialCharacter = false;
    }

    if (c == '<' || addingRichText)
    {
        addingRichText = true;
        if (c == '>')
        {
            addingRichText = false;
        }
    }

    if (!specialCharacter || !addingRichText)
    {
        PlayDialogueSound(text.maxVisibleCharacters, text.text[text.maxVisibleCharacters]);
        text.maxVisibleCharacters++;
        yield return new WaitForSeconds(1f / charactersPerSecond);
    }
}

trying to make it so that my dialogue doesnt play a sound when a special character comes but its not working.

rocky canyon
#
    public AudioClip intro;
    public void PlayTempUISFX() => atmosphericSource.PlayOneShot(intro);

    public AudioClip gunshot;
    public void PlayGunShot() => playerSource.PlayOneShot(gunshot);

    public AudioClip[] hurt;
    public void PlayHurtSound() => playerSource.PlayOneShot(hurt[Random.Range(0, hurt.Length)]);

    public AudioClip basehit;
    public void PlayHit() => interactionSource.PlayOneShot(basehit);```
rocky canyon
frank zodiac
rocky canyon
#

my guess would be that its not registering when charactes are special

rocky canyon
#

thefor all of em are !special

frank zodiac
#

its in an else block

#

for some reason

#

thats why

frank zodiac
rocky canyon
#

u have two delays u sure its the first one?

#

debug specialCharacter

frank zodiac
rocky canyon
#

Debug.Log($"Special character is: {specialCharacter}");

#

debug it everywhere thruout those functions

frank zodiac
rocky canyon
#

so its true?

frank zodiac
#

yeah

rocky canyon
#

soo is it ever false?

#

b/c if not then that conditional doesnt run

frank zodiac
rocky canyon
#

if (!specialCharacter || !addingRichText) <-- means if its not true

#

oooor if not adding richtext

idle ginkgo
#

time.deltatime basically as a numerical value that increases with time right?

rocky canyon
#

if either one of those are conditions return true ur dialog sound will play

rocky canyon
#

delta Δ

idle ginkgo
#

oh k

frank zodiac
#

if either one of them return false

#

not true

rocky canyon
idle ginkgo
#

why for moving player everyone multiplies move speed with time.delta time

rocky canyon
#

remove one of em.. and test w/ just the !specialCharacter

frank zodiac
rocky canyon
idle ginkgo
#

oh so if a frame took longer too load , it will move more accordingly

#

got it

rocky canyon
#

multiplying it w/ delta time makes it frame independant

#

sooo both machines will move same distance.. no matter the frame rate

frank zodiac
rocky canyon
#

strange..

#

i'd have to test it a bit on my machine to figure it out.. i dont see anything that stands out to me a being wrong from the code u sent

idle ginkgo
#

i tried and i able able to directly use transofrm.position in visual studio

#

why cant i do this for other compnents like rigidbody and animator

rocky canyon
#

!ide is it configured correctly?

eternal falconBOT
idle ginkgo
#

for that i need to getcompnent or make an instance i think

frank zodiac
rocky canyon
#

no.. i'll just rob ur script

frank zodiac
rocky canyon
#

debugs

remote osprey
#

Hello

frank zodiac
rocky canyon
remote osprey
#

How do i make a collider move left/right with left and right direction keys

frank zodiac
#

but hello to you too

eternal falconBOT
#

:teacher: Unity Learn ↗

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

rocky canyon
frank zodiac
#

whats the diff between them

rocky canyon
#

it returns -1, 0, 1

#

if its not raw then its smoothed automatically..

frank zodiac
#

why not make it smooth though

rocky canyon
#

i just odnt like the smoothing uunlesss im doing it on purpose

rocky canyon
frank zodiac
rocky canyon
#

i can multiply it by my speed variable.. and as soon as i release the keys i know my speed is going to be 0

#

instead of 1, .9, .5 , .432, .2 0

rocky canyon
#

!code

eternal falconBOT
frank zodiac
rocky canyon
#

yea use one of those paste bin sites

#

it's fine

frank zodiac
rocky canyon
#

thanks imma look it over i cant promise anything tho

rocky canyon
#

ohhh its how u update ur string

#

the issue is that text.maxVisibleCharacters is being incremented for every character, but PlayDialogueSound is still called for all characters, including special characters and rich text tags.

#
private IEnumerator DisplayLine(string line)
{
    text.text = line;
    text.maxVisibleCharacters = 0;
    continueButton.SetActive(false);
    HideChoices();
    canContinueLine = false;
    bool addingRichText = false;

    int visibleCharacterIndex = 0; // Counter for visible characters

    foreach (char c in line.ToCharArray())
    {
        bool specialCharacter = (c == '?' || c == '.' || c == ',' || c == ':' || c == ';' || c == '!' || c == '-');
        
        if (specialCharacter)
        {
            yield return new WaitForSeconds(interpunctuationDelay);
        }

        if (InputManager.GetInstance().GetContinuePressed() && canSkip)
        {
            text.maxVisibleCharacters = line.Length;
            break;
        }

        if (c == '<' || addingRichText)
        {
            addingRichText = true;
            if (c == '>')
            {
                addingRichText = false;
            }
        }
        else
        {
            if (!specialCharacter)
            {
                PlayDialogueSound(visibleCharacterIndex, c);
                visibleCharacterIndex++;
            }

            text.maxVisibleCharacters++;
            yield return new WaitForSeconds(1f / charactersPerSecond);
        }
    }

    continueButton.SetActive(true);
    DisplayChoices();
    canContinueLine = true;
}``` try this
idle ginkgo
#

for movement

rocky canyon
#

theres times u shouldnt

#

dont ever multiply ur inputs w/ it before the movement code

#

dont use it in FixedUpdate

#

use fixedDeltaTime instead

idle ginkgo
#

oh ok

slender nymph
rocky canyon
#

i keep forgetting that.. i guess its fine in that case then

rocky canyon
# idle ginkgo oh ok

also any time ur incrementing something
myValue += newValue <-- this would increment differently for different framerates..
soo use myValue += newValue * deltaTime;
same with *= or any other incrementing type of method

elder raptor
#

Can an On Trigger collider trigger another On Trigger collider?

elder raptor
#

okiee

halcyon dagger
#

Ayo, which of the following 2 decalrations is better for a parameter thats only gonna be used inside its class, and the class aint gonna be called from any other script.


[SerializeField] private GameObject obj;
public GameObject obj;`
slender nymph
#

the first. if other objects don't need access to it then it does not need to be public

#

it's also not a parameter, but a field

halcyon dagger
#

Got it, thanks 🤙

glad ore
#

I want to make levels,
30 scenes for 30 levels ? ( just a small 100*100 terrain level)
or 30 levels in 1 scene itself ( and how to do it)

broken cargo
glad ore
frank zodiac
#

@rocky canyon i dont mean to be irritatating but; have you found anything? ive asked but found nothing still

broken cargo
glad ore
idle ginkgo
#

i am not able to rotate the sprite properly

#

changing z rotation should rotate it abot pivot right

#

like in the scene editor when i increase the z value it rotates perfectly about pivot

rich adder
#

show how you rotate in code

idle ginkgo
#

but when i do the same using code , the z value increses correctly but it doesnt rotate that way

#

like this

rich adder
idle ginkgo
#

it is but its rotating like pendulum

#

not like a wheel about pivot at centre

#

which is very weird

wintry quarry
#

When you rotate it, it changes where Translate will move you

idle ginkgo
#

ohhhhhhhhhhhhhh

#

How can i make these independent

wintry quarry
#

You can use world space in Translate with an extra parameter. Or move by setting position directly

idle ginkgo
#

i want this saw to go back and forth and spin at the same time

wintry quarry
#

Really the visual part of the saw should be a child object

swift crag
#

indeed

wintry quarry
#

And you animate the child however you want

swift crag
#

Using multiple objects dramatically simplifies things

swift crag
#
  • Sawblade <-- circle collider
    • Sprite <-- sprite renderer
idle ginkgo
#

btw i use this , where should the rigid body go

#

in this situation

swift crag
#

A Rigidbody can use any collider that's parented to it

idle ginkgo
#

the child or parent?

swift crag
#

You generally want it up top

idle ginkgo
#

oh thanks a lot

swift crag
#

It matters less if it's a kinematic rigidbody, since it won't be moving around on its own

#

But I'd still put it on the parent.

rancid tinsel
#

i dont understand why this requires a "workaround" instead of just making the local scale x/y equal the calculation?

#

could someone explain why that is to me?

swift crag
#

transform.localScale is actually a property

#

when you access it, you're calling a method that gives you a Vector3

#

Vector3 is a value type. This means that you aren't holding a reference to the actual object somewhere else -- you hold the value itself

rancid tinsel
#

what about localScale.x though? normally you can just access an x value of a vector3 and change it normally

queen adder
#

excuse me where is textures chat?

river quiver
#

should i avoid using void Start() and void Update() in logic scripts?

swift crag
#

so it's a compile error

queen adder
#

Or help my bad.

swift crag
rancid tinsel
swift crag
#

you modify that copy

#

and then you store the copy back into transform.localScale

river quiver
swift crag
queen adder
swift crag
#

there is not a "textures" chat. you can ask in #💻┃unity-talk if you're unsure where to ask about something.

#

this is definitely not a code problem

queen adder
#

thats why i asked for the texture help bro

river quiver
swift crag
swift crag
#

there's nothing really special here

river quiver
#

ight thanks

west sonnet
#

What would be the best way to create a enemy that is able to hit the player? I don't mean the player not being able to touch the enemy at all, I mean the enemy hits and only does damage when the hit connects with the player

#

I feel like most tutorials on YT only go over the player not being able to touch the enemy at all

#

Would you make a collider appear and disappear in time with the animation? Or use a raycast?

rich adder
#

overlap

#

raycast good too, is just too thin for melee

west sonnet
#

Ookay

#

I'm trying to make a boss battle, so gotta figure out how imma do it

rich adder
digital kelp
#

ah ty

full kite
#

I have the weirdest problem and I cant figure out a solution for like 2 hours straight.
Basically my UI is alright when im starting in 1920x1080. When I change it to 720x1560 nothing changes.
But when my UI is starting in 720x1560 it goes in all directions some gameobjects, and when im changing to 1920x1080 all are dessapearing. When im putting it on my phone (720x1560 resolution) I see them as I start my run time in 720x1560 on my PC. All of them have an anchor and i really dont know why it happens. Can somebody help me?

#

@rich adder

river quiver
#

This code is in void Update() and after it reaches for example 10 i want it to increment the value only once because now when the enemy hits score 10 it adds 1 every frame because he hasnt reached the score 11 yet, how do i make it to wait

if (gameManager.playerScore >= 10 && gameManager.playerScore % 10 == 0)
{
    moveSpeed += 1;
}
hasty sleet
lethal bolt
#

Cant Raycasts be inn eachoter?

hasty sleet
# river quiver This code is in ``void Update()`` and after it reaches for example 10 i want it ...

Can you describe this problem a little more clearly? The code you posted, if it's in update, makes the player extremely fast once their score reaches 10 or is at 20, 30, 40, 50, etc., or another number >=10 and evenly divisible by 10.

@river quiver
Note: Update triggers every frame-per-second update, which means faster computers will receive faster iterations of logic which is probably not what you want

lethal bolt
wintry quarry
wintry quarry
lethal bolt
#

it did until i made the other one longer

wintry quarry
#

They are unrelated to each other

#

They cannot affect one another

full kite
#

I have the weirdest problem and I cant figure out a solution for like 2 hours straight.
Basically my UI is alright when im starting in 1920x1080. When I change it to 720x1560 nothing changes.
But when my UI is starting in 720x1560 it goes in all directions some gameobjects, and when im changing to 1920x1080 all are dessapearing. When im putting it on my phone (720x1560 resolution) I see them as I start my run time in 720x1560 on my PC. All of them have an anchor and i really dont know why it happens. Can somebody help me?

hasty sleet
swift crag
swift crag
full kite
#

like missplaced

#

but only few of them

swift crag
#

they probably have bad anchors, then

#

or your UI has LayoutGroups and you've got some incorrectly configured objects

#

are you using HorizontalLayoutGroup/VerticalLayoutGroup?

full kite
#

Nope

#

Placed them by coords

hasty sleet
# full kite Nope

I have a feeling something is wrapping or getting stretched due to the different resolution.

Can you post a picture of before/after to help identify the issue?

full kite
#

like with this line

myGameObject.transform.position = new Vector3(newX, newY, 0);
swift crag
#

this sets an exact position on the screen, assuming this is a "Screen Space - Overlay" canvas

#

why are you doing this?

safe radish
#
                vOffset = (adjPos.y % tilingFactor) * tileSize;
                uvs.Add(new Vector2(uOffset, vOffset + tileSize));
                uvs.Add(new Vector2(uOffset + tileSize, vOffset + tileSize));
                uvs.Add(new Vector2(uOffset + tileSize, vOffset));
                uvs.Add(new Vector2(uOffset, vOffset));``` it looks like im getting the output im expecting for the u and v values. but i can't figure out how to apply the correct offsets for the different directions
full kite
#

it is

#

first one is 720x1560
and the second one is 1920x1080

hasty sleet
wanton kraken
#

hey fen, remember all that work we did to make the bullet work right and follow the raycast? well it randomly doesn't work now :l could i send you the code?

twin bolt
#

How can i make the "item" go up also? Item.GetComponent<Rigidbody>().AddForce(ItemHand.transform.forward * 100);

wanton kraken
#

transform.up?

hasty sleet
wintry quarry
twin bolt
hasty sleet
full kite
wanton kraken
#

yeah, transform.up * speed

hasty sleet
#

I wouldn't multiply it with forward

#

You add the vectors

wanton kraken
#

transform.up and transform.forward are two different directions

wintry quarry
full kite
#

and the second one is with that code

twin bolt
hasty sleet
#

They are being set through two different mechanisms, and one of them is dependent on the resolution.

full kite
#

like with this line

myGameObject.transform.position = new Vector3(-1.505f, 2.6f, 0);
hasty sleet
#

They align with your native resolution but not with your skewed resolution.

wintry quarry
umbral rock
#

anyone knows why my vscode doesnt show code suggestions? like if i put inp, he would automatically go for input but he doesnt do that anymore? this is called intellisense right?

full kite
eternal falconBOT
safe radish
wintry quarry
full kite
#

and what should I do to fix it?

wanton kraken
#

what be the issue? it's not bouncing properly, and for whatever reason when i spawn it, it sometimes doesn't move..

    void FixedUpdate()
    {
        Vector3 direction = transform.up;
        RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, MaxDistance, LayerMask.GetMask("Obstacle"));
        Debug.DrawRay(transform.position, direction * MaxDistance, Color.green);
        Bullet.velocity = (direction * BulletSpeed);
        
        if(hit.collider != null){
            print("Object Hit at " + hit.collider.name+ "!");
            Vector2 reflectionDirection = Vector2.Reflect(direction, hit.normal);
            direction = reflectionDirection;
            transform.Translate(direction * Time.deltaTime * BulletSpeed);

        } else {
            print("Collider hit nothing :C)");
            transform.Translate(direction * Time.deltaTime * BulletSpeed);

        }

    }
full kite
#

and what should I do PraetorBlue?

#

should i set the carpet with resolution too

#

like floats?

hasty sleet
full kite
hasty sleet
hasty sleet
#

You might be able to programatically create/assign things to the UI in a way that is compatible with canvas rescaling, but I'm not sure how to do it off the top of my head. Some of the others might know

swift crag
full kite