#💻┃code-beginner
1 messages · Page 781 of 1
i believe that is not supported for security reasons misremembered
well hang on I want to use the LookObritX's inputvalue because it tells me exactly how much input is being put in there
If I can read it then it would be the same as the inputsystem
Well, yeah. That's where the input is.
That's what you want
What debugging steps have you taken?
Well, in editor and exe it works fine
The clicking and the image cursor that follows the cursor work fine
but why can't I just access it? I just want the numerical value from the input value in LocalOrbitX
Just the real cursor doesnt hide
Make a development build and add debug.log where you are hiding the cursor. THen check the javascript console when you run the game
There are no errors
That comes from the Input system.
That's the value it's reading from the input action you've told it to listen for
I don't know how to read it myself from the input system, it came packaged with it
I sent you a link to the Input System section of Unity Learn:
#💻┃code-beginner message
There's multiple ways to read from the Input System, so you can pick whichever one makes sense for your project
I didn't ask about errors
I've been reading it but I don't understand how it recognizes when there is mouse input
That's what the Input Actions map does
The thing you dragged in here
the input system can tell you when there's mouse input, or you can ask if there's mouse input
Ive found the reason, because WebGL can only make the invisible cursor after youve clicked once in the game, so it ignores this first hiding of the cursor
ok but how do I get it to recognize that there is mouse movement in a script?
You would read from the Input Action, just like this is doing
So, check out the link I sent for how to use the Input System
Not unless you share your code etc
Hey guys! 👋 Just dropped a quick guide on Unity Coroutines.
Check it out: https://youtu.be/jBLHdy9pExw
Stop writing messy code in your Update loop! In this comprehensive guide, we dive deep into Unity Coroutines. You will learn how to replace standard methods with efficient Coroutines, understand the power of different Yield Instructions, and master the best practices for starting and stopping them without errors.
Whether you are a beginner or l...
hi im new to unity i used to use python but idk where to start in unity can someone help
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
ok hang on I think I have something
you have unsaved changes
why cant I change the tracking target of a CinemachineCamera at runtime ? None of Follow, LookAt, Target is working am I crazy or
Should work. Getting any errors? Is the code actually running?
No errors and the code is running, this is one of the code I tried, found online
if (_camera != null)
{
CinemachineBrain cinemachineBrain = _camera.GetComponent<CinemachineBrain>();
if (cinemachineBrain != null)
{
ICinemachineCamera virtualICamera = cinemachineBrain.ActiveVirtualCamera;
if (virtualICamera is Component component)
{
var comp = component.GetComponent<CinemachineCamera>();
var temp = comp.Target;
temp.TrackingTarget = _transform;
comp.Target = temp;
}
else
{
Debug.LogError("Active virtual camera is not a CinemachineVirtualCamera.");
}
}
else
{
Debug.LogError("Main camera does not have a CinemachineBrain component.");
}
}
but i've also tried basic things like
_cinemachineCamera.Follow = _transform;
In play mode in the inspector the field stays empty
how have you confirmed that code is running
I put a Debug.Log earlier and it showed in console I removed it in what I sent
where was the log and what did it print. and for future reference don't remove logs when sharing your code
it was just below var comp = component.GetComponent<CinemachineCamera>(); and it was Debug.Log("Here", comp); it showed and when I clicked the log it pointed to the correct object in the scene
Ok nvm it works, I forgot to fill the _transform serialize field in the inspector
fck me
In my WebGL build, the video player doesnt run, anyone knows why?
Did you check the browser javascript console?
Ill try that
Embedded video clips are not supported by the WebGL player: Assets/Sprites/InicioFinal/Cutscenes/Cutscene Inicio.mp4. Use the Video Player component's URL option instead.
there's your answer 😉
Yup... What a pain
how would a virtual camera not be Component
not sure what exactly you're referring to, but i tried googling that for unity, and it gave cinemachine virtual cameras which did seem to be components
doing the as cast in an if is what i mean
as casts are for when you want to silently handle a failed cast
im confused, what's the issue here
oh, i didn't notice this was related to a previous convo
something something threads
you're referring to this, #💻┃code-beginner message, right?
CinemachineBrain.ActiveVirtualCamera is typed as ICinemachineCamera which is an interface
specifically if (virtualICamera is Component component)
very unlikely we decided to make our own virtual camera thats also not component
anyway its not that important
im so confused what you're trying to say...
well, i see CinemachineCamera implements ICinemachineCamera
are you trying to say the cast could just be to that instead of indirectly through the component?
or the else statement? i mean, it could be null
forget it i dont care enough
I recently made a new scene, but for some reason when clicking my next button, it does not respond and events don't change. I think this might be a mistake that I did in my code so if anyone could take a look, that would be awesome (:
where is the EventSystem
🤦♂️
i swear to god, i'm so dumb 😭
thanks man
Anyone knows how to hide a cursor in the WebGL build?
didn't you already get this figured out
Nope, thought I did
then show what you tried, because from what you've said you already know how
Im testing it another way now. The problem is that it takes a while to build webgl
When i click the notice board button or the staff room button, the character appears on screen, but the textbox does not appear. This is my assumption but i feel like i messed up with the eventPos. Could someone please take a look?
a quick glance over it and I don't see where you set the position of the textbox
ah, screenspace canvas
how can i fix the issue?
you'll need to go through and debug it
your code is far far far far too long, I'm about to go to bed so can't help further
You should be doing all that with 1 method and passing in the various params when you call the event
gng 💔
hi
im brandnew to unity and ive been trying to get buttons to work
does anyone know how?
visual scripting btw if that makes a difference
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
can you send a screenshot of your current setup?
really depends on what you want your button to do
that's a pretty broad question, you should start with researching
change the scene basically
or if you have a specific question, you'll have to ask
1s
You may want to provide more context but other than that, probably a question for the #1390346878394040320 server.
look up how to add a listener to a button and how to change scenes in unity
oh
thanks!
if the issue is with the detection of the button press, ask #💻┃unity-talk or #📲┃ui-ux
if the issue is with what to do after the button is pressed, ask in #1390346878394040320
My mistake, wrong channel.
(it's not a separate server anymore btw)
listeners are basically how you allow buttons to run methods, you can do whatever you want from there
its with detecting
ye ui buttons
Chris could you help me with this?
please do not try to get specific people to help you, just bump it to the channel as a whole
have you figured out setting callbacks
hi im so confused about something, so basically im trying to change the xr origin camera view so i can get a better anglee but when i do that in game my camera starts falling for some reason and it gets fixed when i reset it to the default coardinates aka 0,0
no ill research that
sounds like you don't have any work regarding the button so far, you should just find a tutorial yeah
are you using smthn like cinemachine or is this your own script
this doesn't sound like a coding question?
tru but i cant find a vr channel or smth
HUUH oo alr thx
oh god you still haven't fixed the code?
yeah i'm not sure what's wrong with it
the repetition
oh you mean the coroutines?
yeah i'm not sure how to narrow it down 😅
does the textbox have any content?
haven't i already told you
yes
there are lines for when the character speaks, and the name of the person
however, the textbox doesn't show up at all
what is the script that is hiding/showing it? there might be some kind of edge case where the logic to enable it doesnt get triggered or forced to hide every frame
check if the textbox is getting its content set at playtime.
i'm not asking whether you have content intended for it
i figured it all out im just dumb af 😭
same here pal
i found a 500 view tutorial (absolutely peak)
what was the issue, even
before the staff room and notice board buttons appeared, i made textBox.SetActive(false)
and i forgot to set it to true on the next event 🤦♂️
you should consider taking some time to just refactor this to make it more maintainable
is there a way to get my Y velocity (im probably just really stupid)
my objects y velocity*
on the same object or of a different object?
you get the rb and then you get its y velocity
thx
(you should already have a cached reference to the rb)
i forgot about the fact it needs to be rb
oh jesus
i made a jumping mechanic
why does it do this?
that's basically 0
This number is 0
😭
-1.212088E-08 = -1.212088 * 10^-8 = -0.00000001212088
it's scientific notation
ah
is there a better way to make a choice of a random animation other than adding more states at animator?
You can use Animator Override Controller and control the random animation via scripting.
https://docs.unity3d.com/6000.2/Documentation/ScriptReference/AnimatorOverrideController.html
interesting, would use in dire scenario
Anyone can help me understand why my character is not animating the idle state?
Probably needs an avatar configured and assigned.
I see
got it to work thanks my guy
im using cinemachine Third Person Follow. it follows my player fine, but how do I look around with my mouse?
do i use script or is there a component for that
If i use a script, how should up and down rotation be handled if the script is on my player? horizontal is fine, and I want the player to rotate along with it, but when I go veritcal, the whole player rotates vertically too
you look around by targeting something that rotates
so my target shouldnt be my player, it should be an empty gameobject that rotates vertically and horizontally with mouse movement?
well, if the head rotates independently from the torso you can target that too
otherwise you can do something like an invisible gameobject where the head is and rotate that instead
my player is just a capsule
is this how i rotate the target
should rotate
right if the head doesn't move then empty game object is the idea
also I'm not usually a big fan of the third person camera and instead use the orbital so try that too
basically third person camera with more properties
is the difference that you can do a 360
there's a lot of things you can do with it, but yeah it can be very loose too if you want it to be
can it do the same thing as a camera like in fortnite
I dont play that unfortunately but perhaps
I will try the orbital after but
would this approach work
The third person components target is an empty game object that rotates only up/down with mouse movement
then a script on the player manages left and right
So that the player can rotate left/right with mouse movement without the player rotating up/down?
yeah sounds standard enough
if the empty game object is child to the player then it will move along with the body of the player, thus repositioning
both the posittional and rotational modules can also target different objects anyway
oh wait I see what you mean. So you're saying you cant rotate left and righ with the mouse in fortnite?
some funky control scheme
huh
unless you do mean you can strafe with 'A' and 'D" but also rotate 360 with the mouse
no no no, essentially, a fps camera, but the camera is moved back so that its in third person
wait 360 yes but the player rotates along with the camera
right yeah that's standard. Orbital and Rotational Composer probably
Ive added those two components, how can I make it so that the camera rotation affects players left/right rotation too
so that the camera isnt just floating around the player
or should i figure that on my own
like I said, if the empty game object is child to the capsule then when you rotate the capsule player then the empty will rotate with it
what will make the capsule player rotate
my chinemachines target is the empty
you will make the capsule rotate (possibly through a rigidbody if you have a collider)
well, if this is standard 3rd person controller, then you should have a rotational constraint on the empty* that it can't rotate further than something like 75 (+/-) degrees
and the closer it is to those values the more the rotation of the capsule will move
rather 45 ish
how can i add a random int that have chances like 50% can i tried random.range but it doesnt have fixed chances
Random.Range has an approximately uniform distribution
you could use Random.value as well
does it make you edit the chances of happening?
no
random value gives you a float between 0 and 1
Are you doing something along the lines of loot boxes where each option has own chance of coming out? If so, how many options do you have? If a lot, you should look into "alias method" for O(1) complexity, if just few, if else chain (or loop given array of probabilities) should do
Something like this:
float value = Random.value;
if (value < 0.5) //50% chance
option1
else if (value < 0.85) //35% chance (0.85 - 0.5)
option2
else if (value < 0.95) //20% chance (0.95 - 0.85)
option3
else //5% chance (1 - 0.95)
option3
i am making a casino so i want like the bad luck is 50 etc...
and i have 5 choices
there is technically another option with AnimationCurves if you want to draw a distribution yourself, but that probably wouldn't be great for discrete outputs
Even with 5 choices, doing an if else chain may be quite prone to errors and hard to maintain (especially if you need many different distributions), 5 is also not nearly enough to make the alias method useful. If I was you, I would consider making a class like Distribution which you can create with different numeric weights for different values. Internally the weights can be stored as array of values normalized to add up to 1. You could then ask for numbers from the distribution where it would do the same logic present in the if else chain above, but by looping through the array instead
In it's simplest form it could work something like this: new Distribution(1, 5, 10, 17) (in this example the weights correspond to 0, 1, 2 and 3) where myDistribution.getRandom() would be 5 times likelier to return 1 (weight 5) compared to 0 (weight 1), and 2 times likelier to return 2 (weigth 10) compared to 1 (weight 5). I would prefer this kind of approach to not have to fiddle with the probability values by hand to always make them add up to 1
This is only very simplified example. In a real use case you would probably want to link the weights to a returned values too so they weren't just 0, 1, 2,... which would make you have to keep track of which value refer to which item/action
You could also just add a number from 0 to 100% for each item as possible weight distribution. Get all items weights combined, normalize them to 100/1 and get a random value from there. Bascially just remap your array of weights to a handleable sized dictionary and get your value back from there.
can i ask question about unity's visual scripting here? 'cause i'm struggling to play the animation although i have followed a youtube tutorial
Hello! I wanted to ask if there is a way for OnTrigger.../OnCollision... to be run on FixedUpdate instead, the document saids it runs on Update and it is unreliable with my custom tick system, it goes as follows:
NO MORE HELP NEEDED!
edit: nvm documentation is half flawed, they do run on FixedUpdate
what documentation did you see that said they were called during the regular update loop rather than the physics update loop?
you guys should really change this!
the hover thingy when you hover over it!
they should fix that!
ah yeah, in that case "frame" being physics frame because it is a physics message
yesss, they did not specify, my mistake!
to be pedantic, they run along with FixedUpdate in the fixed time step/physics tick, not directly on FixedUpdate - they run at separate parts of the physics update
man, I gotta do more Debugging then!
https://docs.unity3d.com/6000.3/Documentation/Manual/execution-order.html
they are called at the end of each physics update, but before WaitForFixedUpdate
this is a bit strange, at 0.1 they just freak out
which if used with my tick system, they might miss a tick
if you only ever expect to need two decimal places of precision you could just snap the value to the nearest 0.01 with Snapping.Snap
otherwise you would want to use some epsilon to check if a value is close enough, but of course how you address this entirely depends on what you are actually doing
How many 'website' LOLbins you have bookmarked lol
does anyone have any idea what this means because i didnt switch anything
!input and welcome to using a version that is 6.1 or higher
To set Active Input Handling, go to:
Project Settings > Player > Active Input Handling
• Input Manager (Old): Use the original Input settings.
• Input System Package (New): Uses the new input system package.
• Both: Use both systems.
i remember all of these actually lol
thanks boxfriend
public class RpgBullet : MonoBehaviour
{
[SerializeField] float force;
[SerializeField] float fieldOfImpact;
[SerializeField] LayerMask hitLayer;
[SerializeField] float BulletSpeed = 7;
Rigidbody2D rb;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
rb.linearVelocity = transform.right * BulletSpeed;
}
private void Update()
{
Explode();
}
private void FixedUpdate()
{
transform.right = rb.linearVelocity;
}
void Explode()
{
Collider2D[] objects = Physics2D.OverlapCircleAll(transform.position, fieldOfImpact,hitLayer);
foreach (Collider2D obj in objects)
{
Vector2 dir = obj.transform.position - transform.position;
obj.GetComponent<Rigidbody2D>().AddForce(dir * force);
}
}
private void OnDrawGizmos()
{
Gizmos.color = Color.green;
Gizmos.DrawWireSphere(transform.position, fieldOfImpact);
}
}```
i am making a rpg bullet
how can make it work well
i tried to make it when trigger enter 2d didnt work well also
What is the issue
It looks like it's doing exactly what your code says to do in that first video
see the video
i want it to have a high force like a normal rpg i made the force = 5000 still it doesnt make it high
Do the things being pushed have anything that sets their velocity
huh?
The things being moved. Do you have code that sets their velocity
nope it was for testing
i am calling it in the on trigger enter 2d
yeah why
ok, so use an instantaneous force
thats enemys
that overrides the force.
how do i use that
Because if you're setting the velocity to a specific value then it will become exactly that value, regardless of however much momentum they've gotten from previous AddForces
add a second argument specifying ForceMode2D.Impulse
ok let me try that
oh
You do want to use Impulse, but if you're setting the velocity to 0 every frame they're not moving, they're going to stop the instant the force is no longer applied
i added it
this is my movement code but when i press a key its like the ground moving up or somthing how to fix? https://paste.mod.gg/kzunrqftlvuj/0
A tool for sharing your source code with the world!
my charcter moving up a bit in the air and this is her ground
i made it = 0 before thats why?
oh shoot
nvm mb
transform.TransformDirection(Vector3.forward)
transform.forwardandtransform.rightexist btw
but is it the issue?
no, it's just something you could make more straightforward and easier to read and maintain
oh ok thank you
it could be part of the issue though if this object can pitch up/down
im gonna change one sec
then the forward vector wouldn't be horizontal
I don't know what the issue is. Your post seemed to indicate you were about to provide a screenshot or example of what you mean but never did
oh ok i will
also, you never reset the downVelocity other than when jumping.
i removed it but i want to make the velocity = 0 after explosion how can do it?
its stuck there i can move but cant hit the ground
So, you move like normal, but your character is always a bit above the ground?
Check to make sure your collider isn't bigger than your mesh
do a lava mode that the flor is lava
Make something original instead
yeah no
Any child objects with colliders?
im to stupid to
then you're not going to make games and you should either give up or stop choosing to be stupid
no
Can you show the full inspector of this object?
i have a lot of them but i can bearly make a player move
You seem to have two player movement scripts on this object, and one of them involves a "Ground check" object which is probably your issue
Where is that object in relation to the character
no its only one that is groundcheack alone no movement
player
That's not an answer to the question I asked
so i didnt get what you asked
The code you showed doesn't seem to use the ground check object at all so what is that script doing
Is there a reaosn why my 3D raycast isn't working?
private void PlayerGroundedCheck()
{
Ray groundRay = new Ray(transform.position, transform.right * 2);
isGrounded = Physics.Raycast(groundRay, 1f, LayerMask.GetMask("Terrain"));
//Draw debug ray
Debug.DrawRay(transform.position, transform.right * 2, Color.blue);
}
How often do you call PlayerGroundedCheck?
DrawRay by default draws it for exactly one frame
the other player movement is only a groundcheack idk why i called it this
if i recall
you didn't supply it
Okay and your issue appears to be that you're detecting ground when you're not supposed to be so maybe look there
supply?
why are you checking for the ground on your right
you didn't give that argument, so it's going to only last for 1 frame
There is a duration parameter. You didn't give it one.
but it's in fixed update. not even the debug raycast is showing up for me
But i'm guessing i don't have to touch it? it's a optional parameter which means it has a default value
the default value is 1 frame, as mentioned
Yeah, the default value is 1 frame. Since FixedUpdate runs on a schedule independent of the update loop, that frame might have passed before it actually has a chance to render it.
If depthTest is set to true then the line will be obscured by other objects in the Scene that are nearer to the camera.
consider setting that to false if you're worried it'll get obscured
Try giving it a higher value and see if you get anything then
I put it on update as well, it still didn't work.
Alright.
Are you looking in the Scene View window as opposed to Game View?
fixedupdate runs in the same cycle as update, just at a different interval. wouldn't you still be able to see it for any frame following a fixedupdate, just not every frame?
Yeah, but if it's on for a frame then off the next it's possible to just not notice it
Making it longer means it might double up but it would definitely show whether it's activating at all
oh true
this wouldn't be an issue if it were done in Update though right, if i'm understanding you correctly?
Nope. Raycast is suppose to be visible with gimzo, well atleast the physics2D raycast did...
Potential culprit would be gizmo not being enabled
Debug stuff shows up in scene view i keep forgetting about the gizmo thing making it show up in game view
Yeah that's a pretty common issue, sadly not the case here
Right. As long as it's unconditionally run in Update
It's weird, it's just not working for some reason lol
have you tried logging the position and going there in the scene view
Did you try a longer duration?
also make sure your objects are appropriately sized
Place a debug log in the function and see if it prints
I couldn't find the duration parameter but i swore i saw it somewhere
lemme try
you could see if it's actually showing in scene view. that'd tell you if it's a code issue or if you just need to enable something for it to show in game view
it's in the first and only signature that the docs gives
i remember there being some weird things about it not showing in game view lately but not sure if that was an actual bug that got reported
Well it's printing the direction correctly
so it's suppose to work.
Well, that would certainly suck, lol
look at it in scene view side by side with game view, see if it appears in one
even with longer duration it's not showing up
it does in scene view!
what. i've never seen that happen
make sure gizmos is actually enabled for game view
The line will be drawn in the Scene view of the editor. If gizmo drawing is enabled in the game view, the line will also be drawn there.
i Wish
having it in game is also more convenient
wait its not even visible in the screenshot lmao
but i can ensure you its not there
You should probably show us it being enabled
Check which gizmo elements are enabled
everything is checked.
No worries.
and i get your concern, it is really weird, and it's putting me for a loop as well
lol
it should be there in the gizmo
game view
worst part about this? raycast isn't even activating my bool..
does the ground have the proper setup
Yeah, it has the terrain tag
does it have a collider
Yeah. I don't fall off the map.
wait it's probably because i put the distance to 1
🤦♂️
nope..
what the fuck
can anyone help teach me scripting?
i know its a lot to ask but ive broken a finger punching my wall out of frustration
every tutorial is outdated and basically says i suck at scripting
As a practice project I'm trying to recreate pong, this is the code for the player paddle. Right now I'm trying to make it so if the paddle would move higher than 4 its position is just set to 4 so that it doesnt go off screen. Unity is unhappy with how im trying to do this and saying I cant just modify tranform.position.y and I am unsure about what to do
we can help troubleshoot issues you have with code, architecture, errors, etc., but unfortunately, this is not a one-on-one or tutoring platform . . .
when you modify y, you have to assign the entire position property. so it would be position = x, y, z (where only the y value is changed . . .
wait so how would I do that
wait, terrain tag?
that's not right
note that is pseudo-code . . .
90% of tutorials are not outdated enough to be useless
sorry modifying vectors is still kinda new to me
there are also resources pinned in this cahnnel
position is a Vector3. you need to assign a Vector3 to position. you cannot only change the y axes . . .
so would I create a vector 3 like [Vector3 paddlePos = transform.position] and then set it through that
transform.position = transform.position + new Vector3(0f, 4f, 0f);
I assume this is an abomination
yes, that's not how c# works
instead of assigning only the y value, you need to assignposition to a new Vector3 . . .
you should probably go learn some basic c#, there are resources pinned in this channel
Im still figuring it out
that's not the task
Ive been taking the microsoft thingy for it
this doesnt make any red
yes, technically, it's correct, but this adds to the position and will likely confuse them. i don't want them to think this is the correct way to assign a value (since they need to set/assign the position instead) . . .
this creates a vector3 correctly, yes
I updated the code to this but the paddle doesnt stop at 4 like it should
well, now paddlePos.y doesn't go above 4
but you want transform.position.y to not go above 4
you did it wrong . . .
oh wait I need to update the transform to paddlePos at the end then?
yay it works
alright
oh yeah since it is inherently a bool
that evaluates to true
its like saying true == true right
you really don't need paddlePos at all. you're just assigning the transform.position to the new vector . . .
yep
it's not inherently a bool, it just.. is a bool, outright
whats the issue there
it doesn't do the right thing
the desired effect was transform.position.y = 4, not transform.position.y += 4
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NewBehaviourScript : MonoBehaviour
{
public float moveSpeed;
public float jumpHeight;
public KeyCode Spacebar = KeyCode.Space;
public KeyCode L = KeyCode.A;
public KeyCode R = KeyCode.D;
public Transform groundCheck;
public float groundCheckRadius = 0.2f;
public LayerMask whatIsGround;
private Animator anim;
private bool grounded;
// Start is called before the first frame update
void Start()
{
anim=GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
// Jump
if (Input.GetKeyDown(Spacebar) && grounded)
{
Jump();
}
// Move left
if (Input.GetKey(L))
{
Debug.Log("Moving Left");
GetComponent<Rigidbody2D>().velocity = new Vector2(-moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
if (GetComponent<SpriteRenderer>() != null)
{
GetComponent<SpriteRenderer>().flipX = true;
}
}
// Move right
if (Input.GetKey(R))
{
Debug.Log("Moving right");
GetComponent<Rigidbody2D>().velocity = new Vector2(moveSpeed, GetComponent<Rigidbody2D>().velocity.y);
if (GetComponent<SpriteRenderer>() != null)
{
GetComponent<SpriteRenderer>().flipX = false;
}
}
anim.SetFloat("Speed",Mathf.Abs(GetComponent<Rigidbody2D>().velocity.x));
anim.SetFloat("Height", GetComponent<Rigidbody2D>().velocity.y);
anim.SetBool("Grounded", grounded);
}
void Jump()
{
GetComponent<Rigidbody2D>().velocity = new Vector2(GetComponent<Rigidbody2D>().velocity.x, jumpHeight);
}
void FixedUpdate()
{
grounded = Physics2D.OverlapCircle(groundCheck.position, groundCheckRadius, whatIsGround);
}
}
like i mentioned in #💻┃unity-talk, share your code appropriately please
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
see the "large code blocks" section
support is a 2-way street, mate. you gotta help us be able to help you.
i explained in the message. they're having issues understanding how to assign a value properly. though, your version works, it's adding to the current position, which is not their intent
this will cause confusion and can lead to them using it for every assignment, thus, receiving undesired results when the other axes don't match
yours works because you have 0 for the x and z values. you'd have to specifically explain why it works and the meaning of using those values . . .
oh , i thought we had to add 4 to its y
I removed it. Even without it. It still didn’t work
i try to press create paste but it doesn't work
try any other service
And you would be correct. I mistakenly used tag instead of layer
you need to have a terrain layer
working fine for me, but try another service
Yup that solved the issue.
Thanks alot.
Although, the debug raycast is not showing up in my game gizmos that's still weird.
I have a player object with a running script, and I have a jump platform with a jumping script. There is a bool in the jumping script that triggers a jump in the running script. The jumping script is referenced in the running script, but my problem is that when I turned the jump platform into a prefab, I expected the code to work for every jump platform. Instead, it only works with the specific object that is referenced in the running script.
How can I make it so that every jump platform works with the running script?
the instance of the running script and instance of the jumping script don't need to know about each other directly like that
you can make the running script detect the jump platform and react accordingly, or vice versa - depends on the design
It's working now, so I will send you the link of it right?
send it here, sure
a powerful website for storing and sharing text and code snippets. completely free and open source.
having each platform detect the player/entities would probably be easier to make it more extensible
wouldn't it be better to reference inside the clone script and get the running script from there on each instance
not sure what you mean by "clone script", but that would be tight coupling, it would make it harder to work with in the future
usually when you have prefabs it's better for the prefab to reference the script rather then referencing the prefabs
It is. each new instance of a prefab that has a script can simply run a code on awake that gets the component of a another gameobject , in this case a script.
ah, thought you meant with serialized references.
yeah, that's still not very good
Nah nah not serialized xD. And yes, there are definitely a million other ways to handle that, which i can bet a few pennies on that you know more then me about.
also i saw you on the aseprite discord server, i was kinda suprised. do you do pixel art?
i wish 😔
🫳
Hey, y'all, I'm newer to making actual games in Unity. I'm trying to make a game called "Multi-Paul" for a class project, and the concept is that each time you press a button (in this case: F), you respawn at main spawn and a clone is made following the path you made before the reset. Essentially like replaying a recording.
It's a puzzle game. I finished the first level, but I wanna implement a mechanic where when you can't see the clone anymore (due to an obstruction) you can see the outline of the clone through the object/ wall. This is because I also wanna make it so that you can destroy the clone when pressing E on it, even through walls.
I'm having trouble getting the outline concept to work. Can anyone help me out?
Record all the inputs and the frame number they were sent on. Then, spawn a copy of the player object and instead of getting input from a controller, they get it from the list of inputs
Ah, wait, I read further, you want the outline
how can i make the running script detect the bool in the jumping script without referencing it
That's going to be a Render Feature in URP, and you can set it to draw "After Opaques" to draw on top of it.
impossible without
collision or physics checks would probably be the easy way
A custom renderer feature for screen space outlines - Robinseibold/Unity-URP-Outlines
but yeah you'd be referencing it eventually, just not directly with serialized references
I'll try it out, thank you.
You wouldn't. You need to reference the thing you want to read a value from. That's what Referencing means.
you wouldn't be "detecting a bool" anyways, you could just either:
- the running script detects a jump platform, and applies a force/velocity to itself.
- the jumping script detects the player, and applies a force/velocity to it
not the issue, but just a sidenote: you should have the rigidbody and spriterenderer cached, instead of all those getcomponents every frame
There's like a million different ways to do outlines and they all suck in different ways, so if this doesn't work you might want to find another implementation
@fathom wind have you checked this? i asked quite a while ago
have you checked its transform to make sure it's actually not moving, or if it's perhaps moving very little?
How can I check it ?
With your eyes, Bert.
Look at the transform and see if the numbers are changing
So, it's moving?
have you tried checking the scene view
in case your camera and background are following the character
Yes it follows the character but it's move too slowly
What is your move speed set to
move speed 50 and jump height 25
And how big is the character
have you tried checking the scene view
When I post the link into unity, it doesn't show up. It loads for like .1s and then just shows me assets I already have.
That don't have any correlation.
Is it outdated?
Yes and when I play the game it start jump animation
that's not what i asked
check the scene view and see if it's moving
check if the camera and background are moving
also while you're at it, make sure your script is saved
Yes it's moving with the character
I save it the code close vs code
ok, so then the character is moving fine
it's just that the camera and background are moving with it, so there's an illusion of no movement
you probably don't want the background to move perfectly along with the player, unless it's a really far background for parallax purposes
I am a newb. I'm trying to figure out how to make boomerangs go in an arc
yes and I made a script for zoom camera so I can control the zoom too
you would also usually have the camera following with smoothing or with a bounding box rather than following the player rigidly
that's not relevant at all, but sure...
which part are you having issues with exactly?
have you tried researching that?
also, are you familiar with unity concepts in general yet?
I will removing the script from the character and re-adjusting the animation; that might be the problem.
instancing them is fine. the issue is making them go forward in an arc and then back. I've a degree of experience in setting up things like goombas and grabbable objects, but the boomerang trips me up
it is not.
ive already told you what the issue is
it's not the character
alright, what part of that do you have issues with?
designing the trajectory, figuring out the math, implementing it? etc
Figured it out.
the boomerang barely travels. i think it's its physics
!paste
There's no command called
paste.
im tryna make my character swing when they attach to a specific object via using a hinge joint 2d but when i do press the button which adds the component which connects them together they just stay in place
heres my code
A tool for sharing your source code with the world!
thank you , and does you know a good and creative one idea for puzzle
alright well if you have a specific issue you need help with, you're gonna have to give some info to work with
quick question what would be a good way to fix this i am just messing around no tutorials trying to get this working using System;
!code =
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
oh sorry
A tool for sharing your source code with the world!
There sorry did not know i was meant to do that
What’s wrong in your current code?
it moves on direction then just stops working
does it ahs any constrainstconstraints if it moves only in one direction
No does not have any
Put them inside Update
https://pastebin.com/rcRH1HVp this is how i set up its movement
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.
you might want to consider using coroutines here
it'd probably make it easier to work with
makes sense. i'm just scared they'll overlap
not sure what you mean by that
ah, i see. it's how the movement is calculated. it doesn't go in an ellipse at all, it goes in a v. No idea how i screwed that up
this is more complicated than expected
also consider making it parabolic rather than elliptical
which.. i guess are pretty similar
am I correct that: a Rigidbody cannot be temporarily "disabled" and then reenabled because the physics system doesn't like that? I want my player to have a mode where they are a drone, and I am using a Rigidbody with force/rotation applying functions, while also having a CharacterController component for easy walking around, but it seems Rigidbodys are not very good when attached to a CharacterController using gmaeboejct
They're mutually exclusive. You'll need to choose either CharacterController or Rigidbody
a Rigidbody cannot be temporarily "disabled" and then reenabled because the physics system doesn't like that?
this is not true
a rigidbody cannot be truly disabled, that's just not something it can do - not because the physics system doesn't like that, just that it's not a thing
what you can do is make it kinematic - but this disables physics simulations, not the entire rigidbody. it'll still be trying to control the transform afaik, so it'll still fight the CC.
you could maybe consider having the drone and walking forms completely separate
Or either remove the Rigidbody component and readd it?
Thnx I will probably have the drone and walking be separate, I am just curious on why RBs can't just be disabled willynilly like a normal component
components being disabled only mean anything if the code in said component actually cares about it (aside from some niche stuff like findobjectsoftype)
if there isn't any usage of stuff like Update, OnDisable & OnEnable you can't even toggle the bool in inspector
ohh so e.g. its just a tag
no but similar line of thinking yeah
you should not do that
technically disabling isn't part of components, it's part of behaviours
Component doesn't have an enabled prop
Behaviour does
oh yeah... they're all MonoBehaviour... i think i get it
anybody have tips on where to learn ?
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!

ah
thanks
damn it
i downloaded the wrong module
and it wont let me remove it 
You can't remove the installed module through Hub
i have to do it through files ?
yes

staff solution also says [its for android module but]
i did it through terminal

thanks for the help
So I'm trying to clamp a car so it don't roll over. I want it to lean and stuff, but I don't want it to be able to tip or flip. Unfortunately for me, my code seems to just make the car glitch out horribly. Been trying to figure this out for the past few days and I feel like I'm beating my head against a wall.
Vector3 localRotation = transform.localEulerAngles;
float localRotationZ = localRotation.z;
if (localRotation.z > 20)
{
transform.rotation = Quaternion.Euler(0, 0, 20);
}
if (localRotation.z < -20)
{
transform.rotation = Quaternion.Euler(0, 0, -20);
}
Is there any easy way to clamp this thing so it'll just lean and stuff and not like, tip over or glitch out? Thank you.
Perhaps you meant to retain the previous x and y values?cs localRotation.z = Mathf.Clamp(localRotation.z, min, max); transform.rotation = Quaternion.Euler(localRotation);
You'd probably still get glitches though as converting from quaternion to euler has some issues. For the best of results, keep a field to retain the actual rotation and simply apply it to rotation rather than reading the rotation from the Transform component.
can someone link me to a premade equation for gradient fractal perlin noise for terrain? i dont feel like doing hours of trial and error
I must have done something wrong. Car still flips.
Admittedly I have next to no idea what I'm doing. Only been dabbling with code for a few weeks now.
if you're using a rigidbody you can just freeze the rotational axis
I would, but I want it to be able to lean side to side a bit.
Yeah. But I figure if I can get Z, I can get X too.
It's the MotionSicknessMobile...
Like, at all times it's trying to set z rotation to 20. It kinda just flickers horribly. And my video of it won't go through.
https://docs.unity3d.com/ScriptReference/Rigidbody-rotation.html
If you're using rigidbodies then use its preferred rotation method as transform.rotation may be fighting with the interpolation
I'll need to give that a lookthrough after I wake up. Even if it doesn't fix it, it's at least information about what I'm doing wrong which is one step closer to getting it right
Thank you.
You can't read (or write) how much the car is tilted from the Euler Z rotation, it won't tell you that. You'll have to check the angle between transform.up and the ground normal (or Vector3.up) and rotate towards it if the angle is too large
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
bump
I have just imported a scene from the the other project, with the same version as my current one who was specifically boosted to match the version.
For some reason none of the colliders seem to work (projectiles just pass through)
Time to debug!
Yea, probably, but it's very weird cause it worked on the previous versions, colliders are in place tc
By debug: it doesnt even register the collision
how do you know that
Did you debug it without any tag or layer checks?
Debug.Log on attack that checks for enemies, this attack worked on previous unity project, now it doesnt register anything.
show the debug related code
{
AudioClip atk = null;
int r = Random.Range(0, 3);
if (r == 0) atk = audioManager.Atak1;
else if (r == 1) atk = audioManager.Atak2;
else atk = audioManager.Atak3;
audioManager.PlaySFX(atk);
if (Time.time < nextAttackTime)
return;
if (Input.GetMouseButtonDown(0)) // Left click
{
if(atacanimation)Swordanimator.SetTrigger("Up");
else Swordanimator.SetTrigger("Side");
atacanimation = !atacanimation;
nextAttackTime = Time.time + attackCooldown;
int totalDamage = baseAttackDamage + (abilities != null ? abilities.BonusAttackDamage : 0);
Collider2D[] hitEnemies = Physics2D.OverlapCircleAll(
transform.position,
attackRange,
enemyLayers
);
Vector3 mouseDir = (Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position).normalized;
foreach (Collider2D enemyCollider in hitEnemies)
{
Debug.Log("" + enemyCollider.gameObject.name);
....```
is that return happening and are you left clicking (can confirm via debug after thse conditions)
are the enemies the right layer of that mask
is that mask setup right
is this function even running
i mean, animation does play
the same exact code is in the well working version
so its probably something in unity itself
which could be any of the four things i mentioned
a debug log right before the foreach confirms that 1 and 4 are dead ends
you'd need to look in unity for 2 and 3
Ohhhh, the layer turned blank
that explains it
I looked at tags that... got imported normally?
I assumed layers did too
potentially not if those layers aren't defined in that project
not sure
(and defined in the right order)
Okay, i just added Enemy and Player layers and it filled it in automaticly
Gosh, i wouldn't have noticed for some time by myself
Now it works
Thank you!
no worries, remember all i really did was narrow down what could and couldn't be the problem
easy to do in the future 😄
Yea, i have some experience in Unity, but i took a break aside from 24h hackaton this project is from, and now im a little sleep deprived
gotta give some progress to my teacher today, i decided to hand in 2 things instead of 1
Idk if the grade in game programming will be any useful in the resume, but oh well, might as well try for that one subject
if not for anything else
Hi i've got something like this :
IEnumerator LoadExperienceHttp(string url_Complete)
{
Debug.Log("Url complete : " + url_Complete);
yield return new WaitForSeconds(1);
using (UnityWebRequest www = UnityWebRequest.Get(url_Complete))
{
yield return www.SendWebRequest();
if (www.result != UnityWebRequest.Result.Success)
{
Debug.Log("Erreur : " + www.error);
}
else
{
Debug.Log("Réponse serveur : " + www.downloadHandler.text);
}
}
}```
And since it's an http url, i have an "not securised connection, abort" error, so my question is, is there a way to adapt this code to http ?
https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.html
HTTPS is supported and the server certificate is validated against the root certificate store available on the system the app runs on. Validation can be disabled (for example, for development server using self-signed certificate) or changed to custom handling by assigning the UnityWebRequest.certificateHandler property.
I have yet another question
I change the scene in the middle of playtime, yet i have UI from both for some reason
Are they inside a DDOL object and therefore stay active on scene change?
I expected the text UI to dissapear
Also, as this is a code channel. If you think its code related, show the code that handles your UIs, so we can follow
Ohhhhh, i use dialogue system from pixel crushers, it puts it there on itself
How do i bypass it without really changing their code
i mean, if i can i would like to work around the working system rather than change it
I guess they want you to handle it manually with a closing method or an empty text message or however this is working. I dont know the package
Using an Event vs Function call from another sctipt.
So there is no known way to force it to close? I mean i could use disable
We dont know the package 😄 So you gotta check the docs of that dialogue system
Oh, i meant the universal method, not package specific
i'll try disabling in the runtime
why not just searching for the proper method of your dialogue system. I am sure, they have a method you can call from your script where you change the scene or something to close all active dialogues
Because im very low on time to finish it lmao
i'll find a proper method later
quickly searching the docs and finding it might be faster than hack your way around 😄 but you do you
Done
It works now
Crap, i only managed to do it in 2 🙁
glad you found it, as this will be the proper way to do it. Imagine you just disable the gameobject and someone forgot to check against that in the package, you can spawn random errors just because you stitch into their package mid execution of their dialoguesystemloop 🙂
Ah, i mean, i solved it in 2 with disable, ill look later at the link provided
Ah alrighty. 😄
Can someone tell me why is this button even here?
Like, is this supposed to be some kind of mockery lmao?
Its a relict from very old unity times, where Hub wasnt a thing, I guess 😄
that's the amount of content, not the length of the course. there's multiple courses there
Heh
Any idea why they took a nice design of a menu of building projects, and turned it into unintentional mess?
I came from version 2022 to 6000
And gosh, I don't even see where do I input the desired path anymore
the path of what?
Dont you click on build and it opens a prompt to do so? Or are you using a shortcut which will take the last path?
Anyway, its not code related 😄 Thought we were in #💻┃unity-talk
Hi
Dont just say hi in a topic channel please. If you got an issue, just ask 🙂
Hi
İ wonder how i can make a online game using peer to peer connection
1 host version
Are there any experienced dev here about that?
With effort, persistence and difficulty
There are resources linked in #1392142304772358215 message
can anyone tell me why my rotate thing doesnt work? it doesnt print anything but jumping and moving works
using UnityEngine.InputSystem;
public class MovementHandler : MonoBehaviour
{
[SerializeField] private float speed = 5f;
[SerializeField] private float jumpHeight = 2f;
[SerializeField] private float gravity = -9.8f;
private CharacterController controller;
private Vector3 moveInput;
private Vector3 velocity;
private Vector2 viewInput;
void Start()
{
controller = GetComponent<CharacterController>();
}
public void OnMove(InputAction.CallbackContext context)
{
moveInput = context.ReadValue<Vector2>();
}
public void OnJump(InputAction.CallbackContext context)
{
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
}
public void OnRotate(InputAction.CallbackContext context)
{
viewInput = context.ReadValue<Vector2>();
print(viewInput);
}
void Update()
{
Vector3 move = new Vector3(moveInput.x, 0f, moveInput.y);
controller.Move(move * speed * Time.deltaTime);
velocity.y += gravity * Time.deltaTime;
controller.Move(velocity * Time.deltaTime);
}
}```
How did you hook up the input system to this code?
for some reason the playback time on this particle system is like 30 sec i dont want that it is just a muzzle flash how can i change it?
Havent messed with particle systems in ages but one would assume the duration value at the top no?
Also not a code question
Do you guys recommend to learn modeling and all like become full stacked
As a indie dev you have to be in all fields
#💻┃unity-talk this is the wrong place to ask about modeling -_-
nah since im focusing on programming rn
since ive been switching from LUA, JS, and now C#
Sure but the question itself has no relation to coding so this is the wrong place to ask
Well unless you got buddies that can do the other fields or the money to pay others to do those fields
yes, im too looking for a teammate can't do all the things alone
ok i will try
Hi everyone, I'm having an issue in build with Unity, my CharacterController.Move function doesn't move my character when on ground (move vector is correct and all). The moment I jump and move he can walk, even on ground, but as soon as I stop it doesn't move on ground anymore unless I jump and move again...
if(!character) return;
Vector3 targetVelocity = playerVelocity;
if(new Vector3(targetVelocity.x, 0, targetVelocity.z) != Vector3.zero)
{
if(character.isGrounded)
{
playerVelocity.x = Mathf.Lerp(character.velocity.x, targetVelocity.x, accelerationRate);
playerVelocity.z = Mathf.Lerp(character.velocity.z, targetVelocity.z, accelerationRate);
}
}
else if(new Vector3(targetVelocity.x, 0, targetVelocity.z) == Vector3.zero)
{
playerVelocity.x = Mathf.Lerp(character.velocity.x, 0, deccelerationRate);
playerVelocity.z = Mathf.Lerp(character.velocity.z, 0, deccelerationRate);
}
character.Move(playerVelocity * Time.deltaTime);
Here is the movement code in Update
The playerVelocity isn't the culprit I already debugged it in dev build
In editor play mode it works flawlessly
You're only setting the velocity when your current velocity is non-zero:
Vector3 targetVelocity = playerVelocity;
if(new Vector3(targetVelocity.x, 0, targetVelocity.z) != Vector3.zero)
{
if(character.isGrounded)```
seems like a chicken and egg problem
and you can easily debug this
Also if(new Vector3(targetVelocity.x, 0, targetVelocity.z) != Vector3.zero) kind of makes my eyes bleed
Yeah I used that to debug
The issue is it's working in editor but not in build for some reason
And the character.Move is outside of the if statements so it is set even if velocity is zero
but youre calculating playerVelocity.x and z inside of the if statement...
The thing is it is also calculated but with a different parameter if the vector is zero
But even so, why would it work in the editor in that case?
did you debug your isgrounded variable?
are you ensuring you are still grounded after jumping and landing
Yup, it is always true when I'm on ground
Yep, in the state machine, I can only enter move state when on ground, and I have a label that shows me that I am indeed in movestate
if it works properly in build but not in editor makes me think it might be framerate dependant issue
It's the opposite
It doesn't work in build but works flawlessly in editor
And it shouldn't be framerate dependant as I'm multiplying the target velocity by delta time in the Move function
i think it could be this
if(new Vector3(targetVelocity.x, 0, targetVelocity.z) != Vector3.zero)
i think it might have to do with some floating point precision differences between the editor and build
im not too sure
try something like this
Vector3 horizontalVelocity = new Vector3(targetVelocity.x, 0, targetVelocity.z);
if(horizontalVelocity.sqrMagnitude > 0.0001f)
{
//move
}
else
{
//do the opposite of moving
}```
just as a test too see if the issue still happens
Ok, after a few tests the issues seems to be my acceleration/decceleration code, for some reason in build it doesn't lerp and just straight out not move
Same thing for the decceleration, it just stops instantly while in editor everything works for some reason...
Most likely not the source of the issue, but this does seem like it could be a case of wrong lerp: https://unity.huh.how/lerp/wrong-lerp.html which definitely won't help
Applying lerp so that it produces smooth, imperfect movement towards a target value.
Well i made an action and set it like this:
Look (action)
Action type: value
Control type: Vector 2
And then under that a Delta [Mouse] thigny
im pretty new to this sooo
_buttonArray[i].upgradeAttack = GameObject.Find(_buttonArray[i].upgrade.ToString() + "Spawner").GetComponent<PlayerUpgradeAttack>();
Behold my sinful code
And then how did you hook that action up to the code?
cool - so yeah you should definitely see some logs happening when you move the mouse
are you looking at the console window?
i am yeah
ive been asking for help from chatgpt for the last hour but that hasnt helped
And what is it printing?
when i move my cursor?
yes
nothing at all
Have you clicked into the game window to give it focus
i did yeah
Can you show how you configured the action?
I think this is a control schemes issue
Are you doing local multiplayer?
if you're not doing local multiplayer I recommend avoiding control schemes, they will just cause you a headache
uhh its just a singleplayer game...
ive just heard the old input system is outdated...
then idk what a control scheme is
Well you seem to have set at least one of them up
I recommend deleting all control schemes, they are not useful for single player
and they will jsut cause issues
i just started unity and c# overall, how do i set up intellisence for unity with vs code?
oh alright then thank you ill try that
!ide
If your IDE is not autocompleting code or underlining errors, please configure it.
Select one:
•
Visual Studio (Installed via Unity Hub)
•
Visual Studio (Installed manually)
•
VS Code
•
JetBrains Rider
• :question: Other/None
i legit just had to delete the control scheme and it worked
thank you so much dude
i dislocated a finger punching my wall out of frustration yesterday🥹
i followed all the steps and im not getting autocomplete words or anything like that
then you missed something
like what.
Like one of the steps:
The extension in VSC
or the VSC package in Unity
or setting the external editor in Unity
all of them are set
i got the unity extension and c#
and the rest are set in unity
did you press the "trust this solution" button or whatever in VSC
Do you have any compile errors in your console window in UNity?
Here are some other things to check: https://unity.huh.how/ide-configuration/visual-studio-code
it does say at the bottom failed to find entry points?
It says that at the bottom of where
unity
could you show the full message?
Even with this logic the issue remains in build :/
whats the difference between System.Random.Range and UnityEngine.Random.Range?
System.Random is an object that must be constructed, UnityEngine.Random is a static class. System.Random also does not have a Range method
Explained pretty qwell by reading the docs: https://docs.unity3d.com/ScriptReference/Random.html
https://learn.microsoft.com/en-us/dotnet/api/system.random?view=net-10.0
Biggest difference is the unity one uses static everything, the System one is instanced
im getting a null reference on line 33 and im not sure how clearing a list can give me one
https://paste.mod.gg/cifwcdicvuhv/0
A tool for sharing your source code with the world!
The same reason any null reference exception occurs. Because something before a . or a [ on that line is null.
So, check the line, and see what variables come before a . or a [
where do you actually assign a List<T> object to that variable anyway?
And what is the result of that?
null != empty, null == null. a null list cannot be empty because it isn't anything. an empty list is explicitly not null
Because line 33 still has a null reference
What's line 33 now?
the if statement
Okay, and what variables come before a . or a [
line 36 on the link
incorrect, that is adding to the list, not assigning a list to the variable
- That's after the error
- That's adding an element to a list, not assigning a list
where do you assign a new list to the variable
possibleRandInts
here's a hint: ||you don't therefore it is null||
oh my god i see the problem now XD
And hopefully now you see how you might solve literally every null reference error you ever come across.
Find the thing on that line that's null
And make it not be that
i didnt know that creating a list worked differently to creating an array whoops
here's a fun fact: it doesn't work differently
wait nevermind then im not sure what im doing wrong then
your arrays are just not null because they are serialized by unity so unity is creating the instances for you
i see, seems like an odd choice imo
It doesn't
what do you think would show up in the inspector if your arrays were truly null?
oh unity made an instance for me because i serialized it?
that's literally what i said and you said that was an odd choice
misunderstood and thought you ment unity creates instances for arrays and not lists
!code
📃 Large Code Blocks
Use links to services like:
https://paste.mod.gg/, https://hastebin.skyra.pw/, https://paste.ofcode.org/, https://paste.myst.rs/
📃 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.
no, i specifically called it out as being serialized so the instance is created for you.
@edward031633 muted
Reason: Too many messages in multiple channels
Duration: 29 minutes and 47 seconds
Sooo, I finally found out that in build, my fps is always above 1000 so the delta time is really low, and somehow, the character doesn't move because in the Move function I multiply the velocity vector and the lerp by delta time. The issue is, without that, the movement would be crazy fast and wouldn't make any sense
The thing is, how could I make it really framerate independant in that case?
if(!character) return;
Vector3 targetVelocity = playerVelocity;
Vector3 horizontalVelocity = new Vector3(targetVelocity.x, 0, targetVelocity.z);
if(horizontalVelocity != Vector3.zero)
{
if(character.isGrounded)
{
playerVelocity.x = Mathf.Lerp(character.velocity.x, targetVelocity.x, 1 - Mathf.Exp(-accelerationRate * Time.deltaTime));
playerVelocity.z = Mathf.Lerp(character.velocity.z, targetVelocity.z, 1 - Mathf.Exp(-accelerationRate * Time.deltaTime));
}
}
else if(horizontalVelocity == Vector3.zero)
{
playerVelocity.x = Mathf.Lerp(character.velocity.x, 0, 1 - Mathf.Exp(-deccelerationRate * Time.deltaTime));
playerVelocity.z = Mathf.Lerp(character.velocity.z, 0, 1 - Mathf.Exp(-deccelerationRate * Time.deltaTime));
}
character.Move(playerVelocity * Time.deltaTime);
if(character.height != targetHeight)
{
character.height = Mathf.Lerp(character.height, targetHeight, 0.75f);
}
Consider using the smoothdamp or movetowards.
Here's an example with movetowards:cs playerVelocity.x = Mathf.MoveTowards(playerVelocity.x, targetVelocity.x, accelerationRate * Time.deltaTime);
Mathf.MoveTowards is amazing.. its my pick of the two ☝️ (2:cents:)
MoveTowards kinds of give me parasite move on the sides when moving forward and same thing forward when moving on the sides ^^"
I'm trying to do everything in fixedUpdate but get this kind of stutter and movement blur when playing the game
And I don't seem to find a way to interpolate CharacterController
Mmmh, doesn't seem to work in build with the usage of lerp then ^^"
Or at least doesn't work when the framerate is too high
You need to log some data. Chances are, the improved wrong-lerp has some unexpected values.
the wrong lerp fix here seems a bit weird to me
I tried both anyway, same result
When the framerate is higher than 144 it doesn't lerp as expected anymore ^^"
are you setting playerVelocity outside of this function?
it seems to be the targetVelocity, but you're modifying it
I found it strange that they were using character.velocity
on frame 2, character.velocity.x and targetVelocity.x would be the same value
character.velocity is the actual velocity of the character, targetVelocity is the velocity I'm trying to get to (it changes with player input)
Ideally wrong lerp would be cs value = Mathf.Lerp(value, target, constant);
Not cs value = Mathf.Lerp(somethingElse, target, constant);
how is playerVelocity set?
playerVelocity is set in that function only
it's basically trying to change character.velocity from what it is currently, though indirectly, no?
that part seems fine
it seems like the issue to me would be the playerVelocity getting modified and used as the target the next frame - the second parameter is the broken one
targetVelocity is set according to input
Vector3 targetVelocity = playerVelocity;
...no?
Lerp expects a non-changing first argument. Character velocity likely isn't that.
wrong-lerp throws that out the window. it's not a lerp, it's just 2 values combined with different weights
Yeah I changed that bit since xD
sry
what's the current code
Forgot to specify that
if(!character) return;
Vector3 horizontalVelocity = new Vector3(targetVelocity.x, 0, targetVelocity.z);
if(horizontalVelocity != Vector3.zero)
{
if(character.isGrounded)
{
playerVelocity.x = Mathf.Lerp(playerVelocity.x, targetVelocity.x, 1 - Mathf.Exp(-accelerationRate * Time.deltaTime));
playerVelocity.z = Mathf.Lerp(playerVelocity.z, targetVelocity.z, 1 - Mathf.Exp(-accelerationRate * Time.deltaTime));
}
else
{
playerVelocity.x = targetVelocity.x;
playerVelocity.z = targetVelocity.z;
}
}
else if(horizontalVelocity == Vector3.zero)
{
playerVelocity.x = Mathf.Lerp(playerVelocity.x, 0, 1 - Mathf.Exp(-deccelerationRate * Time.deltaTime));
playerVelocity.z = Mathf.Lerp(playerVelocity.z, 0, 1 - Mathf.Exp(-deccelerationRate * Time.deltaTime));
}
character.Move(playerVelocity * Time.deltaTime);
ok, where do you declare/define playerVelocity and targetVelocity
is playerVelocity local or a member
playerVelocity is a member
I've made a main menu for my 3d game, and for some reason when I load the scene it's all dark
playerVelocity.x and z are set only in that function
that doesn't particularly sound like a code issue. try #💻┃unity-talk or #1390346776804069396 or #📲┃ui-ux (depending on the relevant tools) and provide more info
Mmmh
I tried a clean build and it seems to be working now
Maybe there was an issue with the build
After I made the change with targetVelocity
And lerping playerVelocity instead of character.velocity
Thank you for the quick help, it seems to be working fine now 🙂
It clearly was a logic issue on my behalf ^^"
Thanks to @ivory bobcat too btw 🙂
is there a way to refer to a bool method as false in a if statement? I know its already set to false automatically but I need it so that when Im jumping its specifically makes my bool method false
you can't set a method to anything, methods return values, so whatever is being returned needs to include that condition you'd like to impose
you also usually want to call methods rather than just referring to them
what exactly are you trying to do, in a broad overview? it sounds like you don't have the experience to use the proper terminology precisely yet
What do you mean by "bool method"
if (!IsGrounded())
{
// weeeeeeeee
}```
thats not a bool method though
thats just an if statement that uses a bool 
im guessing a bool method would be a bool function that returns a true or false statement
Well, IsGrounded() would be
Whats going on whenever I see code like this?
someVar.someProperty = () =>
{
....stuff....
};
yeah like why is it = to a blank parenthesis and then the lambda to some code block?
Just recently added a raycast along side using comparetags for ground check and this if statement kepted things working for some reason
Like whats the long-hand version of that? I dont know what this is specifically called so trying to search for it is difficult
The => is what's known as a "Lambda expression". It creates an anonymous function. As an example, you can see something like this: () => Debug.Log("Chungas");
And mentally translate it to:
private void ThisNameShouldntBeHere()
{
Debug.Log("Chungas");
}
That's called a lambda expression . . .
You can't set a function to a value. getisGrounded() will give you a boolean. You can't set it to false
Awesome, thanks!
I know
so what is it youre trying to do then?
I just put it there to show what I initially did then realized I couldnt do that
So why are you trying to set it to false?
What would it even mean to set the function to false?
i guess to make it always return false if some condition is met?
i guess you could do that with a seperate bool and an if statement within the bool function
boolean function could run conditionals b4 the return
For some reason my idle animation would play when Im jumping and this if statement in my update method would stop this from happening. I legit could not tell you why
Well Ill figure something out
well since its the idle animation im assuming its overriding the jumping 
you would need some kind of conditional to ensure it doesnt play when you are airborne
Yeah I already have a isJumping = true or false in place for this
and it doesnt change so iunno
it doesnt change?
i mean your isjumping is just the opposite of your isgroundedd
you dont really need a seperate jumping bool
at least i dont think you would, you can just use !isgrounded
to drive the parameter for the animation
use some debug logs
also i dont understand this? isnt this the opposite way of doing this? why are you setting your isgrounded manually at all?
see if they print out to the console when u expect
void Update()
{
PlayerGroundCheck();
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
Jump();
}
if (!playerIsGrounded) // same as saying if(playerIsGrounded == false)
{
// airborne logic
}
else
{
// grounded logic
}
}
``` as kuzmo says ^ 1 boolean should be enough for what i think ur doing.. its either *this* state or *that* state.. and depending on that you can branch off and run seperate logic for both states..
your ground check should become false if its programmed correctly.. you shouldn't need to manually set it..
it overcomplicate things when u have (2) booleans like isGrounded and isJumping.. since they both just mirror each other anyways.. instead of working from there and getting stuck w/ contradicting booleans maybe try to re-think your logic and setup to make it more simple
What happens when a script has a virtual function, and the script that inherits it also has it but not using override? do both trigger? just the newest?
class Parent {
void virtual Something() {/*do something*/};
}
class Child : Parent {
void Something() {/*do something else*/};
}
trying to read someone else's code where testing isnt possible rn
You can still write your own and run that
you could copy that snippet into an online c# compiler and fix all the issues
you wouldn't even have to run it, you'd get a warning telling you exactly what happens
Depends what type you use when you call the method:
Parent childAsParent = new Child();
Child childAsChild = new Child();
Parent parentAsParent = new Parent();
childAsParent.Something(); // Calls Parent.Something
childAsChild.Something(); // Calls Child.Something
parentAsParent.Something(); // Calls Parent.Something
Thought i'd point that out as it isn't immediately obvious if you just "try it and see".
the warning that pops up makes it pretty obvious imo 🤔
the warning says it acts like new
aight ill try and see
does anyone here use the Nova UI framework?
turns out they have different parameters so i was just overthinking the "virtual"
it just uses the one whose parameters you match
don't crosspost. #📖┃code-of-conduct
shut up
<@&502884371011731486>
rules exist, yes
suck a fat one!
in fairness
I'm sure the twelve years or so you've been alive have been hard, yes
set a calendar event 10 years in the future and come reread your message history
18 and richer
sad for u
They're gonna cross a line at some point and get their post history nuked
"you*"
abbreviations exist
!mute 1430691199160815717 1d if you want to continue posting here you will need to be less antagonistic. Follow basic posting etiquette, don't cross-post, and re-read our conduct if you have trouble.