#π»βcode-beginner
1 messages Β· Page 223 of 1
just make sure u use the Reference name not the actual name
uh oh
but what about when you call GameSaved/GameLoaded
then is is set to SavingNotifier.SetActive(true);
what about your GameSavingNote anything destroy or change its active state
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?
it should not, the script is on a parent that NEVER gets destroyed and It is 100% not being called in other scripts
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 π
yeah it will be fine, as long pivot matches
like this
yes to which part
will it work if I save space by making them be in rectangles?
looks fine there, then would just add logs at every step
k so how can i unstretch my sprites
and ur certain Pause Menu does not disable ?
Ohh I thought you meant the Sprite Editor..
I did that, will do a test round and come back with results
then in that case no making them rectangles will resize it @lusty flax
yeah the PauseMenu Gameobject will need to stay active all the time
otherwise it will prevent hte coroutines from running
k so i remake the spritesheets but with spacing this time?
that counts its parent being disabled as well
wdym with spacing?
(to make each sprite a square)
make them rectangles there if you want to modify their "borders" of the rect transform
but in sprite editor
nope, the child background pauze does, Ive checked it
but as thought the give it a sec does get loaded
but the Invoke does not https://hatebin.com/ypfaagmcqu
so its working...
oh wait nvm wrong log srry
are you modifying the Timescale ?
might have something to do with it
Yes!
ah
I indeed am
wiil do it?
*for coroutine
because your pause was setting timescale to 0, WaitForSeconds was also pausing
aha!
WaitForSecondsRealtime ticks forward no matter what timescale is
but where do I put that in exacty?
because its not here yield return new WaitForSeconds(delay);
gives me an error
you replace WaitForSeconds with WaitForSecondsRealtime
exact same place, it takes the same args
yield return new WaitForSecondsRealtime(1);

thanks all! appreciate the effort you put in for me :)
Ahh, just came back in to see it.
Dang timescale! Didn't even consider it
yeah no one clued in till they saw other pause related things
like the menu
atleast was a easy fix once found, just replace the yield step
btw nice profile, listening to them now XD
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
its a Gojira album art right, been a while since i listened to any but great stuff
does the Invoke method also work whenever time.timescale = 0 if you use some trick to let it go by the timescale 0?
indeed
What does the error tell u gold?
Its a very simple mistake
It should say something about this method doesnt have a overload
Yep, From Mars to Serius
VEctor3 does not contain an constructor that accept argument 4(translated)
Saw them live, They are amazing
any how many things are you passing into it
I would bet they are, they make great stuff. but thats awesome
exactly ! almost got KOd twice in the pit
oof, only brooses I hope?
haha yea nothing major
but yeah offtopic sorry π lets move onto code
good good
I just wanted to say the same hahaha (but a bit of fun can be happening at times)
so is the StartCoroutine better than the Invoke?
because I donno what would be smart
(just in general speaking now)
Coroutines give much more control
its good for other things too
and do not involve stringly typed bs
can pass it args, and can do many things with it
esp good replacement if you are using InvokeRepeating and need a way to stop the loop/coroutine in general
can wait on time, frames, or a condtion or what ever you want
i dunno...
hmm I see
i tried replay it to understan
well thanks! I will take all off this into consideration
a Vector3 has 3 components to it, x y and z you tried to make one with 4
i SEE IT NOW
oh and they can be stored inside a variable Coroutine so it can be stopped any time.
but I am tired as hell, wanted to fix my bug and now its 3 in the mornin
yay :)
haha lol
i typed too fast
It was telling u the whole time
:/
Slow down and read the error more carefully
he can now move correctly
They usually tell u the exact error
like if it is being activated it could just be told NO and it will stop performing the delay?
yeah it can be stopped while WaitForSeconds is going on for example
or before it
good to hear! Looks dope
thats very usefull! thanks
but imma go now, thanks again for all the help :)
https://cdn.discordapp.com/attachments/763495187787677697/1211106170107076698/image.png?ex=65ecfd84&is=65da8884&hm=621b68dc74dd09335b4f62006ba79e4081fc70ee15c03ec686fdee2875111fcd&
https://cdn.discordapp.com/attachments/763495187787677697/1211106177505562664/image.png?ex=65ecfd85&is=65da8885&hm=6d333289bf58d0b9bf9f4f7f8550b8417aca65d12fc5896d43772a499efb58ca&
https://cdn.discordapp.com/attachments/763495187787677697/1211106479034073198/image.png?ex=65ecfdcd&is=65da88cd&hm=fdea2b79bd8ff359cd8e159675aca7df7cbc871934e5a068bbafdc72bcf9f9b7&
I have a camera focussed on only the red box but ReadPixels() returns a screenshot of the entire screen rather than just the bounds of the camera. What parameters do I pass to make it only capture the camera's region? Or is there a different function that does it? Anything really.
erm
I thought they would have embedded
awkward
uhhh im wary of clicking random cdn links
now animation part
What I would do instead is using a Render Texture
:)
then export that as the Screenshot
Whats up gold?
the smaller box
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
oh ok , and ur certain that simCamera is the smaller cam
instead of read pixels maybe copy the image directly from the RT to the texture
using GPU
How does one do this
Graphics.CopyTexture
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
they need the pixels anyway to save the image to file
yes, but it needs to read the pixels to do that
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
if the textures was already copied directly from GPU you dont need it(read pixels) to Save
https://docs.unity3d.com/560/Documentation/ScriptReference/Texture2D.EncodeToPNG.html
the other camera is main camera and its the whole screen
im 100% certain Im using the right camera
whats this
ah yes
its a method on your Texture2D
to apply the data you just read
call it after ReadPixels
apply is the thing that sends data to GPU
so thumbnail.Apply() ?
so you don't need it
you're not writing pixels and sending them to GPU, you're doing the other direction
_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
show one screenshow and I'll go check my code for this in the meantime π
Did you try debugging the pixel width and height and confirming that it corresponds to the expected area?
Apply() doesnt change anything
It was correctly screenshotting and saving the image just not capturing the right area
What does 0,0 even mean
What corner is that lol
maybe because because ur passing in the camera size instead of RT size
But wouldnt they be the same since I want the image to be exactly what the camera is seeing
hey im new what should i learn first?
Lower left corner:
https://docs.unity3d.com/ScriptReference/Texture2D.ReadPixels.html
RT size is the pixel size of it
you're missing the camera.render() bit
that is only needed because i use a disabled camera
!learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
i tell it when it capture a frame
oh ok ty
start with the Essentials path @night grove
!learn
:teacher: Unity Learn β
Over 750 hours of free live and on-demand learning content for all levels of experience!
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
I think it's more about controlling which camera is rendered at the time
it is not that part is based on where you assigned the rt
(because I have it too π but that's code I wrote ages ago, so π€·ββοΈ )
Does it even matter which camera its using, as long as I pass the correct region as a Rect into the ReadPixels function, no?
Do you though?
textures are all about pixels
Can I convert the rect at once or do I have to redefine it with pixel coords
No I dont
and what that is relative to your screensize
I have no idea what a rt is loool I just want to export a screenshot as a file
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
:squinting
IF simbounds was the correct region, would this work
How to post !code
π Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
well the rect arg is the rect in the RT you want to read, the other 2 zeros are where to put it in the texture
I keep seeing this
The issue is in that block for sure, but if you insist in seeing the whole code....
ive used SimBounds elsewhere and it definitely is the right region.
But the code gives this
maybe the shader does not support alpha? π€·ββοΈ
And im guessing this is a screenspace/pixel issue
We can't see the line numbers.. and the image hurts the eyes.
Time.deltaTime shouldnt not be used for timers right?
The shader is being modified by the keywords to allow for transparency
nothing wrong with using it for that
But thats not the actual time and wont the timer change depending on frime rate?
Shouldnt the timer always be consistent?
no the timer will be consistent
across low / high fps
Hope u guys dont mind
But im gonna test so i can set my mind to ease
Ill post results here
Since I have no idea why its capturing the wrong area, is there a way I can just crop the image after lol
Don't trust yourself, sometimes you are an absolute troll
just find out what the problem is! π
i made animations using spritesheets. How do I implement them now? How do i make them play when the player does a certain thing?
public float Timer;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha1))
{
Application.targetFrameRate = 4;
}else if (Input.GetKeyDown(KeyCode.Alpha2))
{
Application.targetFrameRate = -1;
}
Timer += Time.deltaTime;
}```
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
My class is similar to that
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}");
}
}```
I recommend against - if you wanna do this (programming / game dev), you need to learn to code and to debug and all that
I didnt think about switching framerates on the fly like that tho. Thats smart im about to steal
Something wrong with mine?
Very true, however sometimes I'm just too stupid to figure it out on my own
why you say that
what does this prove though people do the deltaTime add when you want to start tracking time from a certain point, and wnat it to start at 0
No no im asking before i test
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
btw Time.time is total time since simulation ran
pretty sure they are just gettin confused with screen coords vs coords into the render texture and texture
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
Render() changes nothing and it returns the entire screen no matter what size or where the camera is. I just don't know how to pass the SimBounds rect I have to ReadPixels() because every time I do it returns some error
quite possibly... so yeah, they should play with them until they understand what's going on π that's what I'd do and suggest at least
it "returns" error?
well do you ever assign the render texture to the right camera
Maybe im overthinking it
Github Copilot > Microsoft CoPiLoT
What's your worry?
is that this? :v
Never used it so I cant say
no, that is just the active target for the readpixels call
well one is actually helpful, the other just makes stuff up most of the time
Lol
Something stupid dont mind me tbh
I dont actually want the texture to be rendered onto anything though I just want to save the image as a file
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?
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
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.
depends on the shader, maybe it's not using the mat for alpha π€·ββοΈ
Results
will want to get the activeTexture from the camera
This is a fading object: https://gdl.space/ilenosuvow.cpp
set that to rendertexture.active then read that into the texture 2d
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
Make sure to read the rest of what I wrote
try testing against a real life timer lol
I'm not sure that's correct... now I wanna try it π
i telling you its pretty accurate maybe few ms off
you're comparing apple and oranges
yours re suspiciously off, tbh
i cant see what your test is trying to prove though
I mean any of the color parameters on my graph do anything to the alpha value of the shader; but I though the main color overall (_Color) that comes by default would have its alpha value linked to the alpha value of the shader
I could be...
like what are you expecting your test, to test?
Im testing to see if .deltaTime is good for timers
I did, this is working perfectly fine with any default material in Unity, even if they are many in the same object, that should not be the issue
Like if deltaTimes...time is actual time passed
compare the Time.deltaTime += float to a realTimer
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
like the one on your computer
that will differ too, since deltaTime is frame based a system timer is not
deltaTime is nothing more than "compensating" for the frames.
Ill test deltaTime with a timer on my phone
strange they were pretty close for me
maybe few ms off
delaying in my clicking mostly
will be close but up a frames worth of time off
and can accumlate
true
ya you're still depending on the Update loops at the end of the day which is still tied to FPS no ?
deltaTIme is how long the last frame took, time.time is just summing all of that since startup
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
I mean i did test it at 4fps before and it was pretty close to 60fps too
also the different in time and deltaTime you see is related to startup time
but yeah like mentioned wont be totally accurate.
if you need real accuracy use Datetime and compare those
that or any of the system timer classes
will be more tied to your systems clock then frames
oh yeah StopWatch works too right ?
yeah
that would not effected by frames
well aside from that you are starting and stopping it in unity code
that is frame based
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
Deep stuff
Time.deltaTime shouldnt not be used for timers right?
That would be the delta between each frame. If you add all of the deltas up, it would yield how long the app has been running (excluding the instructions done this very frame before the line of code has been called)
and assuming you started adding it up at the same point time.time starts ticking
it's good enough if you're measuring things in seconds, I guess
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
Expect some floating point errors though if you're simply accumulating values and comparing it to total elapsed time 
Refer to time stamps with caches of Time.time, if the precision is important.
well even time.TIme is only 32bit
Any ideas why I'm getting a UnauthorizedAccessException: https://pastebin.com/hcgJ5UWK
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
so will get weird for long sessions
there's timeAsDouble now, no?
ah did not know about that
usually that means bad path
didnt look at code yet though
In this case my path is a folder inside the project files
I added a virtual camera, now when the player moves for some reason the sight is twitching, how to fix?
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
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....
print the path, also make sure its saving as a file instead of just the folder
Arithmetic with floats will likely yield a value different from what you'd expect. Aassignments and differences would be a bit more accurate.
Assets/Scenes/Inventory Icon Screenshot Tool/Screenshots
well yeah would never want to do direction comparisons
and why no one uses float or double where you need to be perfect
no file name ?
also are you taking screenshots of inventory items ? I got a tool I made a while ago if you need that
Should be Application.PersistentDataPath
its editor tool
I could kiss you
my cats will be jealous idk
just reminded me I should probably update this tool to UIToolkit and cleanup some stuff
Help guiys pleaes
Wdym twitching?
It twitches when moving, this came after I started using the virtual camera to track the player
Possibly my fault, but your tool isn't compiling for me
Might have something to do with ur camera settings? Also does ur character have a rigidbody or character controller?
interesting, can you tell me what you mean by "not compiling"
Well first off
Sorry should probably have said "endlessly compiling"
can't open the editor
Interpolation on the Rigidbody should be set to interpolate
And Collision detection Continous
2d game?
did you just drag the Unitypackage inside Unity Project window ?
and it started endlessly compiling?
Still needs to be set to interpolate
let me test this q
Double clicked, then I got some post processing something or other for like 2 min
huh that is strange. Im gonna test it again on 2022, but should still work fine..
yes
Still twitching?
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
Show a video of the problem so i can make sure, were talking about the same thing
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
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?
Use cinemachine
WASD
I told you it started after I added the virtual camera.
THANK YOU
it was camera.Render() after all
I didnt realise i had the camera disabled by default
use cinemachine
ok
so I uninstalled the virtual camera and the twitching went away.
Did u ever have a camera follow the player before cinemachine?
How do I fix this? I want to track the player and aim without jerking.
no
I dont think its cinemachine it always works for me in 2D projects
why doesn't it work though? I saw that cinemachine is a better alternative, but i'd like to know what the error was?
I've always used a virtual
Whats that script supposed to be on?
Ok show me ur playermovement code offshore
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?
Oh yeah that could be it
Had that same twitching, except in 3d
As is, you're teleporting some fixed pixels per frame. Perhaps consider using some sort of smoothing?cs transform.position = Vector3.MoveTowards(transform.position, mousePosition, speed * Time.deltaTime);https://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html (initial behavior would be a slow down so adjust speed as needed)
Heres my playermovement code if u want to just copy it
What does this have to do with the virtual camera? If I don't aim, I move normally too.
the whole point is the coordinates when moving when the camera is always following the player.
I do _rigidbody_velocity instead of hard coding the position
There's clearly a problem with the fact that I'm using Camera.Main in the code, not the virtual one
The player is moving with physics whereas the camera (assuming this input callback is being done on Update) isn't so you'll get jerks/micro-teleportations
Most likely the movement is causing it to calculate the wrong mouse coordinates.
Like Mayo said is the camera a child of the Player gameobject?
I don't have any jerks or anything, I have a problem with aiming.
Ur not setting the position of the camera in that code u sent ur just accessing a method
no
Does ur crosshair influence player movement at all?
We know lol
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
But the rigidbody and camera run on different update ticks which could cause jittering
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?
Are we solving the jittering or the character not moving in the direction of the cursor?
The only thing we see moving in code is whatever crosshair is.
This doesn't have enough context
if there's nothing wrong with the static camera? It's only a problem when it's dynamic.
WASD
WASD?
Oh, so you're moving the character with direction keys? The cursor is unrelated?
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?
as you can see the problem disappeared as soon as the camera became static.
No
What you see and what occurs in the physics frame are different.
Try changing ur movement code
the player is controlled via WASD, what does the control have to do with the problem with the dynamic camera?
It's clear that your character jitters. It's just more obvious when a camera is following it
Dont hard set the players position
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.
Doesn't cinemachine have a composer setting to keep an object in frame or smth? Instead of hard setting it
Try this instead
how do I fix it?
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
_rigidbody_2D.velocity = new Vector2(_move_direction, _rigidbody_2D.velocity.y);
Instead of MovePosition()
Have whatever crosshair is move in the fixed update loop as well.
Well in this case you can just do velocity = _move_direction;
I dont think his crosshair matters
Its his player movement code
You see, the problem is it's tied to the new input.
stop please
Alright lol
It's not about control if it's about the dynamic camera.
Then USE them in Update or FixedUpdate
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
It seems like you have interpolation disabled on your rb. That would make it jitter.
Then it must be broken due to how they move.
Thats what ive been saying lol
I don't think character movement code was shared yet, was it?
Here
can someone help me plsπ₯Ί π π
Gold does ur player move at all?
i does not move at ALL
Ur using the wrong PlayerInput
how
Show me ur Player Gameobjects inspector
Im surprised you dont get error?
i do
Whats the error say
It glitches when I aim on the move.
because the camera follows the player
If the camera is static and I run the character and aim, everything is fine.
Right i understand it follows the player
i red it again i dont see the error
What does the error say
oh
The camera follows the player
my mesh does not have an animator?
Then what the heck happens when you're aiming? How is that related to camera movement?
I was aiming for all the clips
But the clip you just sent looked fine?
Look at the video where the camera is standing still and as the aiming takes place the scope is not twitching there, and look where the camera follows the player and how the scope is twitching there
What does "aiming" mean in your game? What does it do?
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
the last clip where the camera follows the player and the scope jerks.
is that the scope appears and I can shoot.
How is it related to camera or movement?
No no were confused
these are half of my expectation
watch closely as the scope twitches.
His crosshair is jittering
Ah, okay
yes
Dont assign the crosshairs position via the event system
So the problem is not with the character
Do it in update
it happens when the camera is dynamic.
Oh
Wdym by "dynamic"?
Follows the player
If the camera is static, there's no twitching.
So, when the camera moves?
Ive caught up with his leango
When he says static he means it isnt moving
Follow
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.
they don't animate
If you make both update during a regular update, the issue should be fixed
I would just assign the crosshairs position in Update instead
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)
Your updating it on the Inputs Event System from the cameras LateUpdate, which is following a players movement that gets called on FixedUpdate
We know what ur doing bro lol
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?
That statements doesn't make sense. You can cache your input as you do now and only apply it in update. This is the correct way even with the input system.
Do u still have the error first and foremost
#π»βcode-beginner message
You WANT to use Update (and FixedUpdate) with the new input
I've selected different modes, it doesn't work.
You seem to be mixing things up. The new input system doesn't change how you move objects. Only where and how you querry input.
just a saying
Because that's only one possible factor..? The more important one is what vee is talking about.
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
Whats the value when u press a button
(A)left = -1x and (D)right = 1x
(W)front = 1x and (S)back = -1x
Debug.Log(inpt.move.magnitude)
in the update?
Yes
wait are we talking about animation or movement
Ur input code influences ur animators parameters
So i need to know if ur getting a value from input at all
done
What does that print
from what i understand it's the move stuff in input manager
Thats fine. What does it print when u press WASD
In general, thank you who helped, had to make the sight on Update, did not know that unity has such problems
Unity doesn't have a problem. The problem is caused by you moving the objects at wrong timing:
#π»βcode-beginner message
It's not really a problem, just the way it works.
Those merhods you were trying to do it in are CALLBACKS
I can see how that would be confusing tho
Even outside of Unity, you don't want callbacks to handle things that need to be done smoothly
it says the value
of x and y
Which is ???
I'm still wondering why no such guides are recorded, all I've seen is the old input and no virtual camera
1, 0 or -1
Youtubers, take a note that you need a video like this.
Well ur speed parameter should never be -1
1 when pressed w or d and -1 when a or s is pressed
well yes
magnitude can never be less than 0
lmao
it :(
I cant remember if its supposed to be normalized or magnitude
Hold on Gold
Actually yeah
aren't you supposed to be telling what your Debug.Log is printing, not what you see in the inspector for your Move variable?
the debug does not say it
if the log is not running then you have errors in your code that you are ignoring
no like it does not say if there is negative
Show me ur console
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)
again, magnitude cannot be less than 0
So it does say the value
it is mathematically impossible to be less than 0
If a vector is at 0,0 and ends at -10, 0 the magnitude is 10
that's what i tought of
what is it
Rename ur animations
ok
And make sure they arent the same thing
Wheres the other animation?
i gotta do quick tho cuz it'S almost midnight
Also thats a prefab not a animation?
ik
just th problem is i imported the prefab with the animation
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
ye
Send me a screenshot of the entire inspector please
i cant rename it tho
Do u see the animation clip
ye
Screenshot it
There we go
Can you play those animations in the animation tab
Make sure theyre different
Are they different?
well i did not make an idle animation i just took an animation next to it that did not do anything
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
Share a video
yep
press printscreen and then screen record
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
The file shouldnt be that big
You can record a short video with OBS studio, No need to compress anything if you have the correct format and settings set(the default should work)
i honeslty dont think these guy will let me
i dont have obs
U can just use prtscrn and screen record then
You can download it. It's free
idk all it says is 94%
ye
i think even more
haha lol
Depends on the pivot points of the objects. If they're at the correct position, you just need to get a point on the plane and use it as the spawn position.
Does the speed parameter reset to zero when u release WASD
I can set the y=2.4f which is the correct y coordinate but I was trying to avoid hardcoding it as I am trying to dynamically place it depending on the height of the terrain
well the animation does not play at all
Do a raycast down to the terrain and use the hit point position.
its something wrong with the hiearchy or animation
i might reimport the animation
Because the parameter is doing whats its supposed to
but tmrw
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
i did not leave my seat for 10 hours straight
Have a good night bro
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
MovePosition doesn't really respect collisions and should be used with kinematic rbs only.
custom physics queries
There shouldn't be any reason you can't use velocity or add forces
The box on the left is itemPrefab
How come when i instantiate one, its massive? lol
It's probably a ui element on a canvas which is in screen space and the rest of your game is in world space
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
You don't. There is no problem
How do I instantiate one of the same size as the referenced one
I thought that would be the default
Not sure what you mean by that.
This is the default.
Did you have a look at the game view?
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
Did you check how it looks in game view?
I thought when I instantiated a referenced object, it would be the same size as the referenced object itself
the game view is in the red circle
lol
No, I mean the game tab
Well you cant see it
Can't see what? The ui or the other stuff?
The instantiated preset, its off the screen and massive
Maybe i am misunderstanding
Not it's not
You are
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
Yes, because it's in screen space
Because screen space canvas renders independently from the camera
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.
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?
But When I changed the Canvas' render mode to world space theyre still massive
Yes, because now your ui is measured in world space, not in screen space.
Understanding?
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
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?
You'd need to adjust your canvas size in world space.
Ideally, you want it to be massive in screen space and not touch it.
Doesn't sound code related.
no one answered in general
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
this is literally the only active channel
Wait a bit more. Or clarify your question.
Check #854851968446365696 on how to ask questions properly and maximize your chances of getting an answer.
If no one answered there, no one is gonna answer here and it doesn't justify breaking the server rules...
With what setup?
Im confused about everything
Im just asking how do i instantiate one the same size bruh
They are probably the same size.
Because the one on the left is the same size in both scene and game view
You should share more info though, because nothing is clear from that screenshot
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
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
Can you just take a screenshot of the whole editor window..?
scene or game
Both
What's too small?
It's 193 x 175 units. Assuming it's on a screen space canvas, it should be visible in game view.
Ah, it's fine
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
Take a screenshot of the instantiated one then(the whole editor window again)
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
Well, figure out what makes it's scale go up
Take a screenshot of the prefab
I just named it weirdly
I stuck it on a scroll view
Take a screenshot of the scroll view as well then
Okay. Then the canvas
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
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.
oh
This worked lol
same size 
ty
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
Where do you draw the green ray?
Why is it commented out?
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
Try moving the raycasting logic to an Update or fixed update.
okay
I meant in code. I see that it's the commented out line now. I just skipped it since it was commented. Don't modify your code when you share it(in the video it clearly is not commented out).
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;
}
}
}
Change while to if.
Unless you want an infinite loop
yeah that makes sense
no infinite loop
btw use for loop, no need to have a bool cast
Ah, they were setting the bool in the loop. I thought it was set in the inspector.
probably can enable the while loop back with a bool....
yeah the while breaks it, but there is no need for a while because it is in the update function
this is what happens when i replace the "while" with "if" still so significant improvements
yes
Can you take a screenshot of the object that emits the rays as well as one of the colliders?
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
How far are you moving it?
Also, are you moving it on the z axis?
show the inspector of the rectangle
!code
π Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
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
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
How far are you moving it?
Also, are you moving it on the z axis?
And how are you moving it.
once the game starts none of the objects are moving, all i did was move it in the scene prior running it
How?
by selecting everything in the hierarchy and using the move tool
So the screenshots that you shared is after moving?
It works fine in the inspector, but it does this when built and ran
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
I think there is no problem actually.
how so?
Adjust the green ray like that:
Debug.DrawLine(transform.position, transform.position + direction * distance, Color.green,1f);
Me neither. The fact that it worked at origin rang a bell though
Kinda hard to visualize the issue without seeing it. Can you record a video?
Yup, ten seconds
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
Did it fix the green rays going through the colliders though?
So the issue is that it works differently in the build and the editor?
Yeah
BU tin the build it does the movement in tiny slow jumps instead of smooth movement
It's a common issue if your code is framerate dependent. Build and editor would have different frame rate.
You see, I knid of knew that, but I can't figure out how it's frame dependent, it's multiplied by time.deltatime
For starters, physics stuff should be in fixed update. Also, mixing transform movement/rotation with rbs is bound to cause issues.
Start from fixing these 2 issues: move Lasso method to fixed update and make sure that your rotate the rbs in a physically compatible way.
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
Please explain the issue first. I don't see any problem in the video
As well as confirmation wether the original issue is fixed
this is when the player is not standing in the origin
π Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
π Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
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
okay nevermind, i figured it out. Thank you
yes it fixed the issue
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
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
What does this error mean?
consider
while(hitNumber < amountOfCasts){
yield return
}
might be ure starting an non existant coroutine?
Why is it non existant?
what is startcoroutine("start")?
starting itself without any yield return?
doesnt exist in the code
Oh my god I'm so dumb
I just did the wrong name
I forgot I named the coroutine "Spawn", not "Start"
you should call the method not using its name
How?
also, r u working in a 3d game or 2d? cuz ure using vector3 and rb2d
2D, why?
nah, just askin
