rb.velocity = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")) * moveSpeed * Time.deltaTime * 60;
So i made this top down movement line of code and noticed that it moves way too fast diagonally, I found on the documentation that to fix this i need to normalize it but when i add .normalized like in the following line it genuinely tweaks tf out idk how to explain. Any way I can normalize the vector without it having an aneurysm?
rb.velocity = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")).normalized * moveSpeed * Time.deltaTime * 60;
#💻┃code-beginner
1 messages · Page 282 of 1
Well for one, you don't need to multiply it by Time.deltaTime.
rb.velocity handles that for you.
Same with the 60, idk why you need to multiply it by some random number.
if i remove both of those and its just ... .normalized * movespeed;
it still freaks out
idk theres not much else lmao
well how is it "freaking out"?
the movement acts really weird when it's normalized, if i tap any movement key and immediately let go, it will keep going for an extra half second
and the movement is overall just super jerky and unresponsive
Oh I see.
but is completely fine when not normalized
Do you know what normalizing does?
im not exactly sure no
its like something to do with the radius of a circle around you or smth
this is due to using GetAxis which includes input smoothing. you want to use GetAxisRaw instead
thank you :)
ill try it
I'm sure he wants a bit of smoothing. Issue is that normalize is setting it to 1 even when values are low.
oh yea cos something about magnitude of 1
yeah this worked, thank you :) I'll be able to add my own smoothing myself
Normalizing a vector refers to making its length 1. Normalized vectors are useful because they can represent directions.
if you want smoothing from GetAxis or to support analog movement with lower values, then clamp the magnitude of the input to 1 rather than just normalizing it
If you want to use the smoothing provided by Unity, you can use this with a value of 1.
https://docs.unity3d.com/ScriptReference/Vector2.ClampMagnitude.html
This will prevent the length of the vector from exceeding a value of 1.
So you won't speed up on diagonals.
oh i see
Also, do you know why it's speeding up on the diagonal?
yeah
because moving up 1 and to the side one
so 1.41 units
ish
Yep, exactly.
wait how is clampmagnitude different from normalize?
Normalize forces the length to 1, this includes smaller values.
because it allows the magnitude to be lower than 1
ClampMagnitude "clamps" it to some specified value. Aka it will not exceed the value, but can be smaller.
oh that makes sense
So what was happening was Unity trying to smooth out your value, slowly increasing it to 1 (full speed) as you held the button, and slowly decreasing it back to 0 after you let go.
Normalize forced all those smaller intermediate values back to 1.
And only gave 0 when the input was literally giving 0.
Which caused that "unresponsiveness".
that actually makes a lot of sense
aight rate the new smoothing i added
not sure what the f means but i saw people typing it after numbers in videos in the past and so it wasnt working at first so i typed an f and it worked 🔥
It might be useful to check out some of the functions in Unity's Mathf and Vector classes structs. There's some exceedingly useful stuff in there. Specifically the Lerp, Clamp, Distance and MoveTowards functions.
https://docs.unity3d.com/ScriptReference/Mathf.html
https://docs.unity3d.com/ScriptReference/Vector2.html
based entirely on this statement, you should stop what you are doing and go through some beginner c# courses. there are some great beginner courses pinned in this channel
that's probably a good idea
I've tried to search to understand some of the things I have seen in the past like the f that people sometimes type after numbers and what a vector is (point? line?) but honestly the unity documentation isn't very easy to understand
so yea some c# courses could be helpful
f marks the number as a float.
Do you know what a float is?
non integer number?
Ya. It stands for a floating point number.
from what ive gathered
It represents "real" numbers. Aka everything with decimal places.
ok sick, why isnt every number always automatically parsed as a float then? why do we have to do it manually?
Vectors are more of a math concept. They're "lines" composed of a magnitude and a direction.
You can do an absolute shit ton with them.
there are more than just floats, sometimes you only want whole numbers. outside of unity, double is used a lot more as well.
How floats do what they do is kinda complicated.
Just know that the default is integers, which are whole numbers.
You use them for counting things and math.
Floats represent all the real numbers. You use them for math and more math.
🤣
good to know
is there any c# documentation that contains examples for most things? I've used documentations with examples before and they made it a lot easier to understand how certain scripts can be used and to learn languages as a whole
how would i go about having a selection of buttons all going to different scenes, kind of like a game selection menu.
use grid layout group
Do you know how to make a single button do something ?
i looked at that but didnt know how to use it exactly
and yea, but i dont want to code 32 different buttons on one screen
run a for loop and instantiate the buttons / thumbnail objects in the grid layoutgroup
okay
make a prefab for one should look like / button component on it. then from there have a script linked to all the componets to change like icons
i wanted to use grids for a Supermarket simulator but for a PC repair shop, and ran into issues using grids so i gave up i suck
ive realized even though i have the power of god and anime on my side, I cant find it progressive to sit and stare at a big project forever and get discouraged. So i asked chatgpt to come up with a list of 32 games from easy to hard to make for beginners. I plan on putting it all together and refining it into a lil pack 😛
Im a bit confused on how i would make an image go to the designated spot? ig ill play around
HI. I can't do a certain thing in my game. when I hit an object, it deactivates and reactivates another cube. These cubes have a specific tag. How do I tell to activate cube for example 1, after hitting cube 0, and then for example when I hit cube 1, it deactivates and activates cube 2. I tried searching on google, but I can't find anything :(
Store which object you want it to affect on each cube. You can drag the reference in inspector
yes but, I want cube 1 to be activated when I hit cube 0 etc. How do I write this into the program?
because there are not just two cubes, but many
oooo i did ittt i feel smart 😮
Store which cube you want to be activated on each cube. With a script
Activating and deactivating should just be through some public method on the cube script, so that the cube handles the logic.
If you need a very specific structure to it, itll have to all be assigned manually in some way
okk, i try, thx
How would i be able to make the grid usable after instantiating prefabs? I cant exactly use the scripts on the buttons and match them with scenes i think
i dont have any access to it until runtime
What's the issue?
I got the grid layout working, it instantiates the button w/ image on the correct spot. But how would I get it to do anything at runtime if i cant reference it before runtime?
You can add listeners at runtime
whos listenin?
how would i reference the script to it tho
Reference what script?
while (true)
{
// Go to the throne location with offset
agent.SetDestination(throne.transform.position);
// Wait for 3 seconds at the throne location
yield return new WaitForSeconds(3f);
// Go back to the work location with offset
agent.SetDestination(workLocation);
// Wait for 3 seconds at the work location
yield return new WaitForSeconds(3f);
}
this loops for like only 3 times then they will get somewhat stucked in the position
im realizing i can just put the script on the object. im dumb
you're probably starting a whole bunch of those coroutines
You can create a button prefab that has a script that causes a scene transition. When instantiating the button, you tell that script what scene it's supposed to transition to.
based on the script i only have 2
You could also just directly add a listener to the buttons "OnClick" unity event, and just specify what scene to transition to. Something something anonymous methods.
show the full code
!code
Posting 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.
its long it became like that
if only there were specific instructions for posting large code blocks. since you don't know how to read, i guess we'll never know if that is the case
anyway, this is 100% the issue
it automatically creates a text file
hello
i am a beginner
i am looking forward to introduce myself and meet all the fellow members and experience how the creation team works !
ahh i might need help doing it right, i think im doing it just slowly
that's fine
like now i have a method to loadbysceneindex... but how do I give a number to the scenes at runtime, or do they need to be given at runtime?
the number is assigned when you add the scene to the build settings
how would i reference the number? would i drag it on a reference i make myelf? or is it a method built in to unity already?
unless i need to make a dictionary or soemting
thankyou, trying chatgpt seems to do more harm than good
no surprise there
haha i think the only good thing it did was build a controller that used character controller and 3d pov
i think 5 minutes faster debuging it than making it myself
is it better to loadscenemode.single or additive most the time?
that depends purely on your game design
Chatgpt is a text-/languagebot. It's not perfect in creating or improving code. Just like decrypting stuff like Sha256 or smt.
yea it basically makes stuff up. Right now im finding a problem with referencing the scenebuild number. I made a build and have the button code written and ready to go, but like... how XD i think im just blind
public void LoadBySceneIndex(int index)
{
SceneManager.LoadScene();
}
im stuck at what to code to for the value index
the documentation is full of information
https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.html
ookay okay were getin somewhere
man, your first action should be to RTFM
lol yea i start there, but get confused fast. Theres alot more there than i need but i dont know exactly what im lookin for. So it takes a while
money.text = GetComponent<CoinUI>().amount.text;``` is one faster then the other? trying to work out the difference
its a pretty good tool for psudocoding if you're lazy, but when you're new you'll be referring to docs a lot 
the first does not need to look up a reference because it already has one. The second has to refer to Unity to get a reference so the first is much more efficient
adding onto the above statement its efficient because you dont want to be going GetComponent<>() calls every update if you can avoid it 
The reason i ask is becuase its a DDOL and when i load the scene the field says missing, yet the clone Coin UI is there. Could it be a who loaded first issue?
are DDOL loaded before normal gameobjects?
you can try using SceneManager.sceneLoaded to test? 
tbh the code makes no sense as the component seems to be in the same gameobject so why would it need a singleton instance reference in the first place?
im calling it on my battle manager its its own UI, and CoinUI is its own UI
need to get a ref to the amount
then your GetComponent call is nonsense
yh im using sington, is that also wrong?
they're saying the second line is redundant if you use the first line
if CoinUI is DDOL and a singleton, no

should not lose the reference then
what is battle manager? where this code is being executed?
yes, want me to make a quick video?
no
if Money is correct when you ddol CoinUI and the TMP referenced is also DDOl then there should be no problems
In battlemanager on its start/awake are you referencing money = CoinUI.instance.money?
or smth like that
yh
money.text = CoinUI.instance.amount.text;
hang on i am setting the .text should i be setting the gameobject?
I mean either work but you only want text in this case so text is fine i'd assume
yh so im thinking maybe its a load issue? maybe battlemanager is being loaded before the DDOL?
but would that not throw a null ref error or somthing
is it possible to convert 1st person camera to 3rd person camera?
have two cameras and switch their .enabled if you want to do it in runtime, or just move the camera in the scene
so i just move the camera from the capsule and put it behind the player?
and btw to add sfx do i need to create a file named ''sfx'' and add audio source?
because i am a beginner im trying to learn and help
try running CoinUI.instance.amount.text from both scripts on each scene load maybe? is there a problem with the reference before the scene loads 
i am currently trying to make a soccer / football game but i am lost
you can call it whatever the heck you want 
its just good practice to call it names that you'll be able to understand (and potentially others)
so sfx is good start 
thx i am literally looking up for tutorials but cant seem to find any soccer game tutorials 😦
you can look up tutorials for things you need rather than a game specifically and stitch it all together 
ok i fixed it
{
//Singleton method
if (instance == null) {
//First run, set the instance
instance = this;
DontDestroyOnLoad(gameObject);
} else if (instance != this) {
//Instance is not the same as the one we have, destroy old one, and reset to newest one
Destroy(instance.gameObject);
instance = this;
DontDestroyOnLoad(gameObject);
}
}``` i added this
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
if (instance != this)
{
Destroy(gameObject);
}
}
}
``` instead of this
but i dont no why that would work
cant find
it's actually pretty obvious. In your first code you are replacing the instance in second you are not. So the instance was not being carried over from scene to scene
the comment even tells you this
//Instance is not the same as the one we have, destroy old one, and reset to newest one
because it is coming from the newly loaded scene
ok so even tho its a ddol on a new scene it creates a clone, would that then mean its a new instance?
yes, of course
ok i understand now thanks steve
question is why do you have the same object on multiple scenes if you are going to ddol it?
that makes no sense
the ddol object will exist for ALL scenes, so no need to duplicate it per scene
So I reworked the FSM code, states no longer reference StateMachine. The StateMachine now checks transition by using a Func<bool>, but uhh it's got lot more spaghetti than I thought. Could someone check for me if this feels right?
https://gdl.space/ecurofotiw.cs
Can you explain a bit more, where you think my mistake is so i can understand. I thought i was doing DDOL correct with my awake instance.
this
private void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject);
}
else
{
if (instance != this)
{
Destroy(gameObject);
}
}
}
is what you need in one scene, nothing more
I am assuming this is on your CoinUI class
because instance is static it can be referenced from anywhere without an additional reference
CoinUI.instance gives you all you need
the only thing you need is to make sure that the only things that the instance references are also DDOL
guys please can you tell me how to make a soccer game cuz i am new 😦
Did you try to Google it lol
There is plenty of possible ways to make a soccer game
And define soccer game
you are joking aren't you? Do you have any idea what you are asking?
bumping my questions
what am i asking?
why do my setting up transitions takes like 40 lines
does anyone have a better way of setting up transitions for statemachine
Do you really think anyone can tell you how to make something so specific on a server like this?
what server do i need to be in?
Any server won't tell you how to make a soccer game
like ik how to make ball bounce but how to make it shoot idk
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
a question to start is how did you make it bounce?
did you use a rigidbody? are you adding force to it? what happens if you add more force, or try different force modes? 
yes i used rigid body and physics
no i didnt add any force
try starting out by adding force to a rigidbody 
wanna dm pls
all the concepts are covered on the learning site i linked. best to spend some time there
dw i will
and i am
i just have problem with cloth too
Thanks steve
What happened when two scripts attached to a game object implement OncollisionEnter? 
whatever you tell them to do
when two colliders hit each other, any objects with a script containing oncollisionenter will be triggered
bearing in mind that there also is OnCollisionEnter2D as well 
is there a collaboration system in unity where you create games with another one?
Git or Unity Version Control
rlly
Thanks, i got it
it isnt roblox haha. You can share the files via git or you also can use unity version control. I recommend git. You cant build in the same project, because unity is on your device and not on the cloud.
i have a problem with cloth i dont understand its given properties
i dont even play roblox
and thanks for the help
it was just an example :)
no problem
i think handball would be way easier
Just start learning finally instead of spamming the channel with such generic questions
thx
Hi everyone, is this the correct way to use lock statement in C#? My game has multiple threads accessing the Inventory simultaneously. Thanks
no this isn't going to do anything really
because you're just locking around accessing the list reference. But once the caller has a reference to the list you have no control over when or where they access it or modify it
My game has multiple threads accessing the Inventory simultaneously
I question the motivation of this
"multiple threads accessing the Inventory simultaneously" I have no idea why on earth you'd want to do this. but I'd recommend using the built-in concurrent collections.
https://learn.microsoft.com/en-us/dotnet/standard/collections/thread-safe/
I want everyone in a guild to be able to access the guild's inventory at the same time, I want to learn how to synchronize 
I still don't know if what I'm doing is really right
well if it's a multiplayer thing, you'd still want to do it 'in order' synchronously on the server, based on the order of the packets
I have a question. Can I see the base layer as an Eulerian graph?
Did you try to Google it first? lol
Anyway this is a code related channel
hi, is there a built-in function that detects the number of keys being pressed at once?
No. Also keyboard hardware will severely limit this anyway
no like....at least two keys?
That seems like a strange requirement. What are you planning to use it for?
unity struggles to run an animation when the player is walking diagonally so i thought instead of detecting every two keys which would result in 4 if statements, i would detect if two keys are being pressed, if one of them is the up arrow key, i'd run the animation of going up, if it's the down arrow key, i'd run the animation of going down
You can do that in 2 if statements
I also don't get why you need to check if other keys are pressed, just check if up key is pressed -> always play the up animation, if down key is pressed -> always play the down animation
yeah but i have other if statements for when only the right or left key is pressed
Why is that a problem?
Only because you tell it to do that
is it 2d?
yeah
well two conditions are met there, going right, and up for example, so it keeps switching back and forth from both animations
you tried using blend trees? i dont know how well they work with 2d but in 3d all you need is to provide the direction vector in the form of 2 float params to a blend tree
well no, idk how to use them
Yes, because that's how you've organized the code
but hold on i think i might have a fix
just right click in AnimatorController and create a blend tree and check it out
sounds fun
u know, that makes sense, imma try to change it
why is Destroy(); not running?
as you see in the second image, i am invoking the action, which is Destroy();
any errors?
nope
Transform position2Transform2 = GetEnemyAtOriginalPos2();
if (position2Transform2 != null)
{
Debug.DrawLine(playerTransform2.position, position2Transform2.position, Color.red);
Debug.DrawRay(playerTransform2.position, playerTransform2.forward * 5, Color.blue);
}
foreach (var battlers in activeBattlers)
{
Transform enemyTransform = battlers.transform;
Vector3 directionToPosition2 = activeBattlers[0].transform.position - enemyTransform.position;
directionToPosition2.y = 0;
Quaternion lookRotation = Quaternion.LookRotation(directionToPosition2);
enemyTransform.rotation = Quaternion.Slerp(enemyTransform.rotation, lookRotation, Time.deltaTime * 5f);
}
if (activeBattlers.Count > 0 && activeBattlers[0].isPlayer)
{
Transform playerTransform = activeBattlers[0].transform;
Transform position2Transform = GetEnemyAtOriginalPos2();
if (position2Transform != null)
{
Vector3 directionToPosition2 = position2Transform.position - playerTransform.position;
directionToPosition2.y = 0;
Quaternion lookRotation = Quaternion.LookRotation(directionToPosition2);
playerTransform.rotation = Quaternion.Slerp(playerTransform.rotation, lookRotation, Time.deltaTime * 5f);
}
}``` im trying to make my player face the npc at pos2 but it seems to be off by nearly 50deg
does execution reach that line?
you ran the debugger and the line is hit?
yes, the invoke line is being reached, but the Destroy(); method is never called
hope this is okay to post/ask: is there a way to change the font/material face color slowly and fade between each colour or just cycle through the rainbow, similar to the video?
you can see the break points in the images
and when you step into what happens?
wdym "step into"?
when i press the button, the yellow marker moves to the next line
look into destroy object, maybe something like invocation target is null or something else
this can be some closure/uobject related fuckery, i dont know
the flechette value, is not null
If it's a TextMeshPro text, you can change or animate the color in code . . .
which c# version is that?
your delegate type is Action<T> but you pass Action<void>
i just dont know how it even compiles, but in case when you need to match signatures you can wrap it into a lambda
DirectHit(..., x => { Destroy(); }, ..)
method needs to return Hunter_Flechette right?
nono thats just your DirectHit
you pass it, as a lambda that already matches the signature of Action<T>
x is the argument
you just dont use it inside the lambda, since Destroy() has no params
dude i dont get it
what exactly?
i also dont get how it allows you to pass in an Action, when the signature has Action<T>
anything you've sent since this message
just try the x => { Destroy(); } instead of Destroy
if it works ill explain what you dont understand
like this? config.DirectHit(this,rb, x => { Destroy(); }, collision);
yes
it works!
ok, can you change destroy to Destroy(Hunter_Fletchette x) ?
why not
in terms of your architecture
because you may want unified Destroy() across all your classes
otherwise each will require random bits of params
right, so before it didnt take any perams, but now it takes x of type Hunter_Fletchette, which the action passes that x onto the method. correct?
someone more up to date may explain why compiler allowed you to pass in a delegate with signature mismatch
yes, param and passed delegate have the same arguments, which you tested with a lambda, so that was the cause of it not working, but for .net 4.8 it wouldnt even compile
actually not .net just old c# version
i cant find anything on the topic, cant come up with good search terms, but my guess is, if it is a feature in new c# and not a bug, it may try to generate a delegate that matches the sig under the hood, and because unity doesnt fully support all new c# features it may fail at that
when I jump beneath the coin, my player touches it and falls down, I want my player to jump equally at all times. 2D game
thanks for the reply, unfortunately haven't been able to accomplish this though 😂
it is a textmeshpro
but im trying to change the face - color of the font material if possible, the material font is only attached to one text object
any tips?
#854851968446365696 people on mobile can’t see that
Can you also send a screen recording of what’s happening?
me?
Yes
okay
Why are you calling me? Send a screen recording in here of what’s happening.
@silver girder
…why can’t you send a screen recording
i dont have a recording app
And nothing personal, but I’d rather not hop on a call with someone I don’t know
Use obs
okay i will download it and send
And post your code correctly
Windows logo + G should work too?
idk
People on mobile can’t see txt files in discord
lol, cause everyone's using obs these days
the file is too large
!code
Posting 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.
follow the instructions.
Is there a standard pattern for automatically unsubscribing from all Actions in OnDestroy() ?
i will upload the vid
if you're talking about unsubscribing from events (or more generally removing yourself from delegate fields), then no, not really
for input system callbacks, I'll make a Dictionary<InputAction, System.Action<InputAction.CallbackContext>> so that I can iterate over it to subscribe and unsubscribe, at least
Instantiate(bullet, SpawnLocation, Quaternion.identity);
``` When I do this it starts infintely spawning bullets, I want it to spawn only once. 2d game
Can you provide a brief code example for that? Do you statically declare the dictionary?
nah, I just fill it out in Awake :p
is it maximally efficient? no, but i'll survive
I do want to figure out a way to detect when I forget to unsubscribe from events
What exactly is the problem? What is happening in that recording that you don’t want to happen?
other than just changing scenes and destroying objects and seeing if an error falls out
go to 1:00
how do i use vector3.rotate towards for lets say i press A and i want it to rotate left?
and go to 1:44
How much "left" do you want it to rotate?
And over what time period?
little
That's pretty vague
ill go with just time.deltatime * some speed
What is going wrong? Looking at your code, the behavior seems to be expected. What is the issue here?
Transform.Rotate will be simpler
i mean it should be like a game rotation like slowly uk
No idk what a "game rotation" is
whats the difference?
umm i mean like how do i even say how much it rotates
lets say 90
Transform.Rotate lets you specify how many degrees to rotate
when i add the script to the player and ball it gets anchored and when i delete the scripts the ball acts normal with the physics
okk let me try
RotateTowards rotates towards a certain rotation. Not necessarily a certain amount
Post your code
Hello There. I have an enemy prefab that requires the player & cameras transform transform. however every time I move it into my scene I have to reassign the players transform to the script, what's the best way to automate this?
my thoughts on this is to create an empty game object and create a script containing public variables for all my references so instead of assigning the variable directly to my enemy controller script I could replace it with something like "Refernces.playerTransform"
ok i will post the two codes
so if i want a smooth rotation like in games like gta 5 and watch dogs2 its perfect right?
That's extremely vague. Lots of things in those games rotate in a lot of different ways
you can do a findgameobjectwithtag and assign that on start awake
😭 how do i explain
Not like that. Delete that and use one of these !code
Posting 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.
YO WTF LMAO
like the large code blocks?
i think transfrom.rotate is not right cuz its instant i want it to slowly rotate
heres what ive used before
ill have a read thank you
You can also make the players transform a public static set of vales and then reference them from another script
nvm works fine thanks
Yes, that is definitely a large code block. Let’s start from the beginning. Delete that giant block of code you posted. Put your question, the recording, and both scripts in one message.
i dont understand
What don’t you understand?
deleting "giant blocks" of code i posted and putting question and recording and both scripts in one message
First step, delete this.
i deleted it from unity studio
just rotate by a little bit at a time. There's no difference
No, sorry, that’s not what I meant.
yea just saw that thanks
Vector3 rotationPerSecond = new Vector3(0, 50, 0); // 50 degrees per second
transform.Rotate(rotationPerSecond * Time.deltaTime);```
@sonic dome
np
Alright, put the scripts back into unity studio. Use this message to copy and paste into a new script file as needed.
okay
all scripts except Target script are there
@thorn holly
oh thanks
What happened to target script?
deleted it from unity studio
Can you recover it?
added it back
Okay, so everything is how it was originally?
yea
Next step: delete this message.
deleted it
Next step: make a message that looks like this.
(Question here)
(YouTube video link)
(Script one name): (script one link)
(Script two name): (script two link)
Use one of these links to post your code !code
Posting 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.
Why does the ball get anchored when i add scripts to their places while the ball has physics ?
Youtube Link: https://www.youtube.com/watch?v=2zy8WWU48Xs
Target Script : https://hastebin.com/share/osoqebokor.csharp
Equipt Script : https://hastebin.com/share/igobekeqos.csharp
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
@thorn holly
“What is happening to my script” isn’t your question. Describe what exactly the problem is.
i edit it
edited
Good job. I know that was tedious, but it’s important to format your question correctly. Now we can figure out what’s going on
alright bro thank you !
i hope you find the issue and report it by maybe editing it or send me a short snippet that can help me edit the scripts !
I think I found the problem. Your setting the ball’s isKinematic to true, do you know what that does?
no i dont
Basically, that makes it not use physics. Something that is kinematic can only be moved explicitly through script, not with the physics engine
Is this code from a tutorial or chat gpt or something or did you make it yourself?
so do i write "isnt kinematic""
No
from a tutorial but wrote it myself
Do you know basic c#?
no
You should definitely learn the basics of c# before using unity
aw man
Well, I mean, you have to be able to make your own code if you want to develop.
I reccomend using codecademy to learn c#, but there are many online tutorials you can use
After you learn c#, learn the basics of unity here : !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Then you’re ready to start developing
idk how
So to be able to make your own code, you have to learn c#
how much can it take to learn it?
? Do you mean how long does it take?
yes
You can’t really quantify that, it varies a lot between what tutorial you’re using and from person to person. Codecademy estimated their tutorial takes about 20 hours.
20 HOURS JUST TO LEARN??????!!!!!!
Don't be so dramatic
It takes longer "just to learn". Have you never spent time learning a new skill before?
i have
thanks for your help earlier if I cache the results like so
void Awake()
{
rb = GetComponent<Rigidbody>();
healthBar = GetComponentInChildren<HealthBar>();
player = GameObject.FindGameObjectWithTag("Player");
playerTransform = player.transform;
}
will it negate the performance cost of using FindGameObjectWithTag? I intend to have a large amount of enemies.
Then you should be smart enough to know it takes time to get anywhere.
20 hours to know the basics. Beyond that, you will be constantly learning.
ah okay 😄
So yeah, learn c# basics, use unity learn, and then you can start developing
something is wrong..
What is?
they told me to write " $ dotnet run" i wrote it but didnt write anything
oh yea figured it out
Just keep following the tutorial
I literally just did a couple of simple tasks in Java and CSS on a course and then jumped to Unity Learn and finished the Code part in like 2 weeks?
Now I don't know many, many things, but I feel kinda confortable coding
Cool
So it is not really hard, just takes some getting use to it, like everything
thx
wetnoodle11 and all members who helped god bless you guys
Of course! We’re here to help.
anyone able to provide feedback on this?
if I cache the results like so
void Awake()
{
rb = GetComponent<Rigidbody>();
healthBar = GetComponentInChildren<HealthBar>();
player = GameObject.FindGameObjectWithTag("Player");
playerTransform = player.transform;
}
will it negate the performance cost of using FindGameObjectWithTag? I intend to have a large amount of enemies.
very much appreciated as always.
i'll happily provide additional context if need be
it doesn't "negate" it. It just means you only pay the cost once, and right when the object is created.
as long as you ony run this in awake it should be fine, you wouldnt want to run it un update. there is a seperate method called FingGameObjectsWithTag which will return an array of objects with the tag. That can be super useful, I use it to track the collectibles in my scene.
Brilliant, Thank you both
Hello! My Intelisense seems not to be working anymore, any hints?
I've tried to Regenerate Project Files
Okay... it is working now?
Does anyone know how to fix an android app icon?
Can't seem to get it to fill the icon space , google keeps adding the white boarder
I have resized the image to be 512x512 and I Have shrunk the icon to fit the subject matter in a 344x344 interior dimensions with a boarder fill
Instantiate(bullet, SpawnLocation, Quaternion.identity);
``` When I do this it starts infintely spawning bullets, I want it to spawn only once. 2d game
perhaps show more than a single line of code
theres nothing else
except spawnlocation vector2 and public gameobject bullet
I dont have a problem in code I just do not know how to do it
of course there is something else
you can't just slap one line of code into a script file and have it work
share the entire script.
public class bulletSpawn : MonoBehaviour
{
public GameObject bullet;
public Vector2 SpawnLocation;
void Update()
{
spawnbullet();
}
void spawnbullet()
{
if (Input.GetKey(KeyCode.Space) == true)
{
Instantiate(bullet, SpawnLocation, Quaternion.identity);
}
}
}
i KNOW the difference
Then you know how to solve the problem.
I have a class with two modes, and this class will switch between them. What is an effective way to implement "mode"?
For example, if I use the flags Mode1 and Mode2, I'll check to see if Mode1 or Mode2 return true before proceeding with any logic.
Another example is use polymorphism. But it's only have 2 modes. Is it worth it?
What exactly changes between modes?
Use an enum
My NPC system have 2 type of behavior. 1 behavior is following preprepared data (i named it PathAction), 1 behavior is following state machine.
They first running around the scene using PathAction. If player or the environment impact them, they may switch to the statemachine.
That sounds perfectly reasonable to just do with an enum
how do you make a shooting ball cuz i have no idea 😦
In this video i make a Ball shooting in unity.
Thanks for watching.
nooo
not that
its okay if you didnt understand
what i want is like handball shooting
Well the question was incredibly vague
any tips?
basicaly throwing
in vr?
then its the same isnt it
if(Input.GetMouseButtonDown(0)) <--- this is in update
{
if(!attack1)
{
anim.SetTrigger("attack1");
attack1 = true;
StartCoroutine(combo());
}
if(attack1)
{
anim.SetTrigger("attack2");
}
}
}
IEnumerator combo()
{
yield return new WaitForSeconds(10f);
attack1=false;
}
why is it that both the attack animations r being triggerd one the 1st press?
idk
Vr is done on pc generally
can you send me a tutorial of handball shooting i am really lost
yo thx for that information
just shoot it with less force i guess, then it goes from being like a bullet to being like a thrown ball right?
You first have to describe what you want clearly and with detail
if(!attack1)
attack1 = true;
if(attack1)
review your logic
but if u google ball throwing tutorial then you will find that too https://www.youtube.com/watch?v=ZonVUxvZiwE
This video will show you how to make a Ball Throwing Game with Unity. Throwing objects or hitting cans. Games like that can be done with this script.
Explanation Video: https://youtu.be/fljP8zJ75Lk
Ball Thrower: https://pastebin.com/ScXTY011
Ball Script: https://pastebin.com/2JPEYMiw
Learn Python: https://www.udemy.com/course/python-for-complete...
with character tho
yea i used else if then its kidna sorted by bad
We are not your personal google. JohnSmith is just googling what you are saying. You can do that yourself
idk how
like i cant find them
You are being too specific then. Johnsmith gave you a tutorial that will handle part of it. Now look for how to animate
Combine those
Bam
Build your own Unity games HERE: https://academy.zenva.com/product/unity-game-development-mini-degree/?utm_campaign=youtube_description&utm_medium=youtube&utm_content=youtube_2017_unitybasketball4
Interested in learning Unity game development? This course will teach you how to create a simple basketball shooting game. The main goal of this trai...
thx and sorry for disturbing everyone
sorry for you too
I have this problem where if I move my player it jitters. I am using a cinemachine/pixel perfect camera. The sprite is (supposed to be) 32 units with point filter and no compression. I think the problem is because of the camera movement, but I dont know. Can someone help me with this?
hi, i try to make animation systeme but it did'nt work, the parameter don't change i think is the link between the 2 scripts
im having an error popping up saying that the unity first person character controller script cant find my stamina script and i dont know why.
stamina handler - https://gdl.space/edogipijuz.cs
player controller - https://gdl.space/ajejikiwem.cs
You have not serialized FpsController, so you can't assign it in the inspector, and nothing in your code assigns anything to FpsController
fps controller is from this script
and before my animation script was in my FPScontroller script
yes, and you need to tell Animation how to find the FPSController
adding [SerializeField] to the field will make it appear in the inspector
then you can drag a reference in
bump
it might help if you provided FULL information
what do you want
what do you think?
A screen shot of the error
A screenshot of the object involved
The normal stuff
i think this, theres no object
Why crop it so much?
And he wants a screenshot of the object involved too
He always does this, drip feeds information
Guys my light ran out while compiling yesterday, now I get all these errors and I have no idea what any of them mean
Close your project then Delete both the Library and Temp (if it exists) folders
I made rigidbody2d and wrote script for bullet to move, in editor I attached the script to my player, and in the rigidbody2d field I dragged my bullet gameobject. And the bullet wont move, however if I make new script and attach it to the bullet gameobject in editor it works. Does that mean it is not possible to move any other gameobject than the one script is attached to?
what object involved the player controller or the stamina bar ui
Just give everything you can. Don't make us drag stuff out of you. Don't crop it too
sir yes sir
stamina handler - https://gdl.space/edogipijuz.cs
player controller - https://gdl.space/ajejikiwem.cs
from your code both scripts should be on the same object.
Also any other errors in the console?
Selecting three things together means the inspector shows nothing useful....
Stamina Controller is in a different namespace
how to fix the "Can't add script component 'BasicEnemyDone' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match."?
okay so how do i put it into the same one? via namespace blahblah at the top of stamina script?
hey do you wanna create a fps character?
ive got one mate im fixing it
ah
alr
how to fix the "Can't add script component 'BasicEnemyDone' because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match."?
am i not putting the stamina script into the same namespace with using UnityStandardAssets.Characters.FirstPerson;
no
how would i go about doing that
Do you have compile errors? Does the class name match the file name?
yes
that's the issue
Which one of the two?
does the folder where the character controller is have an asmdef?
the class name match the file etc
what is asmdef
Etc?
Then rename the class ?
What is the issue?
Then do it
i did
but still doesnt work
ok it doesnt, so you can just put your Stamina Controller into the same namespace as the char controller
is there a solution??
cheers 👍
Give us info to actually help with...
Show the file, show the class, show the console
i will record
My 2d character shoots shurikens, is it possible to make them roll (rotate ) forward through script or would it be better to make animation?
ah okay
Did you take the previous advice on taking some C# learning? The basics will really help you if you take the Pathways over at Unity Learn !learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
i diiiid
This is none of the things I asked for
Show the class, the file, and the console
Inside the script you would have written
public class Something
(or it was generated automatically)
Yes
oh ye ik that
Which pathways did you complete?
So you have compile errors. Did you not read the error message?
You said you did the learn pathways as suggested here
#💻┃code-beginner message
class
Show the file I guess. Is it called BasicEnemyDone?
basicenemydone or BasicEnemyDone ?
2nd option
And what does this say?
So then the issue is that you are referring to BasicEnemy in other scripts
ahhhhhhh
can a drag & shoot tutorial work with this ?
Why not 🤷♂️
There are tons of tutorials. You can change things. C# is turing complete and you can do literally anything code can do
ooooo
thxx
hi, I have a script for animator but the parameter don't work with the spacebar
when i jump the parameter don't change
You have one parameter for everything and just set an int value?
Very interesting, never seen that
It wont you set the int to 30 and then immediately back to 0
Honestly mate, I highly recommend you starting with the Unity Essentials Pathway over at https://learn.unity.com/, you will learn the basics and start creating things straight away, and it will be much more fun. Right now you are spending most your time troubleshooting.
he don't go to 30
i did i am still learning from it
i just find difficulty understanding a bit so i come here 😄
Like the whole Library folder? I don't think I have anything called Temp
When you jump, you are no longer grounded
Sure this doesn't break anything?
Yes. And no it will not break anything
Yeah that's fair enough, like I don't want to sound like I'm discouraging you from doing your own thing and seeking help on here, that's what this community appears to be for.
I'm just talking from first hand experience as I'm currently going through the Pathways, having finished the Unity Essentials last week and moving onto Junior Programmer. Anyway good luck on your tutorials.
thanks and god bless you and dont worry your arent discouraging me i have enough courage to make the game and to ask here about problems and difficulties i have experienced !
hello, is there a way i could the script run only if the requirements are met ? instead of throwing an error it stops the script ?
for example if i try to reference a box collider in a sphere instead of throwing an error the script wont work, is that possible ?
i think it would work if the item iskinematic wich means works only with script
i personally i aint a proffessional at this kind of thing as i am a learner
but still i wanna find a way to get useful for this community
C# has an is keyword you can use I guess? or you can check it for null, I'd need more context
please don't until you know what you are talking about
okay sorry 😦
Hello! I want my game to finish once the rigidBody2D speed is = 0. how can i do it?
private void FixelUpdate()
{
rb2d.velocity = new Vector2(4f, rb2d.velocity.y * dashingPower);
speed = rb2d.velocity.magnitude;
if (speed == 0)
{
Debug.Log("El juego termino");
}
}`
for now i just need the initial step to do it so im experimenting with things that were problems ive ran into before or other i think i would benefit from in the future
oh, you mean if the box collider fails to be found?
that would just be null I believe
yes
if (boxcol == null) <disable script here>
thank you kind beast
does the log appear when the speed is 0?
No ;(
what method runs this code?
also, you should check if it's 0 or less, or use Mathf.Approximately . . .
you mean the RigidBody2D?
what method is this code inside of?
place a log inside of the method that runs the code you use to check the speed (to make sure it's running) . . .
i don't know how to check it 🥺
do you know what a method is?
void
void is a return type . . .
No
👺
you've been coding so far, where do you place your code within the c# script?
Oh, I used this one on the player
is that what you asked?
sorry, i'm just so bad with coding xd
no, but this is basic c# you need to know, especially to receive help properly . . .
it's hard to suggest fixes or solutions if you don't know how to use them . . .
😔
watch a quick tutorial on the basics, or at least methods in c# . . .. . .
it literally told me that public and private void where methods ;(
you need to place a debug log in the same method where you check the speed to ensure that the method is running . . .
public and private are accessors, and again, void is a return type. i don't think that's what they actually said. if so, i'd be worried. do you have the link?
In the interest of time, can I assume you meant FixedUpdate(), instead of FixelUpdate()?
Oh, true, didn't notice it!
It's in russian, so i'm not sure you will understand it 👀
They know c# though
i see, at least you received your answer. hopefully, it works out . . .
Thank you!
Unfortunately it's a bit confusing to understand it, since it's my first time participating in a game jam as a dev
You could have also have stuck a debug.log(speed) right before your if statement to see if it was picking up that variable, which I think is what RandomUnityInvader(); was suggesting. The result would have been that that too would not have been printing to the console and given you a better idea to troubleshooting.
Good luck for your game jam.
Hello, I'm trying to apply the player settings to change the resolution of my build, but it's not changing the resolution. Does anyone know the fix?
Ususally I force the resolution in my scripts
Maybe I am freaking dumb, but why is this reference not destroying the stuff?
Like the last one does work
Oh, wait this IS the refernce sry
how to stop my player from sticking to walls
Make the walls have no friction
yes but then I slide off when i climb on it
You are probably trying to move INTO the wall every frame. Really need to see the code to answer
what code exactly?
it happens if I jump and hold right arrow
I want it to just slide along the wall
The movement code of course
we need to see your movement code. hard to suggest how to move/slide along a wall if we don't know how you move the character . . .
ok I thougt u need the collider code too...
public bool isGrounded()
{
if (Physics2D.BoxCast(transform.position, boxSize, 0, -transform.up, castDistance, GroundLayer))
{
return true;
}
else
{
return false;
}
}
public void kretnja()
{
if (Input.GetKey(KeyCode.RightArrow) == true)
{
igrac.velocity = new Vector2(speed * 1, igrac.velocity.y);
}
if (Input.GetKey(KeyCode.LeftArrow) == true)
{
igrac.velocity = new Vector2(-speed * 1, igrac.velocity.y);
}
if (Input.GetKeyDown(KeyCode.UpArrow) == true && isGrounded())
{
igrac.velocity = new Vector2(0, JumpStrength);
}
!code
Posting 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.
And you have collider code?
yep
ofcourse I have collider code for that
it wouldnt stick to wall if I didnt
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Enemy")
Destroy(gameObject);
}
the code for collider
Just show ALL the code using a link 
Like, obviously if something that has to do with sticking to the wall it is relevant to your issue of sticking to the wall
ok I will send all my scripts cuz idk what exactly you need
https://paste.ofcode.org/36kwZbhrWGWqDbJirQhv2vT ,,, https://paste.ofcode.org/36kwZbhrWGWqDbJirQhv2vT all my scripts related to movement and collider
r u trynna make a movement system 3d or fixing?
ah so i cant help you in 2d i can help in 3d movement system
is it a top down camera
A very newbie doubt. if i have a 3d game, and I want to show a "cell" where 3d spheres can be placed on a plane. Will this "cell" be 3d or 2d gameobject
well say that
yes
not cell . a round circle looking thing. for ui indication
You are setting constant velicity into the wall. Raycast and check if you CAN move that way, if you can't, don't
Hey guys. Which language code is the best for unity?
c#
c#
C# is the only language you use with unity
ok, thanks guys
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
hey use !learn to get courses if u wanna learn scripting
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
hi i have a little problem, i have a script for some animation and i have a conflict between jump and fall animation
when i jump the parameter direct switch on fall animation so the jump animation don't work
the jump animation don't have the time to be execute
More of a #🏃┃animation question. I still think it's what Steve said though
okay
hey i have a problem in unity bolt visual scripting
i wanna know if the cloth can be put only by itself or does it need a shape to form
how do i do this
i wanna know if the cloth can be put only by itself or does it need a shape to form
hey friends. i've input a system.action into one of my scripts for the first time today. its being invoked when an enemy takes damage. then another script is "listening" to this, in this script https://hastebin.com/share/hewezaguwi.csharp the thing is, when i dont have the justHit bool anywhere in the script, it seems like "enemyHealth.damageTaken += DamageTaken;" gets called about 250/300 times in the space of a second or a frame? i get a huge lag spike. I was under the impression it would have only been called once? [i've added the justHit bool into the script to prevent this from happening but i'm assuming i'm doing something wrong here if the invoke is being called in the other script so much].
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
I think you have already been directed to #763499475641172029 channel no?
that is cloth not visual scripting
Oh, it was misleading since you said:
hey i have a problem in unity bolt visual scripting
Are you using bolt for the cloth?
no
i aint using bolt for cloth
i am making it normally
So is code involved in this at all?
no
This is a code channel
thank
ahhhhh sorry sorry
np
https://docs.unity3d.com/ScriptReference/MonoBehaviour.Invoke.html Looks like it is expecting a methodname in a string format.
Is your method really TakeDamages(25) or are you attempting to pass through an argument of 25? In which case that is probably why its throwing an error.
TakeDamages(Amount) is the function i want to call
So at the bottom of that link, it says "If you need to pass parameters to your method, consider using Coroutine instead."
k thank you
The body of 'Health.OnTriggerStay2D(Collider2D)' cannot be an iterator block because 'void' is not an iterator interface type
i really dont get the problem here
oh i guess i need an ienumerator :(((
best to post the actual error message for us to see and the relevant !code . . .
Posting 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.
private void OnTriggerStay2D(Collider2D other)
{
if(other.tag == "Enemy")
{
TakeDamages(25);
}
}
this is what it normaly does
it instantly kills my player
i dont want to make it on enter
i want it so every 2 seconds it takes damage
Use a coroutine that cancel when they leave
yield return new WaitForSeconds(2.0)
Coroutine routine = StartCoroutine(TakeDamage(25))
StopCoroutine(routine)
Also cache it so you can do that 👆
OnTriggerStay runs 50 times a second by default
ya its still giving me them red lines
Not a helpful answer
What red lines
What do the errors say?
What did you write?
i need an ienmuerator right
An equals sign is required there, and both lines would need semicolons
These errors are just basic syntax errors
And you probably don't want to IMMEDIATELY stop the coroutine
And you are calling TakeDamage and then starting a coroutine called TakeDamage
And I hope you aren't still doing it in OnTriggerStay...
Lastly, yes, coroutines return IEnumerator
You didn't address the issues I said
wait should takedamage(25) be before or after the yield
It is in OnTriggerStay, that is wrong
You are calling TakeDamage directly, that is wrong
ohhh
You are calling StopCoroutine on the line after, that is wrong
Your wait does nothing because TakeDamage isn't a loop, that is wrong
what should i replace ontriggerstay2d with
OnTriggerEnter
i still want it to detect triggers
And StopCoroutine goes in OnTriggerExit
OnTriggerEnter2D <
Yes, sorry
Hey, so I'm trying to make a script between the player and a mob that has a 50/50 chance of destroying either of them, but for some reason it's been doing nothing but destroying mobs; am I missing something in my logic here?
wait why
your random range is a float
You enter the trigger, it damages you every two seconds until you exit the trigger
Is that not what you want?
yea
50/50 chance would be:
if (Random.value > 0.5f)```
Extremely unlikely to be exactly 0 ever
this has a chance to generate ANY number between 0 and 1. Including any obscure decimal. So you have an infinitely small chance of it being equal to zero
I see
so all I'd need is this, correct?
I am never using gpt for this kinda stuff again lol
it works
hell yeah appreciate it, no idea why I didn't realize it was saving their exact values being floating-point numbers lol
chat gpt is a useful tool to give you like an idea for coding, but you shouldnt use it to code. it makes sloppy art, and it also makes sloppy code
You could use Debug.Log(randomNumber) right after declaration to identify the value.
^, generally debug.log is good for debugging
i really am confused
i have never worked with coroutines
yield return is inducing a 2 second delay until TakeDamages() is called again
25 damage
wait 2 seconds
...
basically
ya thats what i want
Inside the coroutine, you make a while loop. Inside the loop you do whatever TakeDamage did, and then yield return
In OnTriggerEnter2D you do StartCoroutine
In OnTriggerExit2D you stop it
That is it
i cant use on triggerstay
You could but then you'd need to do more work
Really no point in using stay
so this is how it should look right
Closer.
You can't do stopcoroutine line that
And you should validate that it is enemy you are leaving the coroutine of
OnTriggerStay actually could make this pretty simple:
float timer = 0;
float damageInterval = 2;
void OnTriggerEnter2D(Collider2D other) {
timer = 0;
DamageThePlayer(); // if you want instant damage
}
void OnTriggerStay2D(Collider2D other) {
timer += Time.fixedDeltaTime;
if (timer >= damageInterval) {
timer -= damageInterval;
DamageThePlayer();
}
}```
So.. to sum it up, my boyfriend is working on creating a 3D racing game in Unity and its going good so far but... we've run into a problem... we can't find the right script for adding a nitrous boost to the car itself (example Need for Speed Heat)... i was hoping someone here could help?
The car does move, and we'd need the script written in C#, with a separate script for the sound and key binding for the booster. (Left shift if anything) Is this the right place to come to?
Someone previously provided a 2D script but we need a 3D script
Yeah, I was about to say, this was just all based on the coroutine suggestion earlier. There are many ways to do this. Maybe just do what praetor is saying
maybe getting it transcribed or transferred to be correct..?
hmm ok i will try this
Don't copy paste. Those need to be the 2D variants of the methods
Who knows how to get players to shoot straight. In the 2D version of Android using buttons?
I'm having trouble here, even searching using YT, I can't find only tutorials for PC, not Android mobile
hi, i have make animation and now when i jump we see the knee of my character, can i do something to make my camera follow like the head of my character ??
How to make the button shoot and code ? I have a problem here because there is no tutorial
Complete newbie here.. me and @tired pilot dont know how to write scripts.. much less adding a C# nitrous script. we dont have one started.
there are beginner c# courses pinned in this channel. after learning the basics of c# i recommend going through the pathways on the unity !learn site to learn how to use the engine
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
!collab 👇
📢 Collaborating and Job Posting
We do not accept job or collab posts on discord.
Please use the forums:
• Commercial Job Seeking
• Commercial Job Offering
• Non Commercial Collaboration
I have tried multiple times, installing everything, cleaning up everything, including java, android n unity . but I am not able to build a plain simple mobile 2d and mobile 3d templates. If i build other regualr ones, they work. Error is
Probably the SDK is read-only
Exception while marshalling C:\Program Files\Unity\Hub\Editor\2022.3.22f1\Editor\Data\PlaybackEngines\AndroidPlayer\SDK\platform-tools\package.xml. Probably the SDK is read-only
I googled, no answer seem to fit why a simple blank template woul dnot builf
wow thanks for the help...I'm leaving...
@mental flower What did you expect? What can we do for you?
We can't just teach you from the ground up how to program 🤷♂️
Edit: ah, you're both gone.
Super weird.
dont know if this is the right thread but im trying to figure out how to disable my scoring system after my player has died, any help is appreciated!
how do i post my code here? just copy and paste?
!code
Posting 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.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class scorescript : MonoBehaviour
{
public int playerScore;
public Text scoreText;
public GameObject gameOverScreen;
[ContextMenu("Increase Score")]
public void addScore(int ScoreToAdd)
{
playerScore = playerScore + ScoreToAdd;
scoreText.text = playerScore.ToString();
}
public void restartGame()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().name);
}
public void gameOver()
{
gameOverScreen.SetActive(true);
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pipetrigger : MonoBehaviour
{
public scorescript logic;
public logoscript countercomms;
// Start is called before the first frame update
void Start()
{
logic = GameObject.FindGameObjectWithTag("Logic").GetComponent<scorescript>();
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (countercomms.birdisAlive is false)
{
logic.addScore(0);
}
else if (collision.gameObject.layer == 3)
{
logic.addScore(1);
}
}
}
the first prompt in ontriggerenter2d seems to work to stop the scoring but then it just doesnt score at all
please let me know if you need anymore info and ill try my best to supply it
Adding zero score isn't going to change the score
any number plus 0 is the same number you started with
How could I multiply a float every frame and have it framerate independent, I assumed float *= 36 * Time.deltaTime would work but it doesn't
What you have there will work if it runs every frame
but like
why multiply every frame?
That's crazy
don't you want to add?
What ar eyou trying to accomplish
Multiply velocity from 3 to 0, multiply by 0.6
what?
Can you explain what you are trying to accomplish in gameplay terms?
doing a percentage per frame isn't really sensical
how can I check in 2D if an object is near an other object, so not if it collides but it has basically an offset to the collider
So I have a Vector3 that controls velocity, when nothing is pressed, it should go to 0, if I set it to 0 instantly, it feels a little stiff
- Check the distance
or - Use a Trigger Collider
So I want to smooth the stopping
I think I'll check the distance, I don't want the object to be trigger
Vector3 currentVelocity;
Vector3 targetVelocity;
public float acceleration = 5;
void Update() {
currentVelocity = Vector3.MoveTowards(currentVelocity, targetVelocity, acceleration * Time.deltaTime);
}```
then you just set targetVelocity elsewhere
yea but i just need it to stop counting when im dead, say if i gain a point every second for being alive and then it stops counting when im dead. any idea how i could write that? am I on the right path or do i have to redo it all?
Adding 0 doesn't mean "stop counting"
it means "add 0"
You could do this at the beginning of the function:
if (!countercomms.birdisAlive) {
return; // to exit the function
}```
Or just disable the trigger collider
or you could add bird being alive as a condition to the other one:
if (collision.gameObject.layer == 3 && countercomms.birdisAlive ) {
logic.addScore(1);
}```
That's more so for following right? I'm using a character controller
this has nothing to do with following anything
this is modifying the velocity over time according to your desired velocity
I'm using a character controller to move
not relevant
Would they conflict?
Oh