#πŸ’»β”ƒcode-beginner

1 messages Β· Page 223 of 1

rich adder
#

expose it

languid timber
#

I mean the SetActive is false when the game begins, so ehh

#

donno

quick pollen
#

just make sure u use the Reference name not the actual name

rich adder
#

but what about when you call GameSaved/GameLoaded

languid timber
#

then is is set to SavingNotifier.SetActive(true);

shell sorrel
summer stump
#

There is a mouse delta binding though

rich adder
#

wtf

#

weird timing

lusty flax
#

In my spritesheets, do all of my sprites need to be encased in equally-sized squares? will it work if I save space by making them be in rectangles?

languid timber
frigid sequoia
#

I mean I was trying to create the typical effect of changing the opacity of any object blocking sigth of the player, I downloaded a bunch of script that did that, but doesn't seem to work with anything else that is not the standard Unity mats. So since just the walls can get into the player view I decided I should just adjust the mat so it can be manually set to be transparent, but I don't know what else to do from there πŸ˜…

rich adder
lusty flax
rich adder
shell sorrel
lusty flax
rich adder
rich adder
languid timber
rich adder
#

then in that case no making them rectangles will resize it @lusty flax

shell sorrel
#

yeah the PauseMenu Gameobject will need to stay active all the time

#

otherwise it will prevent hte coroutines from running

lusty flax
shell sorrel
#

that counts its parent being disabled as well

rich adder
lusty flax
rich adder
#

make them rectangles there if you want to modify their "borders" of the rect transform

#

but in sprite editor

languid timber
rich adder
#

so its working...

#

oh wait nvm wrong log srry

#

are you modifying the Timescale ?

#

might have something to do with it

languid timber
#

Yes!

shell sorrel
#

ah

languid timber
#

I indeed am

shell sorrel
#

WaitForSecondsRealTime

#

instead of WaitForSeconds

languid timber
#

wiil do it?

rich adder
#

*for coroutine

shell sorrel
#

because your pause was setting timescale to 0, WaitForSeconds was also pausing

languid timber
#

aha!

shell sorrel
#

WaitForSecondsRealtime ticks forward no matter what timescale is

languid timber
#

but where do I put that in exacty?
because its not here yield return new WaitForSeconds(delay);

shell sorrel
#

you replace WaitForSeconds with WaitForSecondsRealtime

#

exact same place, it takes the same args

#

yield return new WaitForSecondsRealtime(1);

languid timber
#

wait now it does work haha

#

it just did not

#

Holy bimbus the monkey it works!

rich adder
languid timber
#

thanks all! appreciate the effort you put in for me :)

summer stump
#

Ahh, just came back in to see it.
Dang timescale! Didn't even consider it

shell sorrel
#

yeah no one clued in till they saw other pause related things

languid timber
shell sorrel
#

atleast was a easy fix once found, just replace the yield step

languid timber
clear seal
#

so basically my code says there is an error form the tutorial i made but i dont see an error it's perfectly the same

shell sorrel
#

its a Gojira album art right, been a while since i listened to any but great stuff

languid timber
#

does the Invoke method also work whenever time.timescale = 0 if you use some trick to let it go by the timescale 0?

queen adder
#

What does the error tell u gold?

clear seal
queen adder
#

Its a very simple mistake

#

It should say something about this method doesnt have a overload

clear seal
rich adder
queen adder
#

Ok what can tell you from this

#

You put in 4 arguments

shell sorrel
languid timber
languid timber
rich adder
#

exactly ! almost got KOd twice in the pit

queen adder
#

Gold look over ur code

#

How many arguments are u passing into the constructor

languid timber
rich adder
#

but yeah offtopic sorry πŸ˜› lets move onto code

languid timber
languid timber
#

so is the StartCoroutine better than the Invoke?

#

because I donno what would be smart

#

(just in general speaking now)

shell sorrel
#

Coroutines give much more control

rich adder
#

its good for other things too

shell sorrel
#

and do not involve stringly typed bs

#

can pass it args, and can do many things with it

rich adder
#

esp good replacement if you are using InvokeRepeating and need a way to stop the loop/coroutine in general

shell sorrel
#

can wait on time, frames, or a condtion or what ever you want

languid timber
#

hmm I see

clear seal
#

i tried replay it to understan

languid timber
#

well thanks! I will take all off this into consideration

shell sorrel
clear seal
#

i SEE IT NOW

rich adder
languid timber
#

but I am tired as hell, wanted to fix my bug and now its 3 in the mornin

clear seal
#

yay :)

queen adder
#

haha lol

clear seal
#

i typed too fast

queen adder
#

It was telling u the whole time

clear seal
#

:/

queen adder
#

Slow down and read the error more carefully

clear seal
#

he can now move correctly

queen adder
#

They usually tell u the exact error

clear seal
languid timber
rich adder
queen adder
languid timber
#

but imma go now, thanks again for all the help :)

supple citrus
#
#

erm

#

I thought they would have embedded

#

awkward

rich adder
#

uhhh im wary of clicking random cdn links

supple citrus
clear seal
rich adder
#

What I would do instead is using a Render Texture

clear seal
#

:)

rich adder
#

then export that as the Screenshot

supple citrus
#

I thought thats what ive been doing

rich adder
#

i see 2

queen adder
#

Whats up gold?

supple citrus
#

it should capture just the red box in the first image

#

just the simulation

#

and i have that region as a rect called SimBounds

#

But i couldnt get that to work either

rich adder
#

oh ok , and ur certain that simCamera is the smaller cam

supple citrus
#

As in passing SimBounds as a parameter would do the whole screen too

#

Yea 100%

rich adder
#

instead of read pixels maybe copy the image directly from the RT to the texture

#

using GPU

supple citrus
#

How does one do this

rich adder
#

Graphics.CopyTexture

supple citrus
#

I was following a tutorial for the capture method. I'm not rendering the image to any texture I just want to export the image as a file so I don't know if half of the code i have is necessary

pallid nymph
#

they need the pixels anyway to save the image to file

rich adder
#

true

#

wait no

#

Texture class has a method to Save iirc

pallid nymph
#

yes, but it needs to read the pixels to do that

supple citrus
#

All the saving stuff is working fine

#

Its just not capturing the right area

#

Im guessing it does the whole screen as a default when you enter something invalid

#

but I dont know what ive done wrong

shell sorrel
#

did you call apply

#

you need to do it after ReadPixels

rich adder
pallid nymph
#

show screenshot please

#

also try the other camera

supple citrus
#

the other camera is main camera and its the whole screen

#

im 100% certain Im using the right camera

supple citrus
rich adder
#

ah yes

shell sorrel
#

its a method on your Texture2D

rich adder
#

to apply the data you just read

shell sorrel
#

call it after ReadPixels

pallid nymph
#

apply is the thing that sends data to GPU

supple citrus
#

so thumbnail.Apply() ?

pallid nymph
#

so you don't need it

#

you're not writing pixels and sending them to GPU, you're doing the other direction

shell sorrel
#
_camera.Render();
RenderTexture.active = RenderTarget;
outTex.ReadPixels(new Rect(0, 0, RenderTarget.width, RenderTarget.height), 0, 0);
outTex.Apply();
var bytes = outTex.EncodeToPNG();
#

is how i normally do this

#

then i just shove those bytes into a file

pallid nymph
#

show one screenshow and I'll go check my code for this in the meantime πŸ˜„

teal viper
# supple citrus

Did you try debugging the pixel width and height and confirming that it corresponds to the expected area?

supple citrus
#

Apply() doesnt change anything

#

It was correctly screenshotting and saving the image just not capturing the right area

supple citrus
#

What corner is that lol

rich adder
#

maybe because because ur passing in the camera size instead of RT size

supple citrus
night grove
#

hey im new what should i learn first?

shell sorrel
#

RT size is the pixel size of it

pallid nymph
#

you're missing the camera.render() bit

shell sorrel
rich adder
eternal falconBOT
#

:teacher: Unity Learn β†—

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

shell sorrel
#

i tell it when it capture a frame

night grove
#

oh ok ty

rich adder
#

start with the Essentials path @night grove

night grove
#

!learn

eternal falconBOT
#

:teacher: Unity Learn β†—

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

shell sorrel
#

your Texture2d how is it created

#

what size and format

#

new Texture2D(RenderTarget.width, RenderTarget.height, TextureFormat.ARGB32, false)
made my the size of my render texture

pallid nymph
shell sorrel
pallid nymph
#

(because I have it too πŸ˜„ but that's code I wrote ages ago, so πŸ€·β€β™‚οΈ )

supple citrus
#

Does it even matter which camera its using, as long as I pass the correct region as a Rect into the ReadPixels function, no?

shell sorrel
#

keep in mind the Rect will be pixel coords into the RT

#

not Screenspace coords

supple citrus
#

Oh my rect is in the Screenspace i think

#

Since the width is 8.7f

shell sorrel
#

textures are all about pixels

supple citrus
#

Can I convert the rect at once or do I have to redefine it with pixel coords

shell sorrel
#

well you can just figure it out

#

its your RT you know its res

supple citrus
#

No I dont

shell sorrel
#

and what that is relative to your screensize

supple citrus
#

I have no idea what a rt is loool I just want to export a screenshot as a file

frigid sequoia
#

Ok so... this the script that is supposed to change the oppacity of the object that is blocking sight; if I de-comment like 131 it does set the oppacity to the value that it is indicating (through a shaderGraph variable directly connected to the alpha) AND in lane 146, the debug in the loop is showing the alpha value change properly, so.... why it isn't working, can I not the change the whole alpha value in the color of a shadergraph mat or what is going wrong? I don't get it

rich adder
#

:squinting

supple citrus
#

IF simbounds was the correct region, would this work

eternal falconBOT
shell sorrel
queen adder
#

I keep seeing this

frigid sequoia
supple citrus
#

But the code gives this

pallid nymph
supple citrus
#

And im guessing this is a screenspace/pixel issue

frigid sequoia
ivory bobcat
queen adder
frigid sequoia
shell sorrel
queen adder
#

But thats not the actual time and wont the timer change depending on frime rate?

#

Shouldnt the timer always be consistent?

rich adder
#

across low / high fps

shell sorrel
#

though there lerp looks all wrong

#

its last arg should be elapsedTime / duration

queen adder
#

Hope u guys dont mind

#

But im gonna test so i can set my mind to ease

#

Ill post results here

rich adder
#

go for it

#

you should always test things anyway

supple citrus
#

Since I have no idea why its capturing the wrong area, is there a way I can just crop the image after lol

pallid nymph
#

don't trust randos on the internet

#

some are absolute trolls!

frigid sequoia
pallid nymph
supple citrus
#

Ive been trying for days lol

#

Im so lost with this

lusty flax
#

i made animations using spritesheets. How do I implement them now? How do i make them play when the player does a certain thing?

rich adder
opaque bough
# supple citrus Im so lost with this

This may be a stupid thing to say: but I occasionally use Microsoft copilot to help me write code when I scroll on YT for hours and can't find anything. . .you could try that. πŸ€·β€β™‚οΈ I'm a noob anyway so maybe don't listen to me

queen adder
#

public sealed class DeltaTimeTest : MonoBehaviour
{
    private void Awake()
    {
        Application.targetFrameRate = 60;
    }

    float _real_time;
    float _delta_time;

    private void Update()
    {
        _real_time = Time.time;

        _delta_time += Time.deltaTime;

        print($"Real Time is {_real_time}");
        print($"Delta Time is {_delta_time}");
    }
}```
pallid nymph
#

I recommend against - if you wanna do this (programming / game dev), you need to learn to code and to debug and all that

queen adder
#

I didnt think about switching framerates on the fly like that tho. Thats smart im about to steal

#

Something wrong with mine?

opaque bough
rich adder
shell sorrel
queen adder
#

No no im asking before i test

shell sorrel
#

so create for driving lerps

#

since you can easily do elaspsedTime/duration

pallid nymph
# supple citrus Im so lost with this

okay, so try adding the camera.Render() just in case... also, make the camera size VERY different, like a 200 x 200 square at the top right corner - see what happens, understand more about what's going on and why

rich adder
shell sorrel
queen adder
#

My point is that the timers should be consistent across all frame rates with time.deltaTime the timer wouldnt be consistent depending on frame rate

rich adder
#

right thats why Time.deltaTime

#

so its independent

supple citrus
pallid nymph
shell sorrel
queen adder
#

Maybe im overthinking it

rich adder
pallid nymph
supple citrus
#

is that this? :v

opaque bough
shell sorrel
rich adder
opaque bough
#

Lol

queen adder
supple citrus
#

I dont actually want the texture to be rendered onto anything though I just want to save the image as a file

frigid sequoia
#

No, so apparently changing the alpha of ShaderGraph Mat does absolutely nothing for some reason, at least on mine

#

Why is that? Is that normal?

pallid nymph
#

potential problem with deltaTime is if framerate drops really low (so that the step becomes larger than max time step allowed)... only then you'll have lost time

ivory bobcat
# frigid sequoia Ok so... this the script that is supposed to change the oppacity of the object t...

What is a fading object? If it follows the general unity convention, you'd normally need to assign the new materials back:cs var materials = renderer.materials; ... renderer.materials = materials;https://docs.unity3d.com/ScriptReference/Renderer-materials.html

Note that like all arrays returned by Unity, this returns a copy of materials array. If you want to change some materials in it, get the value, change an entry and set materials back.

pallid nymph
queen adder
#

Results

shell sorrel
shell sorrel
#

set that to rendertexture.active then read that into the texture 2d

queen adder
#

Now im gonna change frame rates

shell sorrel
# queen adder

that does not really prove anything, since Time.time of course starts earlier

#

since its not based on when that script started updating but the engine loading

ivory bobcat
queen adder
rich adder
pallid nymph
#

I'm not sure that's correct... now I wanna try it πŸ˜„

rich adder
#

i telling you its pretty accurate maybe few ms off

queen adder
#

There different!!

#

At the 60 fps deltaTime was half its value

rich adder
pallid nymph
#

yours re suspiciously off, tbh

shell sorrel
#

i cant see what your test is trying to prove though

frigid sequoia
queen adder
shell sorrel
#

like what are you expecting your test, to test?

queen adder
#

Im testing to see if .deltaTime is good for timers

frigid sequoia
queen adder
#

Like if deltaTimes...time is actual time passed

rich adder
shell sorrel
#

to get them to match on Start you would need to cache Time.time to a var so you can subtract it wehn printing the result

rich adder
#

like the one on your computer

shell sorrel
rich adder
queen adder
#

Ill test deltaTime with a timer on my phone

rich adder
#

maybe few ms off

#

delaying in my clicking mostly

shell sorrel
#

and can accumlate

rich adder
#

true

#

ya you're still depending on the Update loops at the end of the day which is still tied to FPS no ?

shell sorrel
#

deltaTIme is how long the last frame took, time.time is just summing all of that since startup

queen adder
#

Ok at a 144 fps there pretty close

#

few ms off

shell sorrel
#

thing is the usage you saw that start all of this

#

the real time passed does not matter

#

since it was for a lerp and things inherently tied to frames

queen adder
#

Oh wow

#

Im just crazy

#

Same thing at 60 FPS

rich adder
#

I mean i did test it at 4fps before and it was pretty close to 60fps too

shell sorrel
#

also the different in time and deltaTime you see is related to startup time

rich adder
#

but yeah like mentioned wont be totally accurate.

#

if you need real accuracy use Datetime and compare those

shell sorrel
#

that or any of the system timer classes

#

will be more tied to your systems clock then frames

rich adder
#

oh yeah StopWatch works too right ?

shell sorrel
#

yeah

#

that would not effected by frames

#

well aside from that you are starting and stopping it in unity code

#

that is frame based

queen adder
#

Thats true

#

My mind can finally rest

shell sorrel
#

but some wavier will happen in that too, like time.Time does not change because you check it later in a frame

#

but a stopwatch would

opaque bough
#

Deep stuff

ivory bobcat
queen adder
#

Yeah i realize that now

#

It just felt off for some reason

shell sorrel
pallid nymph
#

it's good enough if you're measuring things in seconds, I guess

shell sorrel
#

well it all depends on why you are measuring things

#

like good to 16ms for the most part assuming 60fps

#

but why you are measuring things always matters

#

in this and real like, like i dont use machinist tools for measuring wood

#

so if its a timer for driving a lerp, only frame accuracy matters

#

really a timer for most gameplay related things only that matters

ivory bobcat
#

Expect some floating point errors though if you're simply accumulating values and comparing it to total elapsed time UnityChanSorry
Refer to time stamps with caches of Time.time, if the precision is important.

shell sorrel
hybrid gust
shell sorrel
#

so will get weird for long sessions

pallid nymph
#

there's timeAsDouble now, no?

shell sorrel
#

ah did not know about that

rich adder
#

didnt look at code yet though

hybrid gust
abstract pelican
#

I added a virtual camera, now when the player moves for some reason the sight is twitching, how to fix?

shell sorrel
#

but yeah worrying about sub frame timing for most game related thigns is like trying to measure up wood for framing a house with a caliper

frigid sequoia
#

So.. since _Color does nothing, I guess I will do this shit that is terrible cause only work if the inital alpha es exactly one and the shader has an _alpha value conected to the alpha, but I guess it gets the job done....

rich adder
ivory bobcat
hybrid gust
shell sorrel
#

and why no one uses float or double where you need to be perfect

rich adder
#

also are you taking screenshots of inventory items ? I got a tool I made a while ago if you need that

queen adder
#

Should be Application.PersistentDataPath

rich adder
rich adder
#

just reminded me I should probably update this tool to UIToolkit and cleanup some stuff

abstract pelican
hybrid gust
queen adder
#

Might have something to do with ur camera settings? Also does ur character have a rigidbody or character controller?

rich adder
queen adder
#

Well first off

hybrid gust
#

can't open the editor

queen adder
#

Interpolation on the Rigidbody should be set to interpolate

#

And Collision detection Continous

rich adder
#

and it started endlessly compiling?

queen adder
#

Still needs to be set to interpolate

rich adder
#

let me test this q

hybrid gust
#

Double clicked, then I got some post processing something or other for like 2 min

abstract pelican
queen adder
#

have u ran the game?

#

Did that fix ur issue?

rich adder
abstract pelican
queen adder
#

Still twitching?

abstract pelican
#

the scope jerks when I aim and when I walk.

#

It's not me that's twitching, it's my scope that's twitching when I'm aiming and moving.

#

it came out after the virtual camera

queen adder
#

Show a video of the problem so i can make sure, were talking about the same thing

lusty flax
#

why does this cam follow script not work?

void Update()
{
    gameObject.transform.position = new Vector2(player.position.x + xOffset, player.position.y + yOffset);
}

when I run it, I see nothing from the camera, even with a y offset of 0

queen adder
#

Needs more context. Is that script on the Camera or the player?

#

Ok on my end it pretty much looked shaky the whole time

#

How are u moving the player?

abstract pelican
#

I told you it started after I added the virtual camera.

queen adder
#

Not u for cinemachine the other guy

#

Omg

supple citrus
#

it was camera.Render() after all

#

I didnt realise i had the camera disabled by default

lusty flax
abstract pelican
#

so I uninstalled the virtual camera and the twitching went away.

queen adder
#

Did u ever have a camera follow the player before cinemachine?

abstract pelican
#

How do I fix this? I want to track the player and aim without jerking.

queen adder
#

I dont think its cinemachine it always works for me in 2D projects

lusty flax
abstract pelican
#

I've always used a virtual

queen adder
#

Ok show me ur playermovement code offshore

hybrid gust
#

Idk if this translates, but I had an issue when I had my virtual camera directly attached to the game object it was supposed to follow. Try making the virtual camera and the thing you want to follow different gameobjects?

queen adder
#

Oh yeah that could be it

abstract pelican
hybrid gust
#

Had that same twitching, except in 3d

ivory bobcat
queen adder
#

Heres my playermovement code if u want to just copy it

abstract pelican
#

What does this have to do with the virtual camera? If I don't aim, I move normally too.

queen adder
abstract pelican
#

the whole point is the coordinates when moving when the camera is always following the player.

queen adder
#

I do _rigidbody_velocity instead of hard coding the position

abstract pelican
#

There's clearly a problem with the fact that I'm using Camera.Main in the code, not the virtual one

ivory bobcat
abstract pelican
#

Most likely the movement is causing it to calculate the wrong mouse coordinates.

queen adder
#

Like Mayo said is the camera a child of the Player gameobject?

abstract pelican
queen adder
#

Ur not setting the position of the camera in that code u sent ur just accessing a method

queen adder
#

Does ur crosshair influence player movement at all?

abstract pelican
#

I'm specifying that the camera follow the player at all times.

queen adder
#

We know lol

abstract pelican
#

Because of this it seems to me that the camera when moving behind the player because of this the position of the mouse is dislodged

queen adder
#

But the rigidbody and camera run on different update ticks which could cause jittering

abstract pelican
#

and when the camera is static, the sight does not twitch and everything is normal with it

#

the problem occurs in the movement of the camera

#

what does moving a player have to do with it?

teal viper
#

Are we solving the jittering or the character not moving in the direction of the cursor?

ivory bobcat
#

The only thing we see moving in code is whatever crosshair is.

#

This doesn't have enough context

abstract pelican
#

if there's nothing wrong with the static camera? It's only a problem when it's dynamic.

teal viper
#

WASD?

abstract pelican
#

If I remove the player tracking and run, the sighting will be fine.

teal viper
#

Oh, so you're moving the character with direction keys? The cursor is unrelated?

queen adder
#

Ofc there is no jitter to a static camera?

#

Its the way ur moving ur character thats causing the jitter

#

Does the cursor influence the characters movement at all?

abstract pelican
#

as you can see the problem disappeared as soon as the camera became static.

ivory bobcat
#

What you see and what occurs in the physics frame are different.

queen adder
#

Try changing ur movement code

abstract pelican
#

the player is controlled via WASD, what does the control have to do with the problem with the dynamic camera?

teal viper
#

It's clear that your character jitters. It's just more obvious when a camera is following it

queen adder
#

Dont hard set the players position

ivory bobcat
#

If you have the camera follow the player your position with crosshair will no longer be accurate if it isn't occuring on the phyics frame.

hybrid gust
#

Doesn't cinemachine have a composer setting to keep an object in frame or smth? Instead of hard setting it

queen adder
#

Try this instead

clear seal
#

hello i am back :(
i was connecting the movement with animation and then my character doesn't work anymore
i used the blend tree in the animator and the animation i made were coming in models

queen adder
#

_rigidbody_2D.velocity = new Vector2(_move_direction, _rigidbody_2D.velocity.y);

#

Instead of MovePosition()

ivory bobcat
queen adder
#

Well in this case you can just do velocity = _move_direction;

#

I dont think his crosshair matters

queen adder
#

Its his player movement code

abstract pelican
#

You see, the problem is it's tied to the new input.

abstract pelican
queen adder
#

Alright lol

summer stump
#

I try to never have actual movement in the callback methods

#

Just cache values

abstract pelican
#

It's not about control if it's about the dynamic camera.

summer stump
#

Then USE them in Update or FixedUpdate

queen adder
#

The camera follows whatever movement ur doing

#

If ur movement is jittery the camera will be to

#

The camera just follows whatever the player is doing

teal viper
# abstract pelican

It seems like you have interpolation disabled on your rb. That would make it jitter.

queen adder
#

he turned it on

#

I asked him to earlier unless he turned it of

teal viper
#

Then it must be broken due to how they move.

queen adder
#

Thats what ive been saying lol

teal viper
#

I don't think character movement code was shared yet, was it?

queen adder
#

It was

#

Here

queen adder
clear seal
queen adder
clear seal
queen adder
#

Ur using the wrong PlayerInput

clear seal
#

how

queen adder
#

Show me ur Player Gameobjects inspector

queen adder
#

Im surprised you dont get error?

clear seal
#

i do

queen adder
#

Whats the error say

clear seal
queen adder
#

It only glitches when u aim it at a certain position?

#

Gold

#

Again

#

Read the error

abstract pelican
#

because the camera follows the player

#

If the camera is static and I run the character and aim, everything is fine.

queen adder
#

Right i understand it follows the player

clear seal
queen adder
#

What does the error say

clear seal
#

oh

abstract pelican
clear seal
#

my mesh does not have an animator?

queen adder
#

Thank u i needed that clarification actually

#

Were u not aiming in that clip?

teal viper
abstract pelican
#

I was aiming for all the clips

queen adder
#

But the clip you just sent looked fine?

abstract pelican
teal viper
#

What does "aiming" mean in your game? What does it do?

queen adder
#

The clip you just sent the camera was following the player so it wasnt static. And it wasnt jittering

#

So what did u do differently that time

abstract pelican
abstract pelican
queen adder
#

You mean the crosshair is jittering

#

Ok i see that

teal viper
queen adder
#

No no were confused

clear seal
abstract pelican
#

watch closely as the scope twitches.

queen adder
#

His crosshair is jittering

teal viper
#

Ah, okay

abstract pelican
queen adder
#

Dont assign the crosshairs position via the event system

teal viper
#

So the problem is not with the character

queen adder
#

Do it in update

abstract pelican
#

it happens when the camera is dynamic.

queen adder
#

Oh

teal viper
#

Wdym by "dynamic"?

queen adder
#

Follows the player

abstract pelican
#

If the camera is static, there's no twitching.

teal viper
#

So, when the camera moves?

queen adder
#

Ive caught up with his leango

abstract pelican
queen adder
#

When he says static he means it isnt moving

abstract pelican
#

Follow

teal viper
#

Jittering happens when an object is not moving(relative to the camera) at the same rate as the camera is rendering.

#

So, either you move the crosshair at the incorrect time, or the camera moves at the incorrect time.

clear seal
teal viper
#

If you make both update during a regular update, the issue should be fixed

abstract pelican
queen adder
#

I would just assign the crosshairs position in Update instead

teal viper
# abstract pelican

Also, Smart update is not reliable imho, since you don't know where it updates after all. Select a different option(preferably update or late update)

queen adder
#

Your updating it on the Inputs Event System from the cameras LateUpdate, which is following a players movement that gets called on FixedUpdate

abstract pelican
#

I don't want to use updates, I'm using the new management system.

queen adder
#

We know what ur doing bro lol

abstract pelican
#

what's the problem with using it here?

#

why then a new control system if it can't handle such a task why sit on the old control system?

teal viper
queen adder
summer stump
abstract pelican
teal viper
clear seal
#

foremost?

queen adder
#

just a saying

teal viper
queen adder
#

Is ur animator active?

#

Hows ur blend tree set up?

clear seal
#

nothing changed

queen adder
#

Let me see ur inspector for the blend tree

#

I cant help without more context

clear seal
queen adder
#

Again try moving ur mouseCurosr Position in Update instead

#

The new input system wasnt built to replace using Update. It was introduced for better input handling

#

Whats the value of the move vector gold

clear seal
#

this?

queen adder
#

Whats the value when u press a button

clear seal
#

(A)left = -1x and (D)right = 1x
(W)front = 1x and (S)back = -1x

queen adder
#

Debug.Log(inpt.move.magnitude)

clear seal
#

in the update?

queen adder
#

Yes

clear seal
#

wait are we talking about animation or movement

queen adder
#

Ur input code influences ur animators parameters

#

So i need to know if ur getting a value from input at all

clear seal
queen adder
#

What does that print

clear seal
#

from what i understand it's the move stuff in input manager

queen adder
#

Thats fine. What does it print when u press WASD

abstract pelican
#

In general, thank you who helped, had to make the sight on Update, did not know that unity has such problems

queen adder
#

Welcome to the game engine lmao

#

Its somehow the best and worst game engine ive used

teal viper
summer stump
queen adder
#

I can see how that would be confusing tho

summer stump
#

Even outside of Unity, you don't want callbacks to handle things that need to be done smoothly

clear seal
#

of x and y

queen adder
#

Which is ???

abstract pelican
#

I'm still wondering why no such guides are recorded, all I've seen is the old input and no virtual camera

clear seal
#

1, 0 or -1

abstract pelican
#

Youtubers, take a note that you need a video like this.

queen adder
#

Well ur speed parameter should never be -1

clear seal
#

1 when pressed w or d and -1 when a or s is pressed

clear seal
slender nymph
#

magnitude can never be less than 0

clear seal
#

it can

#

why not

queen adder
#

lmao

clear seal
#

it :(

queen adder
#

I cant remember if its supposed to be normalized or magnitude

#

Hold on Gold

#

Actually yeah

clear seal
#

see it's because s is the contrary of w and A is the contrary of D

queen adder
#

magnitude is the length of a vector

#

Lengths cant be negative

clear seal
#

yep

#

well hold on

#

do you know the plan stuff

slender nymph
#

aren't you supposed to be telling what your Debug.Log is printing, not what you see in the inspector for your Move variable?

slender nymph
#

if the log is not running then you have errors in your code that you are ignoring

queen adder
#

Gold

#

Bro i thought we fixed the error

#

Show me ur console rn

clear seal
queen adder
#

Show me ur console

summer stump
# clear seal it can

Magnitude is the length of the vector. If it is pointing 1 unit one way and shrinks to 0, then starts growing the other direction, the magnitude goes UP from 0 (still positive)

slender nymph
clear seal
queen adder
#

So it does say the value

slender nymph
#

it is mathematically impossible to be less than 0

clear seal
#

i tough of that when i heard the lenght stuff and negative

queen adder
#

Thats not the length of something

#

Thats just a X Y Coord

#

Length isnt even 2D?

summer stump
# clear seal

If a vector is at 0,0 and ends at -10, 0 the magnitude is 10

clear seal
#

that's what i tought of

queen adder
#

All good

#

Then theres something else wrong

clear seal
#

what is it

clear seal
#

ok

queen adder
#

And make sure they arent the same thing

clear seal
#

um i imported the animation like that

queen adder
#

Wheres the other animation?

clear seal
#

i gotta do quick tho cuz it'S almost midnight

queen adder
#

Also thats a prefab not a animation?

clear seal
#

just th problem is i imported the prefab with the animation

queen adder
#

I dont think thats right

#

Go to ur animator tab click on the blend tree state then click on one of the states inside of it

#

Click on the reference to the animation from the inspector

clear seal
#

ye

queen adder
#

Send me a screenshot of the entire inspector please

clear seal
#

i cant rename it tho

queen adder
#

Do u see the animation clip

clear seal
#

ye

queen adder
#

Screenshot it

clear seal
queen adder
#

Thats just a preview window

#

Show me a screenshot of the animation clip. Its a Asset

clear seal
#

directly from blender or

#

oh ok

queen adder
#

There we go

#

Can you play those animations in the animation tab

#

Make sure theyre different

clear seal
#

walk animation

queen adder
#

Are they different?

clear seal
#

well i did not make an idle animation i just took an animation next to it that did not do anything

queen adder
#

Ok

#

Go to the animator Tab Go inside the blend tree

#

Play the game press the WASD keys the speed variable inside the animator should change

clear seal
#

ya

#

it changed

#

to 1

queen adder
#

Share a video

clear seal
#

but then i need to compress it

#

so it will take time

queen adder
#

Ok nbvm

#

Do u have windows?

clear seal
#

yep

queen adder
#

press printscreen and then screen record

vast ivy
#

How can I set the y coordinate of a cube to spawn on the top of a plane? I have a Tree prefab made up of 2 cubes and I want to place the tree ontop of the plane. I tried adding the height of the Tree prefab to the plane.y.max but it still didnt work

queen adder
#

The file shouldnt be that big

teal viper
clear seal
#

i honeslty dont think these guy will let me

queen adder
#

U can just use prtscrn and screen record then

teal viper
#

You can download it. It's free

queen adder
#

What toaster are u on?

#

Jk jk

#

How much ram do u have?

#

Are u on a laptop?

clear seal
clear seal
queen adder
#

Makes sense

#

Unity is pushing ur GPU to its limits

#

But anyways

clear seal
queen adder
#

haha lol

teal viper
queen adder
#

Does the speed parameter reset to zero when u release WASD

queen adder
#

Idk then

#

Theres something wrong the animations then

#

The code part is fine

vast ivy
clear seal
#

well the animation does not play at all

queen adder
#

Thats because theres something wrong with them

#

Its not a code issue anymore

teal viper
queen adder
#

its something wrong with the hiearchy or animation

clear seal
queen adder
#

Because the parameter is doing whats its supposed to

clear seal
#

but tmrw

queen adder
#

dont do that

#

Well then have a good night

#

Ill try and help u again tommorow if i can

#

At least the code issue is gone

clear seal
#

i did not leave my seat for 10 hours straight

queen adder
#

Same tbh

#

Ive been here all day

#

I gotta touch grass and get a life

clear seal
#

same

#

anyways see ya tmrw

queen adder
#

Have a good night bro

fringe plover
#

Sup, i tried to use rb.MovePosition instean of rb.velocity for my character controller, but now character just go trough some other objects, is there any way to fix that?

#

It multiply current position with input, so, i can use rb.Addforce and etc

teal viper
fringe plover
#

Oh..

#

Okay

teal viper
#

There shouldn't be any reason you can't use velocity or add forces

supple citrus
#

The box on the left is itemPrefab

#

How come when i instantiate one, its massive? lol

teal viper
supple citrus
#

That is exactly what it is

#

ty

#

How do i fix it :v

#

Changing canvas render mode to world space gives an error when i run it

teal viper
#

You don't. There is no problem

supple citrus
#

How do I instantiate one of the same size as the referenced one

#

I thought that would be the default

teal viper
#

Not sure what you mean by that.

#

This is the default.

#

Did you have a look at the game view?

supple citrus
#

In the first image, the i made the box manually at the size I wanted it

#

Then i referenced it in a script and instantiated it

#

And the instantiated one is hundreds of times bigger

#

How do I instantiate one of the same size as the original one that I referenced

teal viper
supple citrus
#

I thought when I instantiated a referenced object, it would be the same size as the referenced object itself

teal viper
#

No, I mean the game tab

supple citrus
#

Well you cant see it

teal viper
#

Can't see what? The ui or the other stuff?

supple citrus
#

The instantiated preset, its off the screen and massive

#

Maybe i am misunderstanding

teal viper
supple citrus
#

Inside the red circle is the camera that you see. The massive instantiated object is outside the red circle

#

Why would i be able to see it in game tab

teal viper
teal viper
supple citrus
#

But why is the original one normal

#

Normal sized on both Game tab and Scene

teal viper
#

Probably becasue you scaled it down. It wouldn't be visible in the game tab.

#

It would occupy like a 1-2 pixels on the screen.

teal viper
# supple citrus Normal sized on both Game tab and Scene

Canvas ui renders in screen space, meaning it's size is in pixels on your screen. If you want it to occupy half of your screen at 1920 x 1080, it would have a size of 960 x 1080 units. World space objects rendered by the camera, are measured in units and occupy different space on the screen, depending on their distance from the camera as well as the camera size(if it's orthographic). If your camera size is 10, and you want a world space object in front of it to occupy half of the screen, it would need to have a size of 5 units.
Now, when you look at things in the scene view, your world space object is 5 units, but your ui is 960 units wide despite both occupying half of the screen in the game tab.
Makes sense?

supple citrus
#

But When I changed the Canvas' render mode to world space theyre still massive

teal viper
#

Yes, because now your ui is measured in world space, not in screen space.

#

Understanding?

supple citrus
#

No because if its massive when the Canvas mode is in Screen Space and its also massive when the Canvas mode is in World Space, then I dont understand the difference or how to make it not massive lol

woeful seal
#

i am in an organization and my friend is inside the project, and i have full access and a seat, but how do i join the project itself and help him in real time?

teal viper
teal viper
woeful seal
#

no one answered in general

supple citrus
#

I want to instantiate multiple of them to be in a scrollable though

#

And i dont know what to do because in scene space theyre massive and in game view theyre invisible

woeful seal
#

this is literally the only active channel

teal viper
teal viper
supple citrus
#

Im confused about everything

#

Im just asking how do i instantiate one the same size bruh

teal viper
#

They are probably the same size.

supple citrus
#

Because the one on the left is the same size in both scene and game view

teal viper
#

You should share more info though, because nothing is clear from that screenshot

supple citrus
#

like what

#

I havent really done anything yet

#

except make the object

teal viper
#

Well, the editor window. I've no clue what screenshots depict a scene view and what depict game view. It's also not clear what object is selected and what components it has. Or it's transform position/size

#

basically nothing is clear

supple citrus
#

The entire thing is preset Item

#

Preset thumbnail is the white box, its going to be an image

#

name and date are the 2 texts

#

I want to instantiate an entire preset Item

teal viper
#

Can you just take a screenshot of the whole editor window..?

supple citrus
#

scene or game

teal viper
#

Both

supple citrus
teal viper
#

Where's the inspector?

#

That's not the whole window

supple citrus
#

if its too small ^

teal viper
#

What's too small?

supple citrus
#

If the writing in the image was too small

#

I sent a zoomed ver

teal viper
#

It's 193 x 175 units. Assuming it's on a screen space canvas, it should be visible in game view.

teal viper
supple citrus
#

Yes this is the original one that I made

#

When I instantiate one, I want it to look exactly like htis

#

This one is visible in both

teal viper
#

Take a screenshot of the instantiated one then(the whole editor window again)

supple citrus
teal viper
#

It's size seems fine but the position is way off

#

Also the scaling is off

#

The orignial has a scale of 1

#

This one has a scale of 61

supple citrus
#

Yes... its massive

#

That is my issue :v

teal viper
#

Well, figure out what makes it's scale go up

supple citrus
#

I have no idea lol

#

this is literally all of the code

teal viper
#

Take a screenshot of the prefab

supple citrus
#

I just named it weirdly

teal viper
#

Also, where is that code?

#

What component/gameobject is it on?

supple citrus
#

I stuck it on a scroll view

teal viper
#

Take a screenshot of the scroll view as well then

supple citrus
teal viper
#

And of the prefab(I asked it earlier)

#

As well as of the canvas

supple citrus
#

There is no prefab

#

I just named it this because I am stupid

teal viper
#

Okay. Then the canvas

supple citrus
#

I tried setting Render Mode to World Space but nothing changes

#

Well actually it gives an error and corrupts the scroll view

#

So i have to delete it and replace it lol

teal viper
#

The issue is probably due to it instantiating outside of the canvas with normal scale. Then when you parent it to the canvas(which has scale of 0.01), it tries to keep the previous size by adjusting the local scale.

#

You should really use a screen space overlay canvas if you want as little problem as possible.

#

Alternatively, pass the parent into the instantiation method, instead of parenting later manually.

supple citrus
#

This worked lol

#

same size catcool

#

ty

south jay
#

ive used Debug.Draw to show when the Raycast is true or false. For some reason it will be true even when it passes through a box(has a collider) that it previously was false to.

public class RayCast : MonoBehaviour
{
    private Vector3 direction;

    [Header("Customizations")]
    [SerializeField] private float distance;
    [SerializeField] private float amountOfCasts;
    [SerializeField] private float timeInBetweenEachCast;
    [SerializeField] private bool showCastAttempts;

    private float hitNumber;
    private float castNumber;
    void Start()
    {
        hitNumber = 0;
        StartCoroutine(Raycast());
    }

    //coroutine that casts the ray
    IEnumerator Raycast()
    {
        direction = UnityEngine.Random.insideUnitCircle.normalized;
        RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, distance);
        castNumber++;
        if (showCastAttempts)
            print("Attempt#: " + castNumber);

        if (hit.collider)
        {
            hitNumber++;
            print("Hit" + hitNumber + ": " + hit.collider.name);
            Debug.DrawLine(transform.position, hit.point, Color.red,2f);
        }
        else
        {
            //Debug.DrawLine(transform.position, direction * distance, Color.green,1f);
        }

        yield return new WaitForSeconds(timeInBetweenEachCast);

        if (hitNumber < amountOfCasts)
            StartCoroutine(Raycast());

    }
}
#

I have the number for "hitNumber" in inspector set really high so it continues on for the sake of troubleshooting

teal viper
#

Why is it commented out?

south jay
#

I have the green ray draw in the direction that is randomly decided by this code :

direction = UnityEngine.Random.insideUnitCircle.normalized;
#

and it continues on for the "distance" which is set in the inspector

teal viper
#

Try moving the raycasting logic to an Update or fixed update.

south jay
#

okay

teal viper
south jay
#

sorry i was troubleshooting after i recorded the video lol. I have absolutely no idea what im doing

#
public class RayCast2 : MonoBehaviour
{
    private Vector3 direction;

    [Header("Customizations")]
    [SerializeField] private float distance;
    [SerializeField] private float amountOfCasts;
    [SerializeField] private float timeInBetweenEachCast;
    [SerializeField] private bool showCastAttempts;

    private float hitNumber;
    private float castNumber;
    private bool cast;
    void Start()
    {
        hitNumber = 0;
    }

    private void Update()
    {
        while (cast)
        {
            direction = UnityEngine.Random.insideUnitCircle.normalized;
            RaycastHit2D hit = Physics2D.Raycast(transform.position, direction, distance);
            castNumber++;
            if (showCastAttempts)
                print("Attempt#: " + castNumber);

            if (hit.collider)
            {
                hitNumber++;
                print("Hit" + hitNumber + ": " + hit.collider.name);
                Debug.DrawLine(transform.position, hit.point, Color.red,2f);
            }
            else
            {
                Debug.DrawLine(transform.position, direction * distance, Color.green,1f);
            }



            if (hitNumber == amountOfCasts)
                cast = false;
        }
    }
    
}
teal viper
#

Unless you want an infinite loop

south jay
#

yeah that makes sense

gaunt ice
#

no infinite loop
btw use for loop, no need to have a bool cast

teal viper
#

Ah, they were setting the bool in the loop. I thought it was set in the inspector.

gaunt ice
#

probably can enable the while loop back with a bool....

south jay
#

yeah the while breaks it, but there is no need for a while because it is in the update function

teal viper
south jay
# south jay

this is what happens when i replace the "while" with "if" still so significant improvements

teal viper
south jay
#

yes

teal viper
#

Can you take a screenshot of the object that emits the rays as well as one of the colliders?

south jay
#

and my problem here is that it works perfectly when its situated on (0, 0, 0) but when I move the entire hierarchy away from the origin it breaks

teal viper
#

Also, are you moving it on the z axis?

gaunt ice
#

show the inspector of the rectangle

arctic ibex
#

!code

eternal falconBOT
south jay
#

I was watching a tutorial earlier and he used rigidbody 2d as well as the collider, but i didnt think the rigidbody was needed

#

the inspector is on the right

#

you have to click on the image

teal viper
arctic ibex
#

I have a distance joint 2D that is supposed to increase/decrease with the Vertical raw axis, but for some reason it moves in really slow jump skip things, instead of smoothly and quicklt. Any one know why? The code is in the Lasso() method

https://gdl.space/vaxefekege.cs

teal viper
# south jay
How far are you moving it?
Also, are you moving it on the z axis?
#

And how are you moving it.

south jay
south jay
#

by selecting everything in the hierarchy and using the move tool

teal viper
#

So the screenshots that you shared is after moving?

arctic ibex
south jay
#

yes, before moving (when it was working) the circle(player in this case) was on (0, 0, 0) the goal is obviously to have the player move and when i move the player the Raycasts seem to be aiming towards

teal viper
south jay
#

how so?

teal viper
#

Adjust the green ray like that:

Debug.DrawLine(transform.position, transform.position + direction * distance, Color.green,1f);
gaunt ice
#

oh i didnt notice that

#

or replace it by draw ray

teal viper
#

Me neither. The fact that it worked at origin rang a bell though

teal viper
arctic ibex
#

Yup, ten seconds

south jay
#

okay so that code was a test for a larger problem, and i tried your fix for that and it didn't work. Give me a few minutes ill explain

arctic ibex
#

if that wasn't obvious lol

teal viper
teal viper
arctic ibex
#

Yeah

#

BU tin the build it does the movement in tiny slow jumps instead of smooth movement

teal viper
#

It's a common issue if your code is framerate dependent. Build and editor would have different frame rate.

south jay
#

this is the rest of the code that got cut off

arctic ibex
teal viper
south jay
south jay
# south jay

this happens only if the player(circle) is on (0, 0, 0) but if its anywhere else the enemies(dots) spawn randomly, the red boxes are also supposed to be obstacles in the world

teal viper
#

Please explain the issue first. I don't see any problem in the video

#

As well as confirmation wether the original issue is fixed

south jay
teal viper
#

Also, share !code properly

eternal falconBOT
gaunt ice
#

it hurts my eyes
btw your ray seems not constructed properly

#

you define the spawn coordinate by dir*dist+tf.pos then raycast from tf with direction spawn coordinate
if i didnt misread

south jay
#

okay nevermind, i figured it out. Thank you

south jay
magic pagoda
#

I currently have this enemy script with NM+, and Im trying to make the enemy's sprite flip whenever it moves in the opposite direction, but its not really the most accurate (flips when its not supposed to sometimes)

anyone got a better way of doing this?
https://paste.ofcode.org/ktaMiDSksEg5m2BW8appqE

south jay
#
public class RayCast : MonoBehaviour
{
    private Vector3 direction;

    [Header("Preferences")]
    [SerializeField] private LayerMask worldObjects;
    [SerializeField] private float distance;
    [SerializeField] private float amountOfCasts;
    [SerializeField] private float timeInBetweenAttempts;

    [Header("Info")] 
    [SerializeField] private Vector3 spawnLoc;
    [SerializeField] private bool showAttempts;
    public GameObject[] mobs;
    private int rand;

    private float hitNumber;
    private float castNumber;
    
    void Start()
    {
        StartCoroutine(AttemptSpawn());
    }
    IEnumerator AttemptSpawn()
    {
        rand = Random.Range(0, mobs.Length);
        direction = UnityEngine.Random.insideUnitCircle.normalized;
        RaycastHit2D hit = Physics2D.Raycast(transform.position,direction, distance, worldObjects);
        castNumber++;
        if (showAttempts)
            print("Attempt#: " + castNumber);

        if (hit.collider)
        {
            hitNumber++;
            if (showAttempts)
            {
                print("Hit" + hitNumber + ": " + hit.collider.name);
                Debug.DrawLine(transform.position, hit.point, Color.red,2f);
            }
        }
        else
        {
            if (showAttempts)
                Debug.DrawLine(transform.position, transform.position + direction * distance, Color.green,2f);
            spawnLoc = transform.position + direction * distance;
            Instantiate(mobs[rand], spawnLoc, Quaternion.identity);
        }

        yield return new WaitForSeconds(timeInBetweenAttempts);

        if (hitNumber < amountOfCasts)
            StartCoroutine(AttemptSpawn());
    }
    
}

this is the final code, and it works

arctic ibex
#

What does this error mean?

gaunt ice
#

consider

while(hitNumber < amountOfCasts){
  yield return 
}
shut spade
arctic ibex
gaunt ice
#

what is startcoroutine("start")?
starting itself without any yield return?

shut spade
#

doesnt exist in the code

arctic ibex
#

Oh my god I'm so dumb

#

I just did the wrong name

#

I forgot I named the coroutine "Spawn", not "Start"

gaunt ice
#

you should call the method not using its name

arctic ibex
shut spade
shut spade
#

nah, just askin