I need help for my first game on my own

Hi everyone :slight_smile:

In this video u can see how bullet “skip” player2 or enemy, and i don’t know why is this happening.
On my prefab bullet is Script that move object, i tried to use transform.Translate(), transform.TransformDirection(), GetComponent().AddForce() or .velocity , but the same problem is always there, only if bullet is slow down then is fine but who want slow bullet?
[u should have category that every one can share they own games]

Tnx for your time :slight_smile:

@Nina Will probably correct me on this but i think this is similar to another post.
Could this be down to the collision detection causing this.
I note though that your player shot actually seems to spawn behind the player as well

Yea my Player instantiate bullet’s from left side for now and shot only to right way , tnx anyway :slight_smile:
hmm but my collision detection work on any other distance, as u can see in video, only in specific distance from enemy it looks like he skip player , like bullet is teleporting not traveling.

How exactly do you use your bullets? And how fast are they?

  1. If they are too fast, the colliders could miss them. Try to set the Collision Detection of the Rigidbody2D component to “Continuous”. You could also tweak some values in the Physics 2D settings. However, this will have a negative impact on the performance of your game. Maybe it’s not noticable, maybe it is.

  2. If you move your bullets via the transform, it might be that your code overrides the values calculated by the physics simulation. Use FixedUpdate() and Rigidbody2D methods.


See also:

  1. All my rigidbody in game are set to Continuous, but didn’t know that that has impact on performance .
  2. I use FixedUpdate() method and transform.Translate(Vector2.right * bulletSpeed * Time.fixedDeltaTime); my bullet speed was set to 80 in video.

Why don’t you instantiate the bullet and give it a velocity?

I tried this way GetComponent Rigidbody2D ().velocity = transform.TransformDirection(Vector2.right * bulletSpeed * Time.fixedDeltaTime); or with GetComponent Rigidbody2D ().AddForce() but the same problem was there, i didn’t want to use new Vector2 because it sounds like there is better solution than new Vector 2(x,y).

You set the velocity once after you instantiated the bullet. You don’t set it multiple times.

mb, i was in bus and i just looked in my code i used transform.Translate(Vector2.right * bulletSpeed * Time.deltaTime), but i tried thats i was mentioned in the last comment , and my bullet was too slow with huge bulletSpeed , and i didnt know why , so when i use velocity it needs to be new Vector2 , i just tried to use GetComponent RigitBody2D ().velocity = transform.TransformDirection without Time.deltaTime but then there’s a problem with bullet skipping the enemy if it goes fast.

You will always have that speed problem at some point in Unity. As aforementioned set the velocity once after you instantiated the bullet. Do you remember how we launched our ball in Block Breaker?

I do and i tried , same problem with skipping enemy, can i share my project with u (GitHub?) , so u can see what is problem…i mean if we can do that?

i was searching on internet, and saw that is common problem with unity if object are too small, but i don’t think that bullet is too small, it needs to be small.

Well, it does not matter what you or I think about the size of the collider but what the Unity engine “thinks” about it. In one of my previous posts, I suggested to tweak the values in the Physics 2D settings. Have you already tried that?

If all enemies can be hit by a bullet, you could write a simpler solution that does not involve any collision. You know the position of your player and the enemy. The bullet is probably intended to be fast enough, so the enemy won’t be able to dodge it. When you shoot at the enemy, you could decrease its health in the same method. The bullet could be an animation that fades away after a x seconds (or whatever your bullet is). Do the maths if necessary or use a hard-coded value. When you fire your gun, you could use Physics.Raycast to detect an enemy within the shooting range.


With 250,000+ students to support in the Unity courses, I’m afraid I can’t help out with issues that are outside the scope of the course meaning I do not have time to download and/or debug any personal projects. Please feel free to ask our helpful community of students for advice in our official Discord chat.

2 Likes

Hi Daniel.

Did this get resolved in the end?
If so can you mark a solution or let us know.

Thanks in advance

I just made the collisions bigger and slowed down the bullet,it’s not what i was going for, but it’s how it work.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms