Help with collisions
Hi,
New to developing in unity and was wondering if anyone can help me with an issue I have, basically i want a bullet to hit an object and delete it (or at least log its colliding)
I have a bullet class thats get created when the Fire method is called and this works fine, it creates a bullet that moves at the correct speed in the correct direction but for some reason the collision detection isnt working
Ive attached the 2 noscripts as well as images of the inspector for the bullet prefab and Square object (the one i want the bullet to collide with)
At the moment the bullet just passes right through the square when i would expect it to at least log a message
They each have colliders and rigid bodies so im not sure why this is happening
public class Bullet : MonoBehaviour
{
public float lifespan = 3f;
void Start()
{
Destroy(gameObject, lifespan);
}
void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log($"Bullet hit: {collision.gameObject.name}");
// Destroy the object the bullet collided with
Destroy(collision.gameObject);
// Destroy the bullet itself
Destroy(gameObject);
}
}
void FireBullet()
{
// Instantiate the bullet at the spawn point
GameObject bullet = Instantiate(bulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation);
// Add velocity to the bullet in the direction the spaceship is facing
Rigidbody2D bulletRb = bullet.GetComponent<Rigidbody2D>();
bulletRb.velocity = bulletSpawnPoint.up * bulletSpeed;
}
https://preview.redd.it/vn2y9odqvu5e1.png?width=392&format=png&auto=webp&s=c98df85970ef52dd66dd1e7912a3fbfd6908885c
https://preview.redd.it/o1hs15qzvu5e1.png?width=385&format=png&auto=webp&s=15d9acbc8de04b8edcb96c5dd56fdbc535557db4
https://redd.it/1haevvs
@r_Unity3D
Hi,
New to developing in unity and was wondering if anyone can help me with an issue I have, basically i want a bullet to hit an object and delete it (or at least log its colliding)
I have a bullet class thats get created when the Fire method is called and this works fine, it creates a bullet that moves at the correct speed in the correct direction but for some reason the collision detection isnt working
Ive attached the 2 noscripts as well as images of the inspector for the bullet prefab and Square object (the one i want the bullet to collide with)
At the moment the bullet just passes right through the square when i would expect it to at least log a message
They each have colliders and rigid bodies so im not sure why this is happening
public class Bullet : MonoBehaviour
{
public float lifespan = 3f;
void Start()
{
Destroy(gameObject, lifespan);
}
void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log($"Bullet hit: {collision.gameObject.name}");
// Destroy the object the bullet collided with
Destroy(collision.gameObject);
// Destroy the bullet itself
Destroy(gameObject);
}
}
void FireBullet()
{
// Instantiate the bullet at the spawn point
GameObject bullet = Instantiate(bulletPrefab, bulletSpawnPoint.position, bulletSpawnPoint.rotation);
// Add velocity to the bullet in the direction the spaceship is facing
Rigidbody2D bulletRb = bullet.GetComponent<Rigidbody2D>();
bulletRb.velocity = bulletSpawnPoint.up * bulletSpeed;
}
https://preview.redd.it/vn2y9odqvu5e1.png?width=392&format=png&auto=webp&s=c98df85970ef52dd66dd1e7912a3fbfd6908885c
https://preview.redd.it/o1hs15qzvu5e1.png?width=385&format=png&auto=webp&s=15d9acbc8de04b8edcb96c5dd56fdbc535557db4
https://redd.it/1haevvs
@r_Unity3D
How to disable a rigid body without disabling the collider
So, I have an object that I would like to merge with another object. both objects have colliders and rigid bodies, and I would like to make one of them become a child of the other to connect them. in order to do that, I would like to disable the rigid body of the first so it can become the child of the other, with the ability to enable it on disconnect. the problem is I want the object to still be able to collide as a part of the second object.
If I simply delete the rigid body, it operates as I want it, with the colliders colliding. kinematic is not what I need, and physics layers did not work. problem is simulated just turns off the collider, so that does not work either.
I have been pondering this for close to a week, and found no answer. chat gpt said to maybe create a save state for a rigid body, but that feels ugly, so I would like to know if there is a built in solution that makes this possible.
https://redd.it/1haif2m
@r_Unity3D
So, I have an object that I would like to merge with another object. both objects have colliders and rigid bodies, and I would like to make one of them become a child of the other to connect them. in order to do that, I would like to disable the rigid body of the first so it can become the child of the other, with the ability to enable it on disconnect. the problem is I want the object to still be able to collide as a part of the second object.
If I simply delete the rigid body, it operates as I want it, with the colliders colliding. kinematic is not what I need, and physics layers did not work. problem is simulated just turns off the collider, so that does not work either.
I have been pondering this for close to a week, and found no answer. chat gpt said to maybe create a save state for a rigid body, but that feels ugly, so I would like to know if there is a built in solution that makes this possible.
https://redd.it/1haif2m
@r_Unity3D
Reddit
From the Unity2D community on Reddit
Explore this post and more from the Unity2D community
Assignment doubt
I got an assignment where it is mentioned that dont use generative ai, we can identify easily. Can anyone know how they can find it or how can i get rid of it.
https://redd.it/1hahohl
@r_Unity3D
I got an assignment where it is mentioned that dont use generative ai, we can identify easily. Can anyone know how they can find it or how can i get rid of it.
https://redd.it/1hahohl
@r_Unity3D
Reddit
From the Unity2D community on Reddit
Explore this post and more from the Unity2D community
does anyone know what could be causing this?
https://youtu.be/6aunX6d5o5s
https://redd.it/1hamyan
@r_Unity3D
https://youtu.be/6aunX6d5o5s
https://redd.it/1hamyan
@r_Unity3D
YouTube
unity 2d platformer jump issue
Help building a shop system c#
I am running into some trouble with my shop system.
I have a shop manager noscript that opens and closes the shop UI.
I have three shop slots gameobjects each with a shopslotnoscript. This noscript is responsible for randomizing an item noscriptable object and filling the UI with that items data.
When the item is purchased from the shopslotnoscript, I want to send the items data to the players storage slot UI.
I’ve been staring at this for two days and the answer seems obvious, but I am looking for a way to send the shop slot random item data to other noscripts.
Because the shop slot and item storage slot will sometimes be inactive in the game they both have separate managers, a shop manager and a storage manager. So essentially, I’m looking to send the shop slot item data to the managers so that the managers can send it to the proper slot if that makes any sense.
I thought about creating a variable to fill with the purchased item data but bc I want the player to be able to buy multiple items I would then need multiple variables?
Any help or pointing in the right direction would be amazing. Thanks in advance.
https://redd.it/1hamrma
@r_Unity3D
I am running into some trouble with my shop system.
I have a shop manager noscript that opens and closes the shop UI.
I have three shop slots gameobjects each with a shopslotnoscript. This noscript is responsible for randomizing an item noscriptable object and filling the UI with that items data.
When the item is purchased from the shopslotnoscript, I want to send the items data to the players storage slot UI.
I’ve been staring at this for two days and the answer seems obvious, but I am looking for a way to send the shop slot random item data to other noscripts.
Because the shop slot and item storage slot will sometimes be inactive in the game they both have separate managers, a shop manager and a storage manager. So essentially, I’m looking to send the shop slot item data to the managers so that the managers can send it to the proper slot if that makes any sense.
I thought about creating a variable to fill with the purchased item data but bc I want the player to be able to buy multiple items I would then need multiple variables?
Any help or pointing in the right direction would be amazing. Thanks in advance.
https://redd.it/1hamrma
@r_Unity3D
Reddit
From the Unity2D community on Reddit
Explore this post and more from the Unity2D community
Can I use a hand-drawn map?
Hello! I'm new to making games, and I was making a 2D Pixel game when I ran into a bit of a fork in the road. When I started, I thought I should get most of the design aspects of the game (Sprites, backgrounds, etc) out of the way first before I go onto Unity to code.
When I looked at different methods of implementing the map, however, almost every tutorial used Tilemaps to create the map on Unity. I, however, drew up the map beforehand on a pixel art website (Separating the objects so I can add collision later) and now I'm wondering which method is better/more efficient. Is ok for me to use hand-drawn maps or should I use tilemaps and construct my maps on Unity?
Each location in my game is relatively small so I don't mind putting in the effort to hand-draw them all, but in terms of implementing them in Unity, I want to know if my method is ok, how I should go about implementing my map and if it will lead to any problems. Thank you!
https://redd.it/1haogbg
@r_Unity3D
Hello! I'm new to making games, and I was making a 2D Pixel game when I ran into a bit of a fork in the road. When I started, I thought I should get most of the design aspects of the game (Sprites, backgrounds, etc) out of the way first before I go onto Unity to code.
When I looked at different methods of implementing the map, however, almost every tutorial used Tilemaps to create the map on Unity. I, however, drew up the map beforehand on a pixel art website (Separating the objects so I can add collision later) and now I'm wondering which method is better/more efficient. Is ok for me to use hand-drawn maps or should I use tilemaps and construct my maps on Unity?
Each location in my game is relatively small so I don't mind putting in the effort to hand-draw them all, but in terms of implementing them in Unity, I want to know if my method is ok, how I should go about implementing my map and if it will lead to any problems. Thank you!
https://redd.it/1haogbg
@r_Unity3D
Reddit
From the Unity2D community on Reddit
Explore this post and more from the Unity2D community
This media is not supported in your browser
VIEW IN TELEGRAM
Challenging but worth it! Used Unity to integrate the eBay API and made a one-week jam game where you guess eBay lot prices online with friends or solo.
https://redd.it/1hag1gb
@r_Unity3D
https://redd.it/1hag1gb
@r_Unity3D
This media is not supported in your browser
VIEW IN TELEGRAM
Trying to create realistic rainy weather for mobile endless runner - Unity3d - URP
https://redd.it/1hajt0x
@r_Unity3D
https://redd.it/1hajt0x
@r_Unity3D
Flap Ball Gameplay 🎮 | Can You Beat My High Score? 🏆 | Parth Gamehub
https://youtu.be/5JovakKfmMQ?si=fRgFT5No-JCNskh3
https://redd.it/1hawoz0
@r_Unity3D
https://youtu.be/5JovakKfmMQ?si=fRgFT5No-JCNskh3
https://redd.it/1hawoz0
@r_Unity3D
YouTube
Flap Ball Gameplay 🎮 | Can You Beat My High Score? 🏆 | Parth Gamehub
Welcome to Parth Gamehub! 🎮 Dive into the exciting world of Flap Ball, where tapping is your key to victory. 🚀
This game is simple yet challenging—tap to keep the ball afloat, dodge obstacles, and aim for the highest score. Think you can beat me? 😎
👾 What’s…
This game is simple yet challenging—tap to keep the ball afloat, dodge obstacles, and aim for the highest score. Think you can beat me? 😎
👾 What’s…
Media is too big
VIEW IN TELEGRAM
Every time I finish a new level in Mighty Marbles, it feels like creating a brand-new toy! I have actually finished the entire game except the last few levels, glad it really close to the end now and all the other things are done!
https://redd.it/1havkxb
@r_Unity3D
https://redd.it/1havkxb
@r_Unity3D
I'm a 4th year game design student researching nostalgic game graphics for my thesis. Could any of you help me out and complete my survey related to it?
I'm a 4th year university student who's studying video game design and this survey is a part of my thesis on the topic "The commercial potential of nostalgia-based visual design in the video game industry".
I'm on reddit looking for people who could help me out by completing it, as the deadline of my thesis is fast approaching and I am struggling to get the minimal amount of respondents needed. I'd be grateful to anyone who could help out.
It's on google forms, and it doesn't require you to log in.
It's completely anonymous, and will only take around 5 minutes of your time.
The results of the survey won't be used anywhere outside of my thesis.
Survey link: [https://forms.gle/MF9JvJoKequBdcWGA](https://forms.gle/MF9JvJoKequBdcWGA)[](https://www.reddit.com/r/Unity3D/?f=flair_name%3A%22Question%22)
https://redd.it/1hazwet
@r_Unity3D
I'm a 4th year university student who's studying video game design and this survey is a part of my thesis on the topic "The commercial potential of nostalgia-based visual design in the video game industry".
I'm on reddit looking for people who could help me out by completing it, as the deadline of my thesis is fast approaching and I am struggling to get the minimal amount of respondents needed. I'd be grateful to anyone who could help out.
It's on google forms, and it doesn't require you to log in.
It's completely anonymous, and will only take around 5 minutes of your time.
The results of the survey won't be used anywhere outside of my thesis.
Survey link: [https://forms.gle/MF9JvJoKequBdcWGA](https://forms.gle/MF9JvJoKequBdcWGA)[](https://www.reddit.com/r/Unity3D/?f=flair_name%3A%22Question%22)
https://redd.it/1hazwet
@r_Unity3D
Google Docs
The commercial potential of nostalgia-based visual design in the video game industry
I'm a university student who's studying video game design. As part of my studies, I am writing a thesis on the topic "The commercial potential of nostalgia-based visual design in the video game industry" and I am dedicating a part of my thesis to the results…