#💻┃code-beginner
1 messages · Page 311 of 1
did you tick is trigger?
on the box collider component
send a screenshot with the components expanded so we can see if the issue is there 🙂
if it wasnn't ticked before that's good
it isn't meant to be ticked
down to hop on a vc so you can screenshare it to me?
untick "is trigger"
untick?
that disables "physical collisions" i guess you could call them
aight
is trigger is basically to let objects pass through, but so you can still access the collision
it would be used for something like checkpoints etc
also great tutorial, thats the exact one i started with
remember to untick it for both the upper and lower pipes, as well as the player
youll have to do that to the actual prefabs down in your assets folder
so that all the pipes you spawn in have the same settings applied
by the way
I just realized, they all got box collider 2D
this is a nested pipe
which has a pipes
inside of pipes there's two more nested objects called
upper and lower
yup
inside of each of these there's an actual collider 2D as an object in the hierachy
both collider and upper/lower have colliders
those are the ones you need to untick it for
oh
as in
upper and lower have colliders
but then they also have child objects that also have colliders?
Yep, i know, Im changing everything inside the prefab rn
dont worry about that
yep
exactly
you can get rid of those child objects pretty sure
okay
do you know the timestamp for when in the tutorial you make the nested pipes?
I want to double check what he was doing with that
there is no tutorial
My source is that I made it the fuck up
https://youtu.be/uKeKuaJ4nlw (referece for that joke)
Still better then Obama (kunduz hospital)
https://www.youtube.com/watch?v=TgmTsa3rFU0&t=878s
OG Vid
oh so whats the nested pipe supposed to be?
dont worry i understood the maxor reference
I unticked the ticks
what was the nested pipes prefab meant to be for?
uhm... I wanted to move around the rigidbody 2D thingies and I couldn't if it was on the same Gameobject layer because moving one of these components would move the entire thing along with it and i couldnt adjust it properly
but now its ggwp
im not sure i follow
either way, send a screenshot of the inspector for the player and the pipes
erm.. i couldnt move around the rigidbody 2d bro
and make sure the collider values are visible
moving it around would move the pipes too
and i wanted to readjust the size etc, you know
oh there is another way to do that
see that button there
next to "Edit collider"
Ohhh
yeah
and also if you were to resize the object the collider is on, it would also change the size of the collider
so its just a matter of making sure the collider fits on the object and you dont really need to fiddle with it anymore
thats amazing
thanks for the heads up
but yeah send the player and pipes inspector screenshots
im assuming the issue might be an "is trigger" tick on the player collider?
but cant know without seeing
are these the values youre looking for?
what exactly are you looking at here?
I even added a sphere collider on top of the player
and turned on all the is Trigger
also, still nothing happens, no collissions
you're meant to turn off the is Trigger
"A trigger doesn't register a collision with an incoming Rigidbody. Instead, it sends OnTriggerEnter, OnTriggerExit and OnTriggerStay message when a rigidbody enters or exits the trigger volume."
also sorry for late reply, I had to go do something quickly @whole idol
its best to put the collider on the player game object btw, rather than on a separate one
Or at least make the collider a child of the rigidbody.
But in your case it's enough to just put it on the same go as player
I cant
I already have a rigidbody 2d on the player
and for some reason Unity's boundary is that you can either have one or the other
no
i see the issue now actually
you used a sphere collider
which is for ball shaped objects
as in
3D
you need to use a circle collider 2D
and it will work when putting it on the player with the rigidbody 2D
And you don't need one, because it wouldn't work
and I don't have one
Add a CircleCollider2D onto the player object
oh
it's amazign that i can actually add that
along with rigidbody 2d
i was so confused at one point
thinking i can either have one or the other with when it comes to these physics components
anyway... ill try unticking the IsTrickers again
You said they gotta be turned off right?
It doesn't really need to be turned off
A trigger collider can still 'collide' with another trigger collider
And you'd usually use triggers to, well, trigger something, think of it as of a detection range
amazing
So I'm rather new to Unity, and I'm doing a small project with friends. One thing I'm trying to do is to make an object appear and disappear within a 5 second timeframe, let's say a rectangle
How would I be able to make it work? I've tried to use Coroutine but I'm fairly sure I might've placed it on the wrong location, since said rectangle disappears and never comes back lol
Show the code
if you are disabling the script that runs a coroutine, the coroutine is killed
It's either the script or you're deactivating a gameObject where that component resides on, thus disabling the component itself and killing the coroutine as cache said
I was gonna send the script but it's most likely that
Would making a parent empty object and tossing the script there work?
Sure, if you reference the child from there
you can also only disable the target component, like sprite renderer
I'll give it a shot once my Unity stops entering game state-
Nevermind it crashed
So just to make sure I'm not doing anything wrong, this was the script I was going to use
I just want said rectangle to constantly activate and deactivate, wherever the player is
Assets\scripts\GameOver.cs(7,29): error CS0236: A field initializer cannot reference the non-static field, method, or property 'Component.GetComponent<Camera>()'
can someone explain this error? 
looks ok, you can cache yield instruction
private WaitForSecondsRealtime wait5 = new...;
...
yield return wait5;
Well, it's exactly what it says
thats a non-static field?
So I set that private where again...? Just in the public class, wherever?
Fields initializers cannot reference non-static stuff
Do it in Awake or Start instead
as a class member
Remove the Component. part in your code, or whatever prefixes GetComponent in your case
like other fields in class
ill just do this instead then
public Camera mainCamera;
and drag the camera in from the inspector
like a boss

Ah, I think I see
it just saves you an allocation on each yield, its a small thing but a good habbit imo
If only Unity would have just used structs, then it would not have been required
Fair enough
I'm not quite used to it yet since the whole recent start and all
To explain, WaitForSeconds is a class, when you new it, you create a new instance of that class, an object
that object is allocated (a segment of ram now stores it) on the heap (long term ram storage in .net), which means that when it is no longer used anywhere (no references to it) it will be collected by garbage collector to free that ram, and the more stuff garbage collector has to analyze (it walks all the objects and counts the references to them to see if the object can be collected) the more time it takes to complete a single gc pass over memory
hence the more objects you reuse instead of spamming allocations the less is the probability of you encountering micro stutters due to GC taking too long
you are very far from it causing issues for you, so just note it for the future
I see
Oh, btw, if I want to make a detection of the player on top of the rectangle when it's active, how would I be able to do that?
please respect the garbage collector and cache that WaitForSecondsRealtime(5f);
Dope
Already cache'd
show pls
if I may make one suggestion.
You have programmed an infinite loop. Add a
if (Vapor==null) break;
into it so you have a way out of it
Oh thanks
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameOver : MonoBehaviour
{
//public float lowerBoundsY = -5.98f; // position.y
public BoxCollider2D mycollider;
private bool isCurrentlyTrigger;
public GameObject player;
// we want this script to restart the game everytime somethign happens, also we want to define what a defeat is, and there has to be many
//types of defeat, like falling back, falling down etc. and then we wanna restart the player from where he was.
void Start()
{
bool isCurrentlyTrigger = mycollider.isTrigger;
}
// Update is called once per frame
void Update()
{
if (isCurrentlyTrigger == true)
{
Debug.Log("player touched the lava");
//here we could use some animation or something
//player dies
Destroy(player);
}
}
}
why does this never Debug?
this
bool isCurrentlyTrigger = mycollider.isTrigger;
is a local variable not the class variable
ok I added it inside Update and now its printing
not the solution. just remove the 'bool' from the line I showed
Id recommend a starting course
@whole idol btw your ide should have flagged that that statement in Start is pointless
it didnt?
weird
btw
right now it always Logging that the player is flying
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameOver : MonoBehaviour
{
//public float lowerBoundsY = -5.98f; // position.y
public BoxCollider2D mycollider;
private bool isCurrentlyTrigger;
public GameObject player;
// we want this script to restart the game everytime somethign happens, also we want to define what a defeat is, and there has to be many
//types of defeat, like falling back, falling down etc. and then we wanna restart the player from where he was.
void Start()
{
isCurrentlyTrigger = mycollider.isTrigger;
isCurrentlyTrigger = false;
}
// Update is called once per frame
void check_Death()
{
if (isCurrentlyTrigger == true)
{
Debug.Log("player touched the lava");
//here we could use some animation or something
//player dies
Destroy(player);
}
else if (isCurrentlyTrigger == false)
{
Debug.Log("Player is flying in the air like normal");
}
}
void Update()
{
check_Death();
}
}
oops
I see what I did
isCurrentlyTrigger = mycollider.isTrigger;
isCurrentlyTrigger = false;
Ok I removed the isCurrentlyTrigger = false
but if I do that
you need to fix the first error
my player will be destroyed from the first frame
what error?
game is being compiled and played
oh wait
THAT error
this one
yeah
ok so problem persists
I Cleared the error
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameOver : MonoBehaviour
{
//public float lowerBoundsY = -5.98f; // position.y
public BoxCollider2D mycollider;
private bool isCurrentlyTrigger;
public GameObject player;
// we want this script to restart the game everytime somethign happens, also we want to define what a defeat is, and there has to be many
//types of defeat, like falling back, falling down etc. and then we wanna restart the player from where he was.
void Start()
{
isCurrentlyTrigger = mycollider.isTrigger;
}
// Update is called once per frame
void check_Death()
{
if (isCurrentlyTrigger == true)
{
Debug.Log("player touched the lava");
//here we could use some animation or something
//player dies
Destroy(player);
}
else if (isCurrentlyTrigger == false)
{
Debug.Log("Player is flying in the air like normal");
}
}
void Update()
{
check_Death();
}
}
there is no unassigned variable however I think I know what the problem is
BoxCollider2D is not a GameObject
its not referencing to a gameobject
isCurrentlyTrigger is only be assigned in start
and it is value type, the value got copyed
its referencing to the boxcollider2d of a gameobject
and there is no way to drag that from the inspector
or is there?
oh wait I think I can make a unity layout
somehow
so that i can have 2 different inspectors open at the same time
lol
how else am I gonna point to that boxcollider2d of that object
specifically
the IsTrigger
istrigger of boxcollider2d of lava gameobject
show the inspector of the gameobject with the gameover script on it
that is correct
of course it is, the value of isTrigger does not change
yes,
if (isCurrentlyTrigger == true)
{
Debug.Log("player touched the lava");

why does my firepoint not rotating
private void Attack()
{
anim.SetTrigger("attack");
if (transform.localScale.x > 0)
firePoint.rotation = Quaternion.Euler(0, 0, -90);
else
firePoint.rotation = Quaternion.Euler(0, 0, 90);
fireballs[0].transform.position = firePoint.position;
fireballs[0].GetComponent<Projectile>().SetDirection(transform.localScale.x);
}
}```
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameOver : MonoBehaviour
{
//public float lowerBoundsY = -5.98f; // position.y
public BoxCollider2D mycollider;
private bool isCurrentlyTrigger;
public GameObject player;
// we want this script to restart the game everytime somethign happens, also we want to define what a defeat is, and there has to be many
//types of defeat, like falling back, falling down etc. and then we wanna restart the player from where he was.
void Start()
{
isCurrentlyTrigger = mycollider.isTrigger;
}
// Update is called once per frame
void check_Death()
{
if (isCurrentlyTrigger == false)
{
Debug.Log("player touched the lava");
//here we could use some animation or something
//player dies
Destroy(player);
}
else if (isCurrentlyTrigger == true)
{
Debug.Log("Player is flying in the air like normal");
}
}
void Update()
{
check_Death();
}
}
you mean that i should reverse this?
well
this is supposed to be true
only when the player is touching
that lava object
correct?
Not correct at all, you do not seem to understand how collisions/triggers work
when does it get turned on then?
Your code only assigns that variable once, in Start
It will not change again after that
Also it's just checking if your collider is a trigger collider. It's not doing anything with regard to actual collision or trigger detection
The isTrigger property in Unity's colliders allows objects to pass through each other while still detecting collisions. When a collider set as a trigger interacts with another collider, Unity fires specific events (like OnTriggerEnter, OnTriggerStay, and OnTriggerExit). You can handle these events in your scripts to perform actions when the trigger collision occurs. For instance, in the OnTriggerEnter method, you can write code to respond when an object enters the trigger, such as opening a door or triggering a cutscene.
It gets turned on when you turn it on only.
if you are trying to check if the Player is interacting with the lava then your whole code base makes no sense
Can someone help me out please. I have a structure: Ship Class, Ship Properties SO and ITurnable Interface. My ITurnable Classes will have various parameters, and I want to be able to set these parameters inside SO. Parameters need to dynamically change based on selected ITurnable. How can I implement this? I thought about using OdinInspector with their SerializedScriptableObject.
For example, ITurnable A has turnSpeed, and ITurnable B has turnSpeed and rollSpeed
why does my firepoint not rotating
private void Attack()
{
anim.SetTrigger("attack");
if (transform.localScale.x > 0)
firePoint.rotation = Quaternion.Euler(0, 0, -90);
else
firePoint.rotation = Quaternion.Euler(0, 0, 90);
fireballs[0].transform.position = firePoint.position;
fireballs[0].GetComponent<Projectile>().SetDirection(transform.localScale.x);
}
}```
this is the second time you have posted this code and you still have not added any debugging
Dam
Log what transform.localScale.x is when the code is called
log if the code is even being called
i should see a debug log right?, but i dont see anything
{
anim.SetTrigger("attack");
if (transform.localScale.x > 0)
{
firePoint.rotation = Quaternion.Euler(0, 0, -90);
Debug.Log("working");
}
else
{
firePoint.rotation = Quaternion.Euler(0, 0, 90);
Debug.Log("working");
}```
Then your method is not called
Considering you didn't share anything else but the method, we can't help you
Consider checking how the method is called, and if you actually call it there
ok ty
how do i make a timer so that it is in sync with the fps of the player
i saw somewhere that u have to use time.Deltatime
but idk how it works exactly
deltaTime is very simple. It is the length of time taken to process and render the previous frame.
So...
if you had a timer that did
timer += 1;
then timer would vary depending on the fps of the running game
but if you have
timer += Time.deltaTime;
then you have a timer which is independent of fps
using JetBrains.Annotations;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameOver : MonoBehaviour
{
//public float lowerBoundsY = -5.98f; // position.y
public BoxCollider2D mycollider;
private bool isCurrentlyTrigger;
public GameObject player;
// we want this script to restart the game everytime somethign happens, also we want to define what a defeat is, and there has to be many
//types of defeat, like falling back, falling down etc. and then we wanna restart the player from where he was.
void Start()
{
isCurrentlyTrigger = mycollider.isTrigger;
}
// Update is called once per frame
void check_Death()
{
if (isCurrentlyTrigger == true)
{
Debug.Log("player touched the lava");
//here we could use some animation or something
//player dies
Destroy(player);
}
else if (isCurrentlyTrigger == false)
{
Debug.Log("Player is flying in the air like normal");
}
}
void Update()
{
check_Death();
}
}
yoooooooo, why is this happening?
player is already Destroyed from Frame 1 😭 😭 😭
bruh how
u set your bool to ur collider trigger
and from my guess u would have turned it on
can you not read and follow your own code?
dont complicate it.
just use
void onCollisionEnter2d(other collider){
if(other.gameObject.compareTag("Lava"){
Destroy(gameObject);
}
add a tag called " Lava "
write this code according to the intellisense
i wrote it in discord
and put the script in player..... and try to understand ur code dude
u had a silly problem last time too
add this script to ur player movement script or the script that is in ur player. no need to create a new one
Dear lord, please go follow a tutorial or read the docs to learn how how collisions work. You've already been told that mycollider.isTrigger is not what you want, and besides you only set a value to your boolean once, in Start
.isTrigger tells you whether the referenced collider is a normal collider or a trigger collider (kinda detection range as I said earlier)
well i removed that lol
It has nothing to do with actual collisions taking place
ok do you have any tutorials to recommend?
Do you know what isTrigger does? It doesn't check if the player enters the trigger or anything. It's just the Is Trigger setting that you see in the inspector
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
Ah, seems like caesar explained it
oh okay
!learn
:teacher: Unity Learn ↗
Over 750 hours of free live and on-demand learning content for all levels of experience!
this tutorial is kinda mid honestly, where does it explain Is Trigger for example?
ye, the whole site
i dont get it
anyway, ill try to follow the tag technique
Mrc recommended
Might wanna check this too https://docs.unity3d.com/Manual/CollidersOverview.html
Hey, before asking questions here, I want to ask this: Do you get angry with new people because you are constantly exposed to the same questions?
chatgbt gave me basic isGrounded code but doesnt work 😄
Not really, unless it's the same person asking the same question despite being answered / linked to a solution
alright
If I press the space key and press the space key again while in the air, the jumping animation works again.
Don't use GPT then, especially if you don't know what you're doing
i didnt get answered the first time btw 😭
anyway this tutorial looks good
In this video we will learn how to detect collision 2D in Unity.
OnCollisionEnter2D,
OnCollisionStay2D, And OnCollisionExit2D...
Enjoy the video ☕
————————————————————————————
🖐 Hi Game developer
Welcome to Rehope Games I'm Murat
I share unity tutorial videos on my channel. if you want to make a game with unity (especially 2d platformer...
This is the code chatgbt gave me
That's generally the case if someone didn't learn the C# basics, I never had any issue reading them, quite the opposite really.
no no
has someone explained or should i?>
firstly we do not fix AI generated code
secondly !code
📃 Large Code Blocks
Use links to services like:
https://gdl.space/, https://paste.ofcode.org/, https://hatebin.com/, https://paste.myst.rs/, https://hastebin.com/
📃 Inline Code
Surround code with three backquotes. Not quotation marks.
To format as C#, add cs to the first line:
```cs
// Your code here
```
Add a comment with a line number if there is an error message.
i mean why use ai if u have a helpful discord server and its not that hard of a language to work with
no just asking is this code true or wrong i didnt want fix code sorry
so post it correctly and maybe someone will take a look
Can you suggest a way to prevent the jump animation from being used again after the character presses the space bar until he falls to the ground?
use something like
when the player is not touching the ground play the animation once and dont press again until the player is on the ground and jumps again
You did get answered tho: #💻┃code-beginner message
😄
oh okay, ty , I didn't see that message
yes it is but all i watched animation videos they all opening loop box
try disabling loop
i see the problem
when u press space
it jumps and plays the animation correctly
Nothing to do with your animations - your ground check is always returning true..
but ur animation has loop animation enabled
huh?
oh wait i think yeh
!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.
already when i remove loop box jump aniamtion never play just going upward
but it doesnt go to the second stage
as Carwash said
check ur code
use a pen and paper or something and manually write what happens. like a tree or something
i do that a lot and it helps
Dear lord, please learn about arrays 
your timer is in the first if statement, which then stops getting called, so your timer doesn't increase and never reaches >=3
ik ik its a test code.
just trying get the gameplay
ooooo thanks
not quite the word but yeh. to understand what will make it work
need add bool isGrounded = false; ?
are u using raycast or something else
no
oh oops, didnt check the script
same
need to throw in a log and print out isGrounded see if it's still true when jumping or not
i have only 3 script FPSController(from github) PlayerAnimation(from chatgbt) and groundCheck (from chatgbt)
🤙 😄
make ur own script or understand the scripts
wdym by 🤙 😄
😂 i am making my 4th 3d game and i still havent added any animations.
i need to learn it
its so hard bro
If you're an actual student in education, you're doing yourself an injustice by using "AI" and if I (and many others in here) was your tutor , I would fail you for using "AI"
there is no enaughly youtube tutorial videos
but i swear to god, beans and cubes are the best models for every game
xd
walk run is easy but jump animation really really
your googling skill is not enough bro
there are enough yt vids on youtube
yeh lol
i can find everything i want. u will too
Calling a jump animation is no different than calling a walk/ run animation..
when i started i used gpt too but then i realized that its not worth it
yes true but seems so ugly did you watch this ?
What about it?
are u making a whole game or just learning animations?
The only time I do use GPT is when my brain is fried and I'm looking for a good name for my class/method
this what my games looks like while developing. will add animations and stuff after main gameplay features are finished
lol tru
im trying just learn basic animations
oh nvm
Then you should be in #🏃┃animation
finally i fixed the crop growing error 
its me again...
i have a function for selecting an item in my inventory, and I have a crafting system where user select 2 items in the inventory and it will show up on the craftingUI, but I want the user to only choose 2 items max, so I implemented an int of selected. When selected <= 2, then I can select and selected += 1, else I shouldnt be able to select. however when I tested it, it was like the photo shown. Below are my codes that I hope is relevant:
public int selected = 0;
public void OnPointerClick(PointerEventData eventData) {
if (eventData.button == PointerEventData.InputButton.Left) {
OnLeftClick();
}
if (eventData.button == PointerEventData.InputButton.Right) {
OnRightClick();
}
}
public void OnLeftClick() {
if (selected <= 2) {
selected += 1;
Debug.Log("It has " + selected + " selected.");
selectSlot();
}
}
Not trynna be this guy again, but there is something really weird happening in my code which I dont undestand
just go ahead
how the fuck am i instantiating new clone pipes if no Instantiate() us attached anywhere in any script in my gameobjects?
ur code is simple so i alone can help
lets look at deez prefabs
are u sure that there isnt any Instantiate() anywhere
show script
not panel
ok
now lets look at the script that some of these have
only script they got is a plain MoveLeft script
thats it
show me the script that works with the pipe
1 sex
I mean 1 second
sec
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LeftMove : MonoBehaviour
{
// Start is called before the first frame update
public int speed;
void Start()
{
}
// Update is called once per frame
void Update()
{
transform.Translate(Vector2.left* Time.deltaTime * speed);
}
}
it used to happen to me tooo
thats the only script?
yep
how the fuck does this happen?
did you save the script?
finally its fixed
then there is another script
yeh
where?
Depending how simple your hierarchy is just check every single GO and child for other scripts
which I was experimenting with
im not even sure
I should had probably deleted some of them
I assume there is a PipeGenerator somewhere on a gameobject
Alternatively search the hierarchy for the names of these scripts
just recheck cloner and pip generator \
Search the Hierarchy for "Cloner" and "PipeGenerator"
i mean it could be in any of those scripts but just going off of the names thats where I would assume it is
oh okay I found it
lol
It was emptyAbyss just playing hide and seek
welp good luck with ur game
is there any way to use an int64
dude
u are not me
ur game is still simple
;-;
what is that?
its easy to manage
Things are always only exactly where you put them
true
i got like 10 scripts and total of 2k-2.5k lines of code
what?
he is new
I have a charactercreation thats almost 1.5 k
But its multiplayer/ networked so that adds alot
I am in the middle of refactoring my whole game though so I am sure it will become less xD
When I wrote most of the code I was so much worse at programming than now
Unless if a annoying little ghost always sneaks into my pc when im not looking and shuffles my scripts around the unity hierarchy to make my life easier
i wanted to make my multiplayer too, but then it was too complicated for my game and too much to recode everything so that everything is synced
thats unreal engine spy
Yeah if you are already in the middle of a game there is no point in adding MP in most cases
Adding it from the start is so much better
can i disable any static variable to get changed again by a script
Took me a few weeks to get steam integration and public/ friend lobby finder to work

like disable bool X to be edited when bool Y is true
readonly
ahh
yeh thats why i changed my mind
Do a setter
So you want a variable that you can only change when some bool is true?
basically this script checks if the player presses E near a plant box and then start the plant growing process
oh wait i got it
yeh
But it wouldnt change anything right?
add a bool at the start of the script that is true
make it so that if(raycast && boolx) then do stuff
when the stuff it does is plant and change boolx to false
so the if cant rerun

🤓
do it the other way around
if(boolx && raycast)
checking the bool is cheaper than the raycast
but then i wanna add other stuff to the same script
i mean its not that heavy rn
but why not
and tried to skoop it back out of the recycling bin
just add it in ur player movement script
just use OnCollisionEnter2d
ok
ok cool, thankfully it didnt take that long to fix this time
yeh its really easy
u can just add "Lava" tag or something like that in objects that will kill player on touch
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class GameOver : MonoBehaviour
{
void OnTriggerEnter2D(Collider2D other) // Use 'other' as the convention
{
if (other.gameObject.CompareTag("Player"))
{
// Handle game over logic (e.g., destroy player, display game over screen)
Destroy(other.gameObject); // Destroy the player on collision
// Add code to display game over UI, reset level, etc.
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
}
}
yeh
no wait
what i fix kinda cringe about this is that whenever these pipes hit you in the face position.z goes perma negative by that amount
You should have one script on the player that checks in OnCollisionEnte
and below that i die
not on all obstacles
replace "player" with "killObject" or something
if i touch the floor
yep
and add the "killObject" to the prefabs of the pipes
oh true
Instead of Having GameOver on each obstacle, have one script on the player that check for collisions with objects with the tag "obstacle" or something
and then ends the game
add a object that moves with ur background
and give the killObject kill tag and keep the object and the ground
that will act like lava
also i suggest u make the pipe height high cuz i can just go really high and then wont be able to die
ok so only flying is safe now
all collisions kill player
noh
except if position.x goes too negative
yeh
wait why would that happen
maybe a limit to how far back it can go
how could that happen
oh wait
the background will keep moving at a speed
its not like u controll the player
now pipes will you
yeh
so it will no longer be happening anyways
nice
when u are done a small prototype upload it to https://itch.io
and add it to #1180170818983051344
mine is almost complete. just some polishing
thats not true
there is also a lava above his head
lol
its not lava, i just call bad things lava
yeh the bad things
😛
my game rn is almost complete
single player, farming, zombie survival, day/night cycle
video?
just a sec
My favourite game is deceit
from steam
ive been playing too much of it and I originally wanted to make one game like that, multiplayer too. survival zombie multiplayer type game
it allowed me to meet so many friends and people all around the world, very voice chat oriented type of game too
I wanna make one game like that one day
my dream is kinda like that too
here is the vid
have you finished any games?
yeh
its not really good
looks clean!
i made it in a game jam
its has reloading too but there is a bug and i am too brain dead to fix that
ik whats causing it just that idk how to fix it
holy.., does it increase in difficulty as time goes on?
so much nostalgia from these types of games
no
i will add it to the currently 3d game i am working on
I loved the old call of duty zombie survival modes
yeh
my current game is kinda like that
and i wont add world building so that i dont have to work on world saving
lol
welp thats " Unity's Particle System "
if u know how to use it, it can cure cancer and world hunger
but i just downloaded a asset from asset store
and edited a bit and made it play whenever my raycast hits an enemy, the particles will Instantiate() at hitpoint at a angle from which it got hit
how much time can it take to make a basic explosion like that ? rather than download an asset from the store?
man i learned raycasts in this project and its a life saver
idk. thats why i just downloaded
raycasts you mean the invisible lazer things?
cuzz i didnt wanted to learn
for your aim?
yis
amazing
yis
not really if u can understand the code
its the unity physics
its like OnCollisionEnter just with raycasts
Hi guys is this the channel I can ask for some code help or should I ask elsewhere?
yes
go on
oh so you literally instantiate() bullets?
no no
how
thats a way and another is using a raycast
it will shoot a raycast straight from the camera
if it hits something, it will check if its tag is "enemy" and it will damage it
it looks like it comes out of your gun
using physical bullets is expensive as in fps and is not really nice looking
no thats just cosmetics
the rifle cosmetics are scuffed but yeh
nice
thats what the player is supposed to feel lol
why?
ohhh i see what you mean
I am having the following issue: "PlayerInput does not contain a definition for actions" I am not sure what else to add to this so please help me if you guys need additional information.
it drags down the performance right?
cuz u create many objects which have to be rendered and calculated
while using high firerate guns, it can be laggy
yeh
how do video games handle bullets then?
i can show u a different way @plush igloo
just a sec, let me help Dest then we talk
@plush igloo if u wanna jump when u press space your code can go like this
```
if(Input.GetKeyDown(KeyCode.Space)){
// code for jumping
}```
here Input is a tool in unity
"GetKeyDown" will detect if a key is press
KeyCode.Space will detect if the key is space and run the jump code
oh I understand that part, I'm using the "new" input system so was trying different ways. I am just baffled why it is throwing me this error. went over the video 5 times to check and all is the same.
i dont really use the input system u are using so i dont have any idea
@whole idol talk in dms, we were talking in code questions lol
repost ur question some else might be able to help
I will repost thanks bud
yeh np
Hi guys! I am having the following issue: "PlayerInput does not contain a definition for actions" I am not sure what else to add to this so please help me if you guys need additional information. Reposted the question per MrcJoc's advice.
This uses the new unity input system
tbh old one is better cuz u can use it from the script
so u dont have to go into different window
Hey all! Say I am inheriting a base class. Do I have to use all of its methods? Or can I just like use the ones I want only.
show code and explain. ......
like the update and start class ?
Not sure if this helps you, i just recently started redoing my inputs in the new input system
But that works for me so far
but whyyy
whats the difference
Controller support
oooooooooooooh
All subclasses will have access to the methods of the base class
But you dont have to use them
No like a custom class that has 4 virtual methods and I only want to override 2 of them. What happens to the remaining two?
You can mark methods on the base class as abstarct, then you enforce each subclass to implement their own override for that method
bruh, i cant understand this words. i can just see a code and can help lol
They will still be accesible by the subclass
But the new class thats overriding will not call them right?
I mean the remaining two thats untouched.
can you send a code example?
hm no I'm not working on anything that just is out of my mind.
Ok let me type it out then
The list of new functionality that the new input system offers is about as long as discord would allow to type a message, starting with controller support, built-in support for multiple players, different click types (hold, double click), mouse delta tracking, conversion of key-combos to a vector2 (WASD, arrow keys) and plenty more
public class A{
public virtual void MethodX(){}
public virtual void MethodY(){}
}
public class B : A{
public override void MethodX(){
base.MethodX();
// extra code
// Method Y can be used here aswell
MethodY();
}
}
Does that answer your question?
Not sure if the syntax is 100% correct
what can i use in a if statement as a " or "
for example: if(1 = 1 && 2 + 2 = 4) {}
||
instead of " and " i wanna use " or "
||
Hm okay so I have to still call the base method when overriding and put anything extra in it
You dont have to
You can
If you want to completely replace you dont do base.MethodX();
but if you want to keep logic of methodX in the baseclass and add new stuff on top then you do that
Just a quick question, is your base class a default implementation or basically an interface how the child classes should look?
makes sense all right. So I got the method x. What happens if i dont override the method y and do not include it in the B class?
not an interface no
Yeah I mean I can call but what if I dont call it?
Same as any method
Just exists then?
You can also mark the methods as abstract to enforce overwriting them if thats something you want
Thats more like an interface then
Yeah I kinda get how it works when its abstract classes. I just get confused when the base method actually does something and I inherit that from another class.
i want the mouse to able to be controlled only on the left side of the screen, i have trouble finding any information about it (most of the information is how to lock it to the center of the screen)
Is there a way to make borders that the mouse can't pass on one side of the screen?
Very shallow explanation: You hide the real mouse (Cursor.visible), put an image in its place and move the image with the mouse delta. Limit the image move through simple math and if the player clicks you simulate a click at the position the image is currently
so the image can't pass the border, sounds good. (it's a game where you need to dodge stuff using the mouse so this might be perfect)
i'll see what i can do.
Oh an i think you need to the set cursor lock state
there is good documentation in the unity docs about that one
CursorLockMode.None: the cursor can move freely inside and outside of the game windowCursorLockMode.Confined: the cursor can move freely just inside of the game window unlessEscapeis pressed. This way the cursor can move outside of the window. Once the game window is selected by being clicked, the cursor is locked.CursorLockMode.Locked: the cursor is fixed in the middle of the window
In your case, you don't want the player to be able to bass the border. This way you'll have to consider setting the cursor to Locked.
Cursor.lockState = CursorLockMode.Confined;
marking a method virtual means you can override it. Marking a method abstract also lets you override it. The difference is that abstract stuff do not have a body. What is the difference then?
abstract FORCES a class that inherits from this base class to implement it
the first declaration of a virtual method is like a default implementation
abstract forces all children to have to override, and define their own thing from scratch
virtual method can be overridden, not necessarily. abstract method must be overridden.
virtual method has a body and can be used by the derived class, but abstract cannot have a body and thus must be overriden.
Ah okay that makes sense.
I think you switched confined and locked here
you should only make a method virtual when you actually want all the children to have a basic version of the method to work with
that they all share in common
What would be a case that I would want to run the base method and add stuff?
Like I cannot find any examples and it does not make sense as it is now
virtual.
No I mean. Like an example where I want to run the base method then add more things to do in that method while overriding.
In the ovveridden method
// Foo.cs
protected virtual void Foo()
{
print("Foo.Foo");
}
// Bar.cs
protected override void Foo()
{
base.Foo();
print("Bar.Foo");
// =>
// Foo.Foo
// Bar.Foo
}
i have public class Singleton<T> : MonoBehaviour
It has
protected virtual void Awake() {
that makes the singleton set up it single instance if it doesn’t exist, destroy if there is a duplicate etc
like I showed you here @final kestrel
then I define singeltons like
CameraController : Singleton<CameraController>
CameraController has its own Awake that it wants to call, but it also NEEDS to do the singleton Awake when it calls awake so the singleton can work
I understand this example yes. Like I am just trying to figure out the "extra stuff" part.
so CameraController will have
protected override void Awake() {
base.Awake();
//Then camera controller stuff
}
You can add code in addition to the code of the base class
So in this example when you call the base it wont print anything
You're right, fixed it. Thanks.
the other inherited one will print
i have many other classes that call base.Whatever, but the singleton is maybe the most generic
The logic will be the same
Yeah no I am not making myself clear enough sorry. Like I get the idea. I am just trying to see the real world example where I would want to add extra stuff.
but yes I see now.
this
Thanks a lot for the answers!!
For example a button, you would want all buttons to do the same logic in some way like lerping/ sound
No, it will print "Foo.Foo".
basically, it’s when you want to like “keep adding more” to whatever method is there, but tie it to the same signature
Oh yeah sry i didnt even look at the base method
Meant that it prints something additionally
Yes, that's so
All right. It makes sense now. I should just practice some to get it right.
Abtract methods are very useful for example for items when you f.e. want to use items. Each type of item will have its own logic for using it:
The base item class then has an abstract "UseItem()" method.
All inheriting classes must then implement their own using logic.
That way you dont have to do stuff like:
ìf (item is Weapon) ...
if (item is Tool) ...
You can just do
item.Use()
For example
since they have no body you can just implement them and do whatever you want inside.
class 1 has public virtual void Initialize(…) { set up parameters in base class}
class 2 : class 1 then has
public override void Initialize(…) {
base.Initialize(…); // sets up parameters and crap in the parent
// Then set up things required for class 2
}
Using the derived class would usually be better
if (item is Weapon weapon)
weapon.Use();
It is just confusing when I override and can optionally call the base method first then add some more stuff.
yeah thats what the ... are for
base.MyFunction calls the function with the given signature in the base class
Was just the example of how not to do it
aa okay
base.MyFunc() looks to invoke MyFunc() of this particular instance, as looking for the definition in the base class.
Oh, I see, you're right. It doesn't make sense to use the variant I've shown if the Use method is in the base class, as calling it from the derived reference will give the same result.
inherittance can be tricky. Interfaces might actually be simpler in a way
can you hold properties in interfaces?
property yes. field no
an interface is like an abstract class with no fields, but you can “inheritt” (actually called implement) as many of them as you want. You can only inherit from one class
public class Tool{
public virtual void UseTool(){
// Logic that is for all tools. F.e.: Reduce Durability
}
}
public class Pickaxe : Tool{
public override void UseTool(){
base.UseTool(); // you want to also reduce the durability here
// Code for only Pickaxe logic. F.e.: break stone
}
}
public class Bucket : Tool{
public override void UseTool(){
// base.UseTool(); // You dont want buckets to loose durability, so you comment this out/ remove it
// Code for only Bucket logic.
}
}
a small example for the base.Method()
This is great example thanks!
so I can have something like:
public interface IDamageable {
public int CurrentHp {get;}
public void DoDamage(int damage);
}
any class implementing IDamageable must have a property called CurrentHp with a public getter that returns an int
I never did properties in Interfaces. Do I have to implement them as well?
That answers my question all right.
It is amazing how you have many ways to do one specific thing. Its intimidating haha
private int HP = 5;
public int CurrentHp => HP;
public void DoDamage(int damage) {
HP -= damage;
}
}```
public int CurrentHp => 1;
public void DoDamage(int damage) {
BreakChair();
}
private void BreakChair() { ….}
}```
oh nice so this how you would do it with interface all right.
interface lets you handle things that have nothing to do with each other. but allows other things to act on/with them through the few parts they are guaranteed to have
I could just remove the property from the interface and hold them as fields in classes themselves and just do the logic on the implemented methods too right?
yes. but then you can’t access it via that object when typed as the interface without downcasting
(and you really don’t want to spam downcasting nonsense)
so you should think hard about what your interface should actually have
ah okay. Thanks a lot for the help!
in this case, IDamageable should NOT have a CurrentHp property, because it doesn’t make sense if I’m forcing that shit onto classes that don’t actually have HP
what is the non character controller equivalent of charactercontroller.move()?
huh, weird question
yeh
your own move function
i was considering just doing transform.position += vector
Translate()
For rigidbodies:
MovePosition()
AddForce()
velocity =
{
if(Input.GetKeyDown(KeyCode.Escape))
{
Debug.Log("woking");
onComputer = false;
freeMove = true;
StartCoroutine(ComputerCamTransition());
}
}```
i dont think unity is reading this properly as instead its just trying to tab me out the window
tab you out of window?
nothing in this code does that 🤷♂️
yeah i know but thats what escape does in unity
only in editor
yeah well im in the editor so how do i test it
test it with another key?
switch it when building
if you unity didn't allowcursor unlock mouse would be stuck forever
true just seems really impratical
yup only for esc button though
can you get a trigger point from on collision enter?
I dunno what trigger point means (collision point?) But this is everything you get from the struct
https://docs.unity3d.com/ScriptReference/Collision.html
Likely what you want is contacts
sorry i meant can you get a trigger point from on trigger enter like you can with a collision point on collider
no because triggers aren't solid collisions
i see
All you get is the collider that the trigger intersected with
You can do some math using bounds I guess
there are workarounds like using
ClosestPoint and a raycast
is on trigger when you are the trigger or when the other thing is a trigger
its either one (rigidbody detects both colliders involved)
yes
or a character controller
why isnt the sphere collidingg with the floor? both have a rigidbody and collider
How are you moving the object
with transform.position
im not using physics
That's teleportation. It won't respect collisions
You have to move the object with physics
no..
A trigger also would not work
and expects physics to work 😄
trigger did work
by approximation but wont be totally accurate
it doesnt need to be totally accurate
i wanna hit this baseball around but rigidbody just doesnt work with it
can i move the rigidbody while its kinematic?
will that respect collisions?
like rb.velocity or something
yea
while its kinematic?
no
Does anyone know why when I start my 2D game the Y transofrm axis just keeps going up infinitely? ive tried looking at diff sollutions none of them are working
kinematics dont have velocity
Why would you need it to be kinematic
because i want to use my own physics that I made
probably a script doing it
not if you don't provide any sort of information for us to go off
Then you'll need to use your own collision detection system that you made
i'll just use trigger then
what speicfic information would be relevant for this? im really new to unity
well, what could be affecting the movement of an object?
I first looked at the movement script and disabled it but its still just going down indefinitely
Like how gravity works
why does it fall through the platform but collides with the out of bounds thing?
because the floor is trigger?
so its not an actual collider
bro i m so stupid
thanks i didnt even see that
how can i move a object back. and forth
ik it sounds really easy but i want to do it locally
like reletive to the objects rotation
Use transorm.forward
It will move relative to rotation
then use
transform.position += transform.forward * new Vector3 (x,y,z);
yea i know that but i want to move it back and forth
so it goes 5 units foward and the goes 5 units back
and it just reapeats that
Yes?
So use transform.forward and -transform.forward
And move it back and forth
but how do i make it know when to go back after i go 5 units foward
flip a bool
but how do u identifly that it has gone foward 5 units
Check position against a set "center"
huh
I just told you two
I'm on my phone, so I'm not gonna write code
Might be easier if you make it a child object btw
could u at least give me like a link something
The parent would represent the center
to some explination
Link to what?
I'm sure you can google
so i would need 2 game objects
like a link to a yt video or a article
No, that was just a third suggestion. The other two do not need that
so how do i do this
Vector3 representing a center position
Check if you are over 5 units in front of it
Or over 5 units behind it
You can subtract one position from another and check the magnitude, or add the distance moved to a float and poll that float
float dist = 5;
...
v3 = -v3;
position += forward * dist;
is this what u mean or did i copt the code wrong
hi guys :D i have a silly question, but how do I link script? my phrasing could be wrong cuz i dont really know how to name this question
basically, I have a locked door, and I have a key in my inventory, how do I tell the script locking the door that I contain a key unlocking the door in my inventory script?
it sounds like you want to learn how to get a reference to another object. you can check this out to see different ways to get a reference: https://unity.huh.how/references
alright thanks :D
so whats wrong
you cannot multiply two Vector3 together using the * operator since that operation is not defined. If you just want to transform a Vector3 to be relative to the object's direction just use transform.TransformDirection which will convert the direction from local space to world space
isnt that what it says in this code tho
position = forward * v3;
and it's wrong for the reason i already stated
ok then how do i fix
my bad, should not be vector3 should be float
ok
so like for the sake of simplcity ill just make it a random number and times it by time. delta time and ill see what happens
I updated the code above
obviously dist = -dist
float test= 2f;
void Update ()
{
test = - test;
transform.position = transform.forward * test;
}
does this work
do += rather than =
ok
also - test looks wrong -test is better
well you are doing this every frame which will mean it is moving so fast you cannot see it
could do
but still this code wont be local
like if the cube is roatetd will it still go foward and back
why, using transform.forward will mean it will move in the direction it is facing
wait i just noticed something in my code for the reason the float test is just 0
ok
and i cant just change it
it stays 0
public float test= 2f;
void Update ()
{
test += -test;
transform.position = transform.forward * test*Time.deltaTime;
}
}
this is the code btw