#๐ปโcode-beginner
1 messages ยท Page 227 of 1
its done but how do i call that function
Make a function that does what you want to happen, and call that function from your button
oh sorry i think i understood
score++``` right ?
i'm sorry if the misunderstanding came just from the word function
that i misunderstood
If you actually make it with proper syntax, yes. That would work
i'll show you
so basically, instead of void update that would constantly check if button is pressed, i create void function (linked to button) that starts when button is pressed ?
It's not a "void update". It's a method called Update that returns void (meaning that it returns nothing)
give it a go and see what happens
And, yes, that's a reasonable idea
Gamepad gamepad = Gamepad.current;
if (gamepad != null) Vector2 stickL = gamepad.leftStick.ReadValue();
why does this tell me Gamepad isn't a real class?
I do have the InputSystem package installed
may be dumb again but... can't find the function now
using UnityEngine.InputSystem; doesn't work either
is it not configured correctly or something?
it must be public
and you must not have errors
it won't show up because you have errors, the compile hasn't finished.
It also must be public.
Probably solve all those errors
do other classes from the input system show up?
let me check
e.g. PlayerInput
nope
If you just installed the new input system, you might need to go to preferences -> external tools -> Regenrate Project Files
kill your code editor and reopen it
Unity needs to generate a new .csproj file for the input system package, and your editor needs to actually see it
now that i change to public it showed up
It perfectly works now what a great achievemnt
thanks a lot for your time
Here's the inspector btw @polar acorn
You've left off the tag
Also this is the inspector for the object with the script, I wanted to see the tag on the thing it's colliding with
Show the tag anyway
Can Someone Help me?
using UnityEngine;
public class SpaceBackground : MonoBehaviour
{
public bool rotateAstronaut = true;
public GameObject astronaut;
private float rotationSpeed = 50f;
public bool moveBackground = false;
public GameObject background;
private Vector3 backgroundSpeed = new Vector3(50f, 0f, 0f);
void Update()
{
if (rotateAstronaut && astronaut != null)
{
astronaut.transform.Rotate(Vector3.up, rotationSpeed * Time.deltaTime);
}
if (moveBackground && background != null)
{
background.transform.position += backgroundSpeed * Time.deltaTime;
}
}
}
You have no scene at index 2
!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.
Scene 2 is added to the build settingss though? How do I index it properly?
No it isn't
You only have two scenes
there is no third scene
You NAMED the scene 2
That is not its index
Can I change them from 0 - 1 to 1 - 2?
No
You could add a blank scene as 0...
thats what that was for oml
But it's way smarter to just change your code..
Instead of trying to load an index that doesn't exist, change it to load one that does instead
wooow that is all?
can someone help me
..... with what,
i want that looping
Looping of what?
The Space look the video
The background Space black with start that not have a ending
omg it works now thank you
Just need to get the spite to stay loaded in on the next scene haha
Make the background bigger
Instantiate new backgrounds as it goes
Change the skybox to black so it is less obvious where the end of the background image is
You probably always want like 3 or 9 backgrounds (9 if you can go vertically) always, and when you move onto one of the ones to the side, erase the ones furthest and add new ones in the direction of travel
I'd change the texturemode to Repeat, make the mesh larger then when it reaches close to edge snap it back
unity shaders have a tiling parameters you can just run time over to scroll it
or yeah shaders
needs to be on repeat too yeah
Vector2 offsetSpeed;
material.SetVector("_Offset", Time.time * offsetSpeed);```
Something like that
yeah would just do it in shader
though i would not constantly be setting a vector on it
oh wait it's offset
It shouldnt be setting every frame
Definitely the way to go. I was just worried about suggesting something like that haha
well, I can't expect that unity is updating the buffer every frame
oh, so its this just creating a offset based on when it spawend
and its not animating it
because of hte use of time, assumed it was for a real time scrolling
oh, actually I do have to update time from the variable so i guess I am updating the buffer
no wait, yeah it's a one time set actually the speed is set once, but I need to continuously pass in time
Do you have a tutorial for me
Do you have a tutorial?
plenty of ones for scrolling backgrounds, but I'd go with a shader as suggested
Ah, no wait. You're right. If I do it in update then I am constantly setting the buffer because of the time which can just be done in the shader itself.
adding to UV's scrolls, so can just do what i have in my screenshot there
so either shader graph or edit one of unity's shader
or its pretty simple in hlsl too
Hi there, I just added a new asset pack and unity created a new sample scene to view it and I cant find my old scene anymore. Does somebody know a solution for this?
the scene probably came from the asset pack itself. Search for t:scene in your assets folder and look for your old one. If you didnt save your old scene, then I doubt theres anything you can do. Also not a code question
{
Debug.Log("hover");
// Check if the display object is not null and active
if (displayObject != null && !displayObject.activeSelf)
{
// Display the object
displayObject.SetActive(true);
}
}
``` i cant get this to work, This is a UI object would that stop it from working
cheers
Hi, In my game i have 2 scenes the main menu where you click start game and the game itself i have a simple script to make an invisible layer (pause menu) appear when you click on pause button the script for it is in the screenshot, in the pause menu it also has a button which says exit if i click on it it send me back to my main menu but when you click play the game starts in timescale 0
anyone know how to fix this
it does start with timescale 1
fix what?
that my game starts with time.timescale 0 after i click exit on my pause menu and then click play
Where do you call resume?
And does Pausegame get destroyed? Like is this moving between scenes?
How do I make everything line up? If I go down with the scale I have to adjust everything and if I drag longer it's blurry
also in the puase menu when i click continue button
Is this script on the pausemenu?
and did you debug the value of time scale in the next scene ?
Well, the timescale part is not working, right?
That's what I'm trying to debug
the resume is working
But... timescale going to 1 is not...
TextMeshPro != TextMeshProUGUI btw
I think timescale is a static value that carries over
yes it is
Yep
so where are you setting it back @fading rapids
can i make it so if i clcik my play button on a diff scene it sets my timescale for the next scene to 1
do the same thing you do for resume ?
oh the timescale
or maybe put an if condition ? so many ways to do it
yeah you're modifying the setting inisde the unity project settings afaik
its a "global" value iirc like Gravity vel
yes thank you
Should i watch the code monkey full course on youtube?
Also is 3D fine to play around with as a beginner?
Thank you!
Almost anything you do in 2D version you can in 3D(methods n stuff)
Building 3D engine in 2D pfft.
unity is a 3D engine regardless
the only thing that changes is the Physics engine from Box2D to Physx (3D)
Only after !learn
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
!learn?
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
See the bot?
Of course, I'll take a look at it.
how are you calling pause ?
if thats a button , putting KeyDown inside of it is a baddd idea
well why would it if you're not calling those methods anywhere
Inputs should be polled inside Update
to call a method you want
new voids, idk what you mean by that
okay
if (input)
{
Pause()
}
Thanks ;)
OHHHH
Hey! Any idea what is wrong here?
{
Gizmos.DrawWireSphere(transform.position, groundCheckRadius);
}
Ground Check Radius is shown fine in inspector but its not drawing a wiresphere
check your spelling
me?
c# is case-sensitive
yes
!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.
how would i make it so escape key works for both pause and resume
either ur ide is not configured or ur mistaking Null Reference Exception for compiler error
I switched back to windows so its configured
make a bool that you toggle
eg
void Update(){
if (Input.GetKeyDown(KeyCode.Escape)) { Pause(); }
}
bool isPaused;
void Pause(){
isPaused = !isPaused;
if(isPaused) // stuff
else // otherstuff
}```
okay lemme try
no null reference exception
please use your configured IDE to format your code before copy/pasting it because that is unreadable
I can ask chatgpt to do that wait a sec
no
navarone or boxfriend, what do you see wrong there? because if i type them otherwise i get errors
show me in the documentation where you see the onDrawGizmos method
why not it doesnt write any extra code just tidies it up
this is not onDrawGizmos. this is OnDrawGizmos
you should be using your IDE to format it so that you are actually reading and writing legible code
screenshot the entire IDE window
yes I tried edit advanced format document
it doesnt tidy it as good as chatgpt
where does unity say compiler errors
oh damn , thank you! feeling blind rn lol
what are the error(s) that unity shows
can you show the actual console window
i have no idea what this tiny ass sliver is supposed to show. but yeah you should show your actual console window
here
its console window isnt it?
I have a feeling errors are being collapsed/filtered out
no, that is a tiny ass sliver that shows nothing. open the actual window that has the title Console
hmm I dont see it let me google it real quick
how to fix
just show us the entire console window first
can i put an emoji in a changed text like this ? i can't save the script when i try
should i ?
It shouldn't be a problem afaik but just note that you'll need a font that supports the emoji if you want it to show up in game.
I don't speak French so I can't make heads or tails of that warning.
The W if statement has nothing to do with the if/else below
so if you're NOT pressing S, you will get the else
fixed it myself after seeing console windows. I thought that grey little rectangle was console windows my bad
you probably want this structure:
if w
else if s
else```
also you should fix your formatting, it is atrocious
another nit - m_eulerAngleVelocity not "eurler"
Try using the unicode for it, if it doesnt work
the unicode doesn't work ^^
Should work fine, as I've used unicode to show emojis. What specifically doesnt work
i type the unicode and it shows the code
but anyways the font cant support the emoji i tried
what doesnt work exactly?
i applied noto font to a tmp
are sure you selected all the characters when creating TMP asset font
pretty sure that wont work without converting it to TMP asset
ofc it does
but how do i select all these files in the font creator ?
choose Extended ASCII, should work
some don't work
well it works a bit
You simply haven't included whichever emoji you are trying to use
there are a crapload of emojis
how do i do that ? ^^'
in huge different swathes of the unicode code space
how can i include an emoji if it's not included in noto font
look up the emojis you want, find their unicode code points and make sure they're included int he character set you choose. If needed use a "custom rangle" which uncludes the codepoints you want
If the emoji isn't in the font, it won't work at all
it needs to be in the font and you need to include it in your character set
thanks i'll give it a try later :)
The "Characters from a file" mode might be convenient for you.
seems a bit complicated ^^' it is compatible with another font right ?
like using this i can add an emoji to comic ms ?
does timescale slow down time aswel?
As well as what? What does it slow down besides time?
xd nvm i forgot speed also has to do with time
and gravity
etc
also accepts a range you can specify too
i think i'll add sprites instead it seems to be easier
#unity #unity3d #games #indie
๐พ How to use Sprite Asset in Text Mesh Pro - Unity add icons into a String or Text - Visual Scripting - Unity No Code C - Bolt - Visual Scripting Plus
โ Download Icons used in video : https://assetstore.unity.com/packages/2d/gui/icons/2d-items-set-handpainted-210729
๐ Any questions or discuss about Unity or Visu...
why does Directory.GetFiles() return strings with extra backslashes in only part of the returned path? the following is after i wrote it to a json file
{
"files": [
"D:/Personal/Hobbies/C#/Unity/Project Primary/Assets/resources\\Textures\\dev\\dev_fade.tga",
"D:/Personal/Hobbies/C#/Unity/Project Primary/Assets/resources\\Textures\\player\\grade_bad.tga",
]
}
Backslashes is the preferred path separator in windows
I assume you wrote the first part with forward slashes
That's normal. Like in C#, backslashes are used to escape (ignore) the next character. That's how you can write quotes, newlines, tabs, etc. inside JSON values: ```
"some JSON" value"
Upon deserializing, they will be converted to a single backslash in the string.
oh interesting. thank you
yes the first part was using
Application.DataPath + "/resources"
getfiles/json did the rest
Use Path.Combine instead of string concatenation
You'd want to use Path.Combine(Application.dataPath, "resources") instead. It handles operating systems where the directory separator is different.
thank you for the tip
whats the best way to do damage numbers in a 2d game? just instantiate a text then remove or use particles?
pooling system.. dont instantiate
yea
inclusive or moment
have X amount of text elements that u can reuse..
X or Y?
"yes"
But yeah not sure if that's even possible to do with particles easily, you're better off instantiating or reusing a prefab with a TMP_Text on it
Hi, I'm working on implementing a leaderboard for my game. I've installed the SDK and set up a leaderboard in my Unity Cloud project. I'm writing a script to update it in my game and display it on my scene, but it's not working. I'm not sure which exact functions to use. Can anyone help me?
the functions are listed in the docs
So my update method doesnt want to run. I have the script enabled and the gameobject is enabled as well. the scene is running and it should be working but theres nothing and console shows nothing
!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.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
guys how do i manage collisions between 2 prefabs with the same script
same tag also
i just cant figure it out :c
did you not put Debug.Log inside update ?
there is one in the update
and its not printing ?
nope
so your script is not running
no its running
Debug.Log missing says otherwise
i found it. It got overloaded
What do you mean by "manage"?
if you only want one side to trigger, compare their instanceids
i have a prefab, i want to collide with other gameobject created with the same prefab
if they collide they run the collider function twice
Do you care which one runs the function? Or do you just need to make sure only one of them runs?
they are creatures, so if you drag one to another they breed a third
so i need to get data from both to make the new prefab with that data
Okay, so it doesn't matter which one actually runs the function. So, you can check if the other object you collided with has the same script, and if it does, check their InstanceIDs like vertx suggested.
https://docs.unity3d.com/ScriptReference/Object.GetInstanceID.html
They'll have unique IDs, so you just have them check it and if the other object's InstanceID is higher than this one's, don't do the function. In any collision, only one will ever run
the gameObject will
okay yeah, sorry
None of them are "prefabs" at this point. At runtime the concept of a prefab doesn't exist
the new gameobject generated by the prefab
Does the order of component assignment in the inspector matter at all?
If your code relies on it then your code's the problem
ok im wondering here
im working on a teleportation system for a stationary enemy
basically if you get out of range of an enemy it teleports to your position with an offset
how would i add an offset
What's the error say
adding a float to 3 floats will not work
i am aware
https://docs.unity3d.com/Manual/VectorCookbook.html
See Direction and Distance from One Object to Another
you want a normalized direction scaled by the distance you want to move
So what direction are you trying to add that value to
thanks a lot, this really helped :)
Hey there. I'm trying to make a grid gameobject to visualise A*. Anyway, I'd like the grid to be customisable in size and have different obstacles etc. Is there some kind of way to create a custom object type that would let me customise (and see the customisations) in the Scene window? Ideally would be similar to how you can create a "3D Object" and it comes with certain components already on it. I could do it at runtime using scripts etc but it feels a little clunky to have to spend ages fetching each cell's behaviour script just to change
not sure what you're asking here tbh, sounds like a mix of custom components and editor scripts
Hello, I have a problem with unity new input system. It is not reading mouse delta right now. I have set Action to value - vector2 and binding to delta mouse but I get no values when I move my mouse. Gamepad works fine but mouse is not working. Any ideas why is that happening?
Can someone tell me the simplest event method that gets a MouseDown/Up event? Like, for any click in the game window, regardless of context.
I'm just protoyping and found a couple different options in Unity docs, but they seem to be associated with UI systems?
Any click any where?
yes, i'm trying to do a downdrag , some game logic starts, upon release it stopsand release thing. where upon mousedowndragging
upon mousedown, rather
Ah, thanks. I don't know why Unity needs different mouse events for all it's various systems
It doesn't, you were just looking at how to detect when you clicked on something
if you just need to know when a button was clicked, that's input
true
Could someone link a good tutorial for like a basic 3rd person movement and camera system?
Download unity's first person shooter template and dig through it (you can modify it for 3rd person with a little research)
thanks
you can download it right from the hub
Unity default lighting looks like 2006 Roblox
var playerEntry = await LeaderboardsService.Instance.AddPlayerScoreAsync(leaderboardId, scoreToAdd)
Where can i add the username here pls?
If I were to say, make a mesh of a cube, I could make a 3d List of verticy positions and make the position of each verticy based of the index of the different layers of the list, corresponding to length width and height. But if I were to make say, a tetrahedron, I donโt know how Iโd do something like this. Does anyone know how?
What does the documentation say?
i didn't find anything in the documentation
So, is setting a username even a feature?
usually rendering shapes I reference to tutorials with opengl
yes
What makes you think so? Is it mentioned in the docs?
trying to make the camera of a 2d platformer smoothly follow the player so sudden movements aren't as jarring (ie from the player respawning elsewhere or teleporting). i've applied the stuff here https://docs.unity3d.com/ScriptReference/Vector3.SmoothDamp.html to my existing code and it does seem to work in making the camera smoothly move over after teleporting, but the camera overall has some weird jittering to it (can't seem to record it with a recorder). anyone have some suggestions?
public float leftLimit = 4.34375f;
public float rightLimit = 999.65625f;
public float smoothTime = .3f;
private Vector3 velocity = Vector3.zero;
private float intermediateCameraPosition;
private void LateUpdate()
{
intermediateCameraPosition = Vector3.SmoothDamp(transform.position, targetTransform.position, ref velocity, smoothTime).x;
transform.position = new Vector3(Mathf.Clamp(intermediateCameraPosition, leftLimit, rightLimit), transform.position.y, -10);
}```
i need it, i just want to know how to attach a username to a score
That doesn't answer my question.
If the docs don't mention it, then there's probably no way to do it.
so for you a leaderbord is just a list of scores?
It doesn't matter what it is for me. What matters is what the service and it's API allow. And it's defined in the docs.
pretty sure unity uses a dictionary
oh nvm thats for the meta data
just so you know the username comes from the unity auth..
yes ty! but i just wanted to know if its possible to change the "name" in the lb
which one is preferable?
There is no way of setting any variable based on another outside of runtime right?
Like... link these two values by default on the script preset itself, it should be in the declared on the weigthedList only correct?
Incorrect. You can do it with editor scripts
#โ๏ธโeditor-extensions has resources pinned iirc
Which one?
I have that script:
{
if(Statistics.IsMovingObject == true)
{
Statistics.MovedObject.transform.position = CameraTransform.transform.position + CameraTransform.transform.forward * distance;
}
}
public void MoveObject()
{
if (Statistics.IsMovingObject == false)
{
rb = Statistics.MovedObject.GetComponent<Rigidbody>();
Statistics.MovedObject.transform.parent = Player.transform;
Statistics.IsMovingObject = true;
rb.isKinematic = true;
rb.detectCollisions = false;
}
}```
Its code for moving items by using mouse0 on it.
And its working (not full code). Object stand in front of player.
But i have problem, objects are shaking / trembling / idk how to explain when moving.
Sending settings of rigidbody:
What do you mean which one? I mean YOU make an editor script
use pooling. up to you if you want UI dmg numbers or TextMeshPro mesh
Don't use a transform to move when using Rigidbodies
I turned off collisions and turned on kinematic, so if u say i should not use transform what should i do?
Use the rigidbody
MovePosition works with kinematic
oh
calculation in HandleSpeed calculates how much force to add to reach speed limit, problem with it is that it doesnt add the force in the slopeMoveDirection because slopeMoveDirection is only used in the targetVelocity calculation and not in the final calculation, so the force doesnt get added in the direction of the slope but just forward which causes my character to bounce when walking down a slope since the force is added forward and not down for example with the slope angle
Handle Input - Update ```x = Input.GetAxisRaw("Horizontal");
y = Input.GetAxisRaw("Vertical");
moveDirection = orientation.forward * y + orientation.right * x;
slopeMoveDirection = Vector3.ProjectOnPlane(moveDirection, slopeHit.normal);```
Handle Speed - Update ```Vector3 targetVelocity = slopeMoveDirection.normalized * moveSpeed;
Vector3 velocityDifference = targetVelocity - rb.velocity;
slopeMoveVelocity = new Vector3(velocityDifference.x, 0, velocityDifference.z);```
Handle Movement - Fixed Update rb.AddForce(slopeMoveVelocity * acceleration);
basically what i need to do is to include the slopeMoveDirection.normalized in the final calculation to add the force in the direction of the slope instead of just straight as its doing now because slopeMoveDirection.normalized is not involved
seรฑoras, i have a problem, this code, teleports an object (aliados) below the feet of the player even if its on the air?
basically something like this xd
start by debugging if that line is reached to set position
also good idea to make sure sure the ray is long enough
Debug.DrawRay
can't
thats the code of a friend xd
ill tell him
ty
Why would you ask a code question if you cannot change any of the code
he isn't in the server
How, I though you meant like a package... you mean like customazing the editor manually
then invite him
im just tryna help :^(
But this is meant to be store as prefabs, I don't think is very usefull is that's the case...
What exactly are you trying to do?
I have these "orbs" that are just like powerUp pickups, they are meant to spawn as reward after doing certain stuff, but the one that generates is randomized, based on their rarity level, so I just though it would be more manageable if the rarity had a correlation to the amount of weight it has on the pool on the orb prefab itself rather than assigning it from the weightedPool, but maybe I am just wrong
can u tell me how can i turn my function in to moveposition? thank u
That is correct
https://docs.unity3d.com/ScriptReference/Rigidbody.MovePosition.html
Just gotta plug the direction into the method
Newbie here, if i create a 2d rpg pokemon clone on desktop, can i make it run on the iphone later? or do i have to code the game with ios in mind from the beginning?
anyone please?
You can build it for iphone yes, without any major changes
You need an iphone to test jt though afaik, and a mac to build it? Not 100% sure
I see, my question is, ANYTHING you make on unity can be run on ios? Or are there things I need to look out when coding for steam vs ios
tried by typying same parameters and multiply by deltatime and speed but its not working properly
Maybe best for #๐ฑโmobile
its teleporting
Also, just something unrelated (and probably not that much important cause I have to implement each powerUp separetely anyways and I could set the description from the script), I want to have a description on the script that is just a string parameter to set in the inspector. How can I make it like have paragraph and stuff? Like can I change the format? Should I just not be using just a string for that?
Just like using transform.position, moveposition is a teleportation kinda thing
Gotta know a little more about what you mean to help though
its teleporting by ~ 3 seconds, not moving smoothly
i add same parameters like in script i send, and on end multiply by time deltatime and speed 5f
What do you mean teleporting by 3 seconds?
it stands in one positions for ~ 2/3 seconds and then teleports for new
its not moving smoothly like its should, its teleporting
It'd be really helpful if you just posted the up to date code ๐คทโโ๏ธ
No way we can help without it
CameraTransform.transform.position + CameraTransform.transform.forward * distance * Time.deltaTime * m_speed
sorry im on phone now
thats parameters
of moveposition
It's important to know the context of the code, so wait until you can post the whole thing
But having distance AND speed is worrying
Hopefully this was moved to FixedUpdate? That's where all physics movement should take place (like in the docs link I sent earlier)
i want to tp object in front of player camera (first person game) with distance from player
yes in fixedupdate
So the camera is moving and the object follows it? Then you definitely don't want those parameters
i think i should make one position and then multiply by time and speed
And the movement of the camera is likely the issue with jerkiness from the very beginning
Hi with my character controller script every time i go down stairs/slopes the speed is really slow compared to going up, i have tried multiple "fixes" i found online but none worked for me.
anyway this is my movement script and gravity
Movement:
private void movePlayer(Vector2 ctx)
{
if (!characterController.isGrounded)
{
return;
}
CurrentVelocity = Vector3.zero;
Vector3 moveDirection = new Vector3(ctx.x, 0f, ctx.y);
if (moveDirection.magnitude > 1f)
{
moveDirection.Normalize();
}
moveDirection = transform.TransformDirection(moveDirection);
characterController.Move(moveDirection * (isSprinting ? playerSprintSpeed : playerSpeed) * Time.deltaTime);
}
and Gravity :
private void applyGravity()
{
Ray groundCheckRay = new Ray(transform.position, Vector3.down);
if (Physics.Raycast(groundCheckRay, 1.25f) || characterController.isGrounded)
{
CurrentVelocity.y = -2f;
}
else
{
CurrentVelocity.y -= GravityForce * Time.deltaTime;
}
CurrentVelocity.x -= Mathf.Clamp(CurrentVelocity.x, -Drag, Drag) * Time.deltaTime;
CurrentVelocity.z -= Mathf.Clamp(CurrentVelocity.z, -Drag, Drag) * Time.deltaTime;
if (Mathf.Abs(CurrentVelocity.x) < 0.001f)
{
CurrentVelocity.x = 0f;
}
if (Mathf.Abs(CurrentVelocity.z) < 0.001f)
{
CurrentVelocity.z = 0f;
}
characterController.Move(CurrentVelocity * PlayerMass * Time.deltaTime);
}
im like completely brand new to coding other then like hello world in python and am trying to start off by making a 2d game with no animation or hardly any maybe just basic ones buti cant find any good guides? anyone have any helpful links?
i think it was working but object was little shaking
im mostly focoused on making a simple game with good features and play to eventualy make it 3d and alot more advanced
rather than diving right in, you should go through a structured course that teaches you the concepts you'll need to know. there are some excellent c# courses pinned in this channel and the pathways on the unity !learn site are an excellent introduction to the engine and basic game dev concepts
:teacher: Unity Learn โ
Over 750 hours of free live and on-demand learning content for all levels of experience!
there's also this if you prefer that kind of content https://www.youtube.com/watch?v=XtQMytORBmM
๐ด Get bonus content by supporting Game Makerโs Toolkit - https://gamemakerstoolkit.com/support/ ๐ด
Unity is an amazingly powerful game engine - but it can be hard to learn. Especially if you find tutorials hard to follow and prefer to learn by doing. If that sounds like you then this tutorial will get you acquainted with the basics - and then gi...
hey, i made a blend tree for my jump animation, i have the jump, falling, and landing animation all together inside, what i'm wondering is how do i increase and decrease the number in my script? i have a 2 if statements, one for when i push the jump button, and one that checks if you are on the ground
Anyone? Ignore the audio
cinemachine
it has a component that'll do all this for you..
can define the deadzones, how tightly it follows, smoothness, all that
How do I set my game up to not use URP or HRRP, just default render pipeline, I need some features of the camera that are not availble in URP
not really a code question, just remove the packges
if this is to me, i'd rather figure out what's wrong with my implementation than to import some package i have zero familiarity with for one single issue
ah, shit, easy enough lol
okay so moving
intermediateCameraPosition = Vector3.SmoothDamp(transform.position, targetTransform.position, ref velocity, smoothTime).x;
into FixedUpdate seems to resolve the issue...but why...?
You should use cinemachine unless you really wanna tackle this one yourself.. cinemachine does everything you're looking for and is likely much much easier.
If you really want to avoid jittering, you should make sure your rb is using interpolation and do whatever smoothing you want in regular update.
But as far as your question is concerned - you'll wanna look up the unity lifecycle and become aware of when in the cycle stuff all happens, like physics and rendering - it's likely you've got some logic on your camera that is tied to physics, which doesn't happen in Update, it's in FixedUpdate.. but I'll admit I only skimmed the above convo, so I apologize if that's off the mark
rb interpolation set to none/interpolate/extrapolate seems to have no effect
yes, my camera position is determined in LateUpdate while the rb it targets moves in FixedUpdate
to my knowledge unity tries to run FixedUpdate by default 50 times a second, regardless of framerate, while Update runs once per frame and FixedUpdate once per frame after every Update has run
That's what the interpolation is for. If it doesn't change anything, then you're breaking it by moving or rotating in a wrong way.
okay maybe interpolate does work...? seems the interpolate option doesn't change properly if changed in play mode...
if set the rb to interpolate, then start play mode, it seems to work fine, but if i switch it to none while still in play mode, it jitters, and if i set it back to interpolate (again while still in play mode) the jittering remains
i'll look into cinemachine for future projects but this one i'm currently working on isn't supposed to be a big one and i don't think i'm gonna need to touch the camera anymore after this so
if I were modeling something that was meant to be the same size as the unity default "Plane" mesh, how big would that be? I think this means 10 by 10, right?
but, like, 10 by 10 what? meters?
Unity's units are meters, yes
awesome, thank you
That's weird. It should be updated correctly at runtime too.
keep in mind unity uses meters, but what matters us how you use it
like means very little if you art is very tiny or huge and generally not adhering to 1 unit == 1 meter
anyone?
oh yeah what's the point of private Vector3 velocity = Vector3.zero; and ref velocity in the example in the SmoothDamp documentation? https://docs.unity3d.com/ScriptReference/Vector3.SmoothDamp.html
actually maybe i should ask what the ref velocity in transform.position = Vector3.SmoothDamp(transform.position, targetPosition, ref velocity, smoothTime); does too
rendering an UI image is less expensive than rendering a mesh right? for 99% situations, assume theyre using the same texture(source image)
because rn the previous members in my team use meshes + texture to render all UI images
how many verts are the meshes? if they're just quads it should be pretty much the same
i gotta check on that lol
it turns out that the meshes are just a simple rectangle lmao
wait
oh i see why they did that
ref means that you pass the variable by reference, so any changes inside the method are applied to the passed in variable.
looking through the documentation again, so
- is SmoothDamp basically storing inside
velocitythe camera's velocity velocitycan be used by something else that might need the camera's velocity, but the example itself does not show that
am i understanding how SmoothDamp is working here?
It's not storing anything. It's modifying the variable that you pass into it.
that's what i meant
point is we can then later use velocity for something else right
Sure
and i assume cinemachine actually gives you more control over the easing function
You can google "unity SmoothDamp GitHub" and look at the source code of the function if you want.
Cinemachine does a lot of stuff. It's not just easing.
well yes but just for example if i wanted a sharper ease in and out function or linear or something
Yes, cinemachine provides all kinds of settings related to camera movement.
okay thank you
hey im trying to setparent a 1 by 1 by 1 sphere to a cube scaled 20x20x1 but the spheres get stretched for some reason no matter what i do
im spawning them at the end of a RaycastHit
well
you are parenting them
the child inherits the scale
is there any way to not have them get scaled poorly
have the cube have parent with 1,1,1 scale and parent it to that instead
thats an issue
because
i want to be able to spawn these spheres parented to literally anything in my scene
so that would require everything in my scene having an empty parent
usually should never be mixing scaling/graphics with the root objects
and the collider if must exist on parent for RB reasons, then the collider component gets the sizing not the object transform
so i have to make a parent on everything and gett that
thats so much more work ugh
ok
this is literally for like an assignment i didnt wanna put that much effort in
You could try maybe creating a gameobject at runtime and parent it to that
dunno if it will work
wdym
I think if you make another chilld at the hit.point then parent the sphere to that instead of the one with scale. (Some performance implications though with new() GameObject each hit)
You could try resetting the lossy scale(I think it was?) After parenting.
whats that
Oh wait, it's read only
i c
why do you need the parenting? you could use constraints instead if that's what you are looking for https://docs.unity3d.com/Manual/class-PositionConstraint.html
uh i just want stuff to rotate with things and such
position constraints seem like a lot more work in code
not really, you just assign the object to the constraint instead of as a parent
how do i do that in code
readthedocs https://docs.unity3d.com/Manual/Constraints.html
it is lame that they have no code examples but you're just adding your 'parent' as the constraint source
its not workin
i added constraints to my prefab for the sphere
when you add a source, does its weight default to 0?
might need to set that too (and don't add it twice? why are you adding it twice?)
weight is 1
anyone know what this is referring to?
theres a position one and a rotation one
the constraint has a weight and each source has a weight
oh ha, good point
there is also a direct 'parent' constraint which might save you from having to do both https://docs.unity3d.com/Manual/class-ParentConstraint.html
Refers to the canvas scaler component on disable function
ok when i set the weight to 1 they started going into the middle of the object
yes but is there a reason why it is taking up 6 mb of gc alloc
when I dont disable it or enable it
well that's where the object's position is
it has an offset i think, that you can set if you want it to stick where it hit
ah
i see the issue
i have no idea how to do that lol
i need it to spawn at the end of a raycast
then be parented to whatever the raycast hit
under constraint settings, there's a 'position offset'
Can't "Time.time" be used in delegate?
but like, how do i make the position offset what it needs to be
for it to be where the raycast hit the object
It seems to be disabled with the GameObject that is being deactivated. As for why it is being so heavy, it's hard to say. Try with deep profiling mode.
oh, it'll be the difference of the position of the parent position and the object's current position (or i guess the hit point, in your case)
It can
okay, do I even need it though? I disabled it on my world canvas health bar and nothing seemed to change
no idea why it was even there
i assume some component automatically added it
not workin in a weird way
wait
im dumb
It helps if your game is gonna be played at different resolutions, so that the UI is scaled accordingly.
yo guys what is the best way to make a game multiplayer?
I think canvas adds it by default.
How is this error?
its still slightly off
You're calling it from a background thread.
The problem is not the delegate itself, but where it is called from.
Ohh I recall the delegate are called in ReceiveCallback
theyre spawning on like the opposite side of where they should be
What if I want get time in background thread? Is there any alternative way?
Not really. Well, could cache it in some field on the main thread and access the cached value.๐ค
Thx. I c
say the rigidbody on my projectiles have continious detection on but my enemies have discrete on. Is that a waste since the projectiles will still miss detections due to the enemies mode?
turning continous on for enemies tanks fps so
It would help in half of the cases imho.
Specifically, if the collision was triggered by the projectile moving.
okay so keep it on
Depends on who's checking for collisions
Projectile or enemies? If projectile are checking collision you're fine, if enemies are checking collision you're not fine
projectile is
but its still missing when its flying fast
so i figured it was because the enemy was on discrete
If speed is too much it can still miss even if both have continuous on
Because it checks for collision every frame
Say projectile is still yet to touch the enemy in first frame, but if it's already passed the enemy in the next there won't be any collision detected
so no way to improve detection past that
Raycast
so at a certain speed turn projectiles into raycasts?
No you normally want to have either one system in your game.. either all bullets are physical or all bullets are raycasts
It does a sweep every (physics) frame. The times where it may miss tend to be two fast moving bodies or angular movement
What i meant by raycast was if you really want to have a physical bullet you can check for collision by raycast when you fire the object , and if raycast returns the collision. You can manually calculate how many seconds later the collision occurs and then call the collision on desired object after that duration
But yeah this method has downside of its own because you can't predict that enemies will stay in the same position when bullets reach them
That's what the continuous collision detection is for.
What does "it does a sweep every frame" mean? Sorry English is not my first language
Ohhh wow ok my bad then.. i don't know why I always thought continuous detects collision every frame
Are you using Box, Sphere or Capsule colliders?
circle 2d
Ah, 2D
yep
That's what discreet(the default) collision detection does. There isn't any lower precision option than that ๐
Discrete does it every physics frame no?
That's why it's accuracy is ass for even remotely fast objects
Yes. All of them do it every physics frame. Checking collision in regular update would probably be a bad idea
Physics only operates on fixed update, there's never a time it occurs on a frame. It's only moved every frame if interpolation or extrapolation is enabled, but that doesn't mean it's doing any physics calculations
Is it passing through only at high speed?
And is one of the bodies static, or are both dynamic
The other involved object is also moving and doesn't have continuous detection, so there's plenty of room for it missing.
I am unfamiliar with 2D, but they don't seem to distinguish a Continuous Dynamic, so perhaps they only support it against static
there is a continous option though
Yes, which in 3D means dynamic bodies sweep against static ones
3D also has a Continuous Dynamic, which does dynamic-dynamic sweeps, but I am unfamiliar with 2D and don't know whether its Continuous is Continuous Dynamic or not
okay
Explain where you got this information
Surely if you read this somewhere you would provide some context
I was told that my back.cs script has been delted. It was part of an assignment I was doing for class. I accidently saved it as a score file but, it crashed everything so I ended up deleting it.
Where did you "hear" that it comes with Unity?
Do you mean cs.bak?
I saw that on google.
https://forum.unity.com/threads/external-source-control-cs-bak-and-cs-bak-meta.101946/
I haven't heard of that or back.cs before though
I belive so. It was saying somethin that I had a script attached to my main camera? Does the main camera have a scipt?
What hahaha?
So far nothing you've said makes any sense
Im sorry I am new to unity
I guess to answer your first question: no one seems to have heard of back.cs or have any idea what it is.
You've been asked who told you it was a thing, but haven't answered it. Then brought up cameras, saying "it" was saying something.
What is it? Who told you about back.cs? What are you actually asking?
That would help clarify, so that we could answer you
You probably created a script called "back.cs" attached to camera , and when you ran the program something unexpected happened, you blamed the back.cs file and deleted it, and now it shows you got warning that a script is missing on camera?
Yup thats correct
Then no, it does not come with unity
It came from... you
Has your class taught version control yet? If not (and if you're not using it) then start using it.
The script is likely just in your recycling bin.
Okay. Im still getting the issue that it cannot open my OneDrive\Library\Bee\artifacts\2000b0aE.dag\Assembly-CSharp.dll'. I have tried to move it to Desktop but I am still getting the same issue when I run it as well
Oof. Do not put your project in onedrive
Desktop is a bit better I guess
What did you try to move though. The project or the file?
We have not yet. I got the script out of the recycling bin, but when I opened it, it was another copy+paste script I mistaken for another script that was apart of my project

Oh, you're trying to open a dll? Interesting.
I tried to move the file. I made it unlinked to OneDrive. My professor helped me on the process and it worked, but then its not letting me run the game again with the issue
As a beginner I wouldn't touch DLL files
"The issue"?
I have not touched the DLL files at all
it cannot open my OneDrive\Library\Bee\artifacts\2000b0aE.dag\Assembly-CSharp.dll'.
^ this is .dll
Get to the point. What is the actual issue?
If there's an error, share the whole error here. Or maybe even take a screenshot of it.
That for some reason I am getting an error message when I try to run the game. Its saying that it cannot open OneDrive\Library\Bee\artifacts\2000b0aE.dag\Assembly-CSharp.dll
Take a screenshot of the error.
Also what do you refer to by "run the game"? Clicking the play button in unity or building and running it?
As in clicking the play button
- The project is still in the one drive directory. Move it to a root of your disk or something.
- Do one first.
How do I make it move when its already leaked to the project?
Move the project.
Go to the project path. Copy the project folder, paste it in C:\ . Add it in the hub again.
Some basic computer literacy is required to make games
If you can not move a folder I suggest learning that first
They probably thought that if a project is added to the hub, it can't be moved.
How would I make a part of a mesh that I assigned a vertex group to in blender move the uv of that vertex group based on the position of a bone
Vertex groups dont exists in unity
move it there (in blender). as in shape-keyd those verts, and in unity you can use blendshape to interpolate/change the value
Would vertex colors be a better option to use?
You canโt move UVs in shape keys
Pretty much the only option to id a group of verts
Verts?
Vertices
I try to convert inputfield text to int but it always come error line 43.
I already set input field to contains only integer number.
Any idea how to solve this issue?
I used int.Parse but it will comes error that says: FormatException: Input string was not in a correct format.
So i tried int.TryParse and this is happened. Seems like i cant convert string to int
use the TMP input field
iirc the built in InputField gives a weird char in there
how u know that im using legacy?
are you ?
yea
(https://hatebin.com/vqbohqlpey) hey i have been trying to implement a easily maluable double jump toggle for my movement script for my 2D platforming character, but no matter what method i try i believe i am confused and blocked in the way by a previous feature (jump buffering), what would be the best way to impliment double jump? and could i possibly move the jump buffering to a seperate function that could be used when needed more practically?
yea
Theres this thing too #๐ปโcode-beginner message
is it redundant to convert string to string again?
wdym
do you need a field that only wants numbers?
ya
Tmp Inputfield has that built in
ok ill try that
i mean .text is already string so why we still convert that .text which already string to string agaain. Thats wht i mean
convert where, I don't see any conversion
sorry im completly losing my mind
yea it work using TMP. Thanks for the help. Have a nice day
What is the 2d version of Vector3.ProjectOnPlane? There is no project on line
Or can I just use the Vector3 and ignore the z axis?
Wait, vector - dot, right?
Depends what you really need
I'll try both, see if there is any difference
Yeah, in 2d it would just result in a point. You can do it with a Vector3 too btw.
Your plane would just be orthogonal to the camera plane
is there a way to disable my floating joystick while im in the main menu?
Dose anyone know a good 3d tutorial on how to pick up items and put them into my Inventory?
Hi! Is there any way to assing different instances of the same prefab to different events? In my game I have a door prefab, with an open function. Let's say I have a "FirstBattleOver" event, and a "SecondBattleOver", and I have two doors that are them same prefab for the room for each battle. Is there any way for me to assign them their events withouth having to create another script?
Sure.
How could I do that?
Well, maybe provide some more details, because it's not entirely clear what you're doing. Are the prefab instances spawned at runtime? Where do you assign the events?
!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.
No
The prefabs are part of the map
So what I do is
I have a door script
Where, in code, I suscribe the "openDoor()" and "closeDoor()" functions to its corresponding event
I'm trying to make my character move horizontally and vertically using rigidbody.velocity :https://hastebin.com/share/misoxusomi.csharp
Could anyone provide some advice? I understand the local and global aspect in transform.translate, but not with Rigidbodies
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Like "GameManager.FirstBattleOver += openDoor"
But if I do that, when I want to create a door that is exactly the same but opens for the second battle, I'd have to create another whole script
So I'm trying to find a way to assign them in the inspector
So I can use the same script for all doors
You can pass in an int parameter identifying the door.
Not without properly sharing what you want help with
At least share the error if that's what you are hinting at
i did
Hey everyone, I didn't get a response, so i'm just asking the question again, how would I move my character around according to it's rotation with rigidbody.velocity. https://hastebin.com/share/misoxusomi.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
What does the error say..? Hover over the underline
You can do RB.velocity = transform.forward*Input.GetAxis("Vertical")*speed + [same stuff but right * horizontal]
No, the image doesn't explain anything
Hence the request to just share the error instead of making it guesswork
Until then we can't help
It's important you also learn to debug the issue yourself even though it's fairly obvious what is wrong
I guess they removed the } from the monobehaviour at the end of the script
So what is so hard about sharing a screenshot of the error?
Use transform.TransformDirection to transform the movement vector to world space.
Hover over the red line and screenshot the message, or screenshot the Unity console when you compile
If you hover over the error it will also very clearly explain what the issue is, so you could even find out what goes wrong yourself
If I pass "HelloWorld" to invoke 1st method then does 2nd method. Will the output be same? Seem like not same.Where I did wrong?
The question is the same as well as converting Int and string with each other.How to do it?
You would use the appropriate methods in string and int. Not mess with the string encoding.
You're better off asking the !cs Discord for this or maybe #archived-networking considering handling bytes is mostly a networking thing
Join the C# Discord server, a programming server aimed at coders discussing everything related to C# (CSharp) and .NET. https://discord.com/invite/csharp
I never used endianness but it looks okay so idk
Which method is appropriate?
@small gull Any luck with the error?
your ToInt32 method will only read the first 4 bytes of the array. Please read the documentation
Consider using Encoding.ASCII.GetBytes for writing bytes, maybe.
I made a Packet class and just resorted to using Encoding.ASCII for writing and reading instead of whatever BitConverter is
i'm not sure how you expect "Hello World" to be stored as a single int value
Also, maybe you should add some sort of indication when the string ends, assuming your byte buffer will contain more than just the string. For example, end with '\0' indicating null termination, and check for that when reading. Alternatively write a byte before the string indicating the length.
This is most of the code I wrote for this https://gdl.space/fajufogacu.cs
Ohhh. I c. I tried "HELO" . The first function's returning int value is same as the value in C++
You can obviously ignore this if this does not apply
Really, if this is for Web Encoding you shoud use UTF8 not ASCII
But if I invoke the 2nd method with int sent by C++. I get the wrong string
Good one, never thought of that. I should probably take a look at it
I got it
Hi
Is this Unity related?
I will use these suggestions in my next Unity networking project
Int32.Parse and int to string converts implicitly or use myInt.ToString()
ok
Your method signatures are incorrect also, can you post the code correctly
this works because HELO is exactly 4 bytes in ASCII which will fit in an Int32
I just write it by my self. Cz I didnt find any alternative. Actually I was moving the C++ client side code to C#. I found C++ define like this (pic) . I need to have one in C#. Also it still have to be used in switch case. But the value after "case" must const. I'm consfused how to define it in C#?
Yup
Oh, it wasn't about parsing, ok...
So what you have is fine as long as you use ASCII and never use a string longer than 4 characters
Yup.But thanks to u I got to know something important... Otherwise if I use 5 more characters it will raise an error and makes me big headache
just wont work because when to convert to int the last character (if you use a 5 character string) will be ignored
Also you should really use UInt32 rather than Int32
Standard C# would be something like
byte[] bytes = new byte[] {(byte)'H', (byte)'E', (byte)'L', (byte)'O' };
UInt32 asInt = Convert.ToUInt32(bytes);
char[] chars = new char[] { 'H', 'E', 'L', 'O' };
UInt64 asInt64 = Convert.ToUInt64(chars);
{
if (other.CompareTag("Soul"))
{
AudioSource.PlayClipAtPoint(shriek, gameObject.transform.position, volume);
Destroy(other.gameObject);
UpdateCachedSoulsArray();
}
}
void UpdateCachedSoulsArray()
{
souls = GameObject.FindGameObjectsWithTag("Soul");
soulsInScene = souls.Length;
if (soulsInScene == 0)
{
DisableRandomWall();
Debug.Log("All Souls Have Been Collected");
}
}```
for the code above, the int "soulsinscene" never goes below its starting value because even though there are no assigned gameobjs with the tag "soul" in the scene, there is still at least 1 element in the array. this is because in the OnTriggerEnter func, the gameobj with the tag is destroyed but the element that had stored its value in the array is now null. how can i make it so that i set soulsinscene to however many elements in the array that are not null?
is there something better to use instead of souls.Length that im unaware of?
That could solve the multiple characters. What if I want use them in switch case .. "asInt" "asInt64" cannot use in switch case tho. The value I read from C++ is int. I have to convert to string? Then what method would be propriate?
Are you spawning objects with this tag at runtime?
you can use the ints in a switch if you know and hard code what the values will be. To get the ints back to a string your GetCodeFromInt method should be OK
no they are already in the scene
So I'd say find them all on Start and keep them in a List (or HashSet), then whenever you Destroy also remove them from said list and check that list's Count
thats what im doing already, i call UpdateCachedSoulsArray() in the start func as well
but you find them by tag there
don't find them again, find them once and update the list manually on destroy
is that not what im doing right now?
Yep, HashSet<int> and use GetInstanceID() should work well for this
no, you're doing souls = GameObject.FindGameObjectsWithTag("Soul"); which finds them at the moment of updating
my general assumption is that because Destroy actually destroys things later in the frame, you still Find the thing that was just destroyed
you could try doing souls = GameObject.FindGameObjectsWithTag("Soul").Where(obj => obj != null).Count(); if you want to be lazy, buuut am not sure if it becomes null immediately or again later in the frame
i get an error where it cant convert type int to GameObject[]
Because Count counts the result
What i make wrong ๐ฆ
I want see Options and the Gears in the Game view but...
so how do i fix this?
layering issue
The actual fix would be to stop using FindGameObjectsWithTag and just have a singleton manager with a buffer that holds all souls by reference
Then ask the manager for whatever you want
you just need the count, right? rename the variable to soulsCount and make it an int and done ๐
but of course, as mentioned not doing Find again is preferable, Find sucks, tags also suck
@swift elbow here is an explanation on singletons: https://unity.huh.how/references/singletons
It's a much better solution that using Find-type methods in most cases and generally also way easier to manage
what i must do?
drag the gears in the hierarchy to the bottom of the parent
UpdateCachedSoulsArray would be in the manager and rather than finding them all by tag you could have a List buffer that is filled with souls that spawned. The souls could register to the manager when they spawn, or you could have a special "spawn" method in the manager that spawns the souls for you
Currently having issues with this code segment I followed a tutorial on. I think they did something wrong as comments on the video also complain about this issue. Here is the code https://hastebin.com/share/vucekifuvo.csharp
My issues are, the when its dropped or thrown the object changes size, more and more every time. And my other issue is that I can't rotate the object once its picked up. It just moves the mouse, I know I need to disable mouse movement, but cant find a good way to do it
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Hello there, I've been testing a bit with RigidBody, is it a bad praxis to (just for walk) force the speed with rb.velocity = motion, instead of using rb.AddForce(motion)?
I don't see anything that would change the object size. Maybe you're parenting it to scaled objects?
As for rotation, you'll need to debug it.
It's fine if it works and serves it's purpose.
is the easier way i found to limit velocity without extra calculations ๐ xD
umm hey, I cant see text on my buttons can some1 help me with that?
dont cross post
Btw, using ProjectOnPlane and vector - dot both works. I decided to use the latter just so I can pretend I'm a good programmer who can create solutions to my problems on my own. But if you ever feel the need to project something onto 2d: you may just use the Vector3.ProjectOnPlane. It works as ProjectOnLine the same.
nvm I fixed it i shouldve imported the text mesh pro package thing it suggested me that a few times and i ignored it
my collision is still not working
The players parry hitbox has this script: https://gdl.space/lerukiyeju.cs
Everything that has the Parryable should be added to a list, but it wont even detenct the collision.
The hitbox has trigger collider, and the projectile has rb and trigger collider, i use a ontriggerenter2d, why wont it work?
screenshot the inspectors of both objects
public Text CounterText;
private int Count = 0;
private void Start()
{
Count = 0;
}
private void OnTriggerEnter(Collider other)
{
Count += 1;
CounterText.text = "Count : " + Count;
}
trying to increase the count in numbers if collided
when collided it wont increase counter and will give these errorrs
CounterText is probably null
!code read below on how to post code properly
๐ 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.
colliding with "box"
it increasese counter
box has the script
so I copy pasted one of the cubes here
and added script to it
thought it'd work
it works with box
doesnt work with the cube I copied from the box parent
Because "Box" has a text object assigned in the inspector for "Counter Text", and "Cube 5" does not
counter text is null like @pallid nymph said
this doesn't have a rigidbody, so it won't receive physics events (ie: Your OnTrigger methods in PlayerParry.cs wont get called)
(only one of the objects need a RB for events to work, just FYI... although a moving object must have a RB, so yeah, you probably do need to add one)
A moving object that requires physics events must have an RB
A moving object that has a collider should also have a RB
nope
yes
A moving platform doesn't need an RB
fixed it but unity crashed dk why
it doesn't strictly need one, but it really should have one for performance and stability reasons, it's in the docs
i cant even add a rigidbody to the hitbox cuz the parent already has one.. or something
otherwise it's considered static (and it really is not, because you know, moving)
link pls
this has a 3D collider not a 2D one
it will only be considered static if you mark it as static.. surely
@hexed terrace ah, apparently the performance cost of static colliders is gone and that's old information, so my bad... used to be here: https://docs.unity3d.com/Manual/CollidersOverview.html and you can read in Collider types that static is collider without RB
It also doesn't make sense when you remember the included CharacterController doesn't want a rigidbody component
Static Collider
This is a GameObject that has a Collider but no Rigidbody. Static colliders are used for level geometry which always stays at the same place and never moves around. Incoming rigidbody objects will collide with the static collider but will not move it.The physics engine assumes that static colliders never move or change and can make useful optimizations based on this assumption. Consequently, static colliders should not be disabled/enabled, moved or scaled during gameplay. If you do change a static collider then this will result in extra internal recomputation by the physics engine which causes a major drop in performance. Worse still, the changes can sometimes leave the collider in an undefined state that produces erroneous physics calculations.
From 5.6 .. all the way up to 2019.1
๐
That is an interesting point about the Character controller - haven't thought about it ๐ค But yeah, as you can see, it was a thing some years ago ๐คทโโ๏ธ I haven't really done much physics lately :/
I sort of vaguely remember that now I've read it, but like you, haven't done much physics in a while.. certainly none that would touch this.
hello, i have those buttons and i want to turn them red and to add 1 to a variable on click. In order to make the color stay the same between sessions, do i have to create one playerpref for each of these buttons ?
because there will be a lot of buttons, they all do the same but it's important for each button to stay the same color, they each mean something different (meaning validated or not) between sessions
mm... if they have some sort of ID / unique name, I guess you can easily store them in PlayerPrefs... I'd probably prefer to save them in a file, because PlayerPrefs kinda suck, but it would work quite similarly
If it's info that doesn't matter that a user could change easily, be better to use a json, so you can just use an array of some sort
it is sort of tasks, when completed you click the button that changes color
hello. So I have an object with 500 thousand speed and it rotates around another object. when it collides with an object thats in its path counter is supposed to increase. I tried with 100 speed it works fine. but with 500 thousand speed collision doesnt happen sometimes and happens inconsistenly how can I fix this
it's going too fast, try changing to ....err... is it 'continuous' on the RB
fast
because it's the movement of that that does the detection
changed it to continous
still same
its supposed to increase like 500 in one second
in one second it rotates around it 500 times
but counter only increases by 2 or 3
how does it rotate around?
with transform.rotatearound
right...
yea
so... whenever you deal with physics - you need to use the Rigidbody to move/rotate the object, not the transform
I know its bad but i chose it because was easy
yeah, and as you can see - it doesn't work
but doesn't work with physics!
ok I actually forgot how to do it with vectors let me research and come back here real quick
now to the second part... even if you do it with a RB, it still wouldn't work for 500 collisions per second, if I get it correctly
I highly doubt the physics engine would simulate 10 enter/exit per tick, because your object rotated 10 times over some other object
you'll need something custom to simulate such things
Hello is there any way to find where i have set a player pref
Because i added a player pref to track what level the player is on and i dont remember where in the code i put it
As in which script
Use your ide search function ctrl+f
is it hard
is there something custom made already I could use
if you're good at programming and physics... yes ๐ otherwise it's impossible
no idea, never needed something like this... google may know more about simulating such things... also you need to understand why are you simulating it - what's the goal? perhaps it doesn't need to be too precise and you can go with some fake but much simpler approach ๐คทโโ๏ธ
I guess yeah
there probably is a simpler approach
how can I learn the maximum limit
for detecting collision
like whats the collision limit per frame
yo u know nevermind. I fixed it by slowing down the timer
there was a timer like 0 1 2 3 and number of times collision hapens like 500 for example i set timer precisely to increase by 1 only when 500 is there
its nothing like realtime but I cant deal with writing my custom thing
omg how did i not notice... thank you man
Don't feel bad, apparently no one else did either
Hey guys, So I was just following the official unity Create with code tutorial series in which they moved the backround to the left by resetting it's position after it reached it's half point(the backgrounds). they do this with the help of a box collider and then using the box collider to divide the x size by half and then resetting it's position. but the background just goes down and stutters. The player jumps force also seems to decrease. Pls help
here is the code
line 13 is the obvious give away
what is wrong in it?
read it
it seems fine to me.
sorry I meant 19 not 13
yeah still seems fine
wrong, read it again, carefully
no still not seeing anything wrong
since when do you terminate an if statement with a semi-colon?
when someone says 'carefully' it means character by character
Help pls , when I play the obstacle disappears
But the physics is applied though
Also tried changing the layers
What does this have to do with code?
in all fairness that one was pretty hidden ๐ good catch ๐
This part has nothing to do with the code
There are other aspects which have been coded
really?
well, I didn't see it too, and I do read a lot of code... it's not that one doesn't see it, it's that brain auto-ignores it ๐คทโโ๏ธ
Hey sorry, but the background still goes down from 9.5 to 0
yep, and the art of the good programmer is to see what is actually there not what you want to be there

My supiror was nearby. I have to hide....