#Bullet Problem

1 messages · Page 1 of 1 (latest)

cerulean igloo
#

So I have come up with some plans,

  1. I try OnCollision with continues dynamic ( prob alr did )
  2. I retry OnTrigger with Vector.Reflect
  3. I retry Raycasting with a twist, I make a longer raycast , and when close to enemy/player it starts spamming overlapsphere ( idk about performance tho )
#

does the third option make performance rlly worse?

cerulean igloo
#

why wouldnt 2 work?

#

Reflect is for things like Raycasts

#

make bullet follow raycast?

#

It can’t get normal colliders

cerulean igloo
#

No

#

damn

#

Unless you wanna write like 1476 lines of code

cerulean igloo
#

Nah it’s not possible is what I’m saying

#

lol

cerulean igloo
#

and the 3 option?

#

why not?

#

performance?

#

or do I not completly understand OverlapSphere?

#

I asked that question some time ago

#

About the ray thing

#

It’s not gonna work

#

I have an idea

#

The only thing close to my answer was the raycast

#

You’re gonna have to focus a lot cuz it’s a bit hard to explain

cerulean igloo
#

oh your idea

#

im all ears

#

So the problem is that the enemy bullet hits the player and it bumps him back right?

#

yessir

#

goddamn thats long

#

but take your time

#

So, you can make

The main Trigger bullet the parent of the Collider bullet

So the trigger bullet is a bit bigger than the collider bullet

The collider bullet is the one that can make it actually collide with walls and bounce

But if the trigger bullet detect the player, it deleted it self, which will also delete the collider bullet (since it’s the parent)

#

The trigger bullet is invisible

#

nice plan

#

however

#

Wait hold on the meeee

#

U see the speed,

#

IF its is trigger , it would need to be much bigger then collider

#

and that faces another problem

#

the bullet hits before actually touching the player

#

Trigger Bullet (Parent, the bullet with the script)
-Collider bullet (Simple allows it to collide)

#

so dodgeing wont be so fun lmao

#

Hmmm

#

You sure it would need to be that much bigger?

#

You should still try

#

not sure im gonna test

#

however rn I cant I have to do some math homework

#

Rip

cerulean igloo
#

doesnt work sadly

#

However I have another idea

#

I combine a prediction script I found with your idea

#

The prediction script predicts the bullet and if it phases trough the player it is put back inside the player.

#

If I manage to change the prediction so that it is always off by the distance of the is trigger collider of the bullet , then it should work

#

Problem being , idk how to manage it

cerulean igloo
#

.

#

.

#

.

#

So after some testing

#

I have come to this

#
    private void FixedUpdate()
    {
        StartCoroutine(Predict());
    }

IEnumerator Predict()
    { 
        Vector3 prediction = transform.position + rb.velocity * Time.fixedDeltaTime;
 
        RaycastHit hit2;
 
        int layerMask =~ LayerMask.GetMask("Bullet");

     if(Physics.Linecast(transform.position, prediction, out hit2, layerMask))
     {
 
        transform.position = hit2.point;
        rb.collisionDetectionMode = CollisionDetectionMode.ContinuousSpeculative;
        rb.isKinematic = true;
 
        yield return 0;

        OnTriggerEnter(hit2.collider);
     }
    }

This has weirdly kinda solved the problem,

  1. Player doesnt get pushed anymore if standing still
  2. Player still gets interuped if walking in bullet
  3. Bullet doesnt bounce anymore cause it gets teleported by the prediction in the player
cerulean igloo
#

Since I am not going anywhere

#

I might switch my enemy bullets to is trigger

#

However I am still waiting for hope

cerulean igloo
#

What if you make the player have a trigger object around him and it detects bullets?

cerulean igloo
#

Imma stick to isTrigger bullets

#

on enemys

#

cause I cant make any so smart to predict the player and reflect bullets off of walls

#

Fun fact , my whole project got corupped because of that bullet that cloned itself

#

.

#

.

#

The reason it crashed is cause I want to make it so that the bullet splits above the player/enemy

#

And I used a raycast

#

And when raycast hit it would clone

#

little did I know , a raycast shoots super fast even if the bullet is above for a split second

#

Any ideas to make this work?

cerulean igloo
cerulean igloo
#

Wth happend?

#

Imma send script in a sec

#
    private void FixedUpdate()
    {
        if (Physics.Raycast(transform.position, Vector3.down, Mathf.Infinity, whatIsPlayer) && rayCastHtAlr == false)
        {
            rayCastHtAlr = true;
            coolCloning();
        }
    }```
#

coolCloning is when the bullet explodes into more

#

Nice

cerulean igloo
#

So um

#

How can I make it so that coolCloning only activates once?

#

I cant really explain what is causing it do it more then one time , since my pc crashes after that actually happens

cerulean igloo
#

Unsure

#

It spawns it as long as the ray is hitting

#

That’s the issue

cerulean igloo
#

so after all this time I fixed the bouncy bullet problem

#

now all I have to do is fix the cool cloning bullet

cerulean igloo
#

How’d you fix it

#

So um

#

Started a way to predict where the bullet would land , and move the bullet in that place before it passes it

#

by passing means it goes so fast , 1 frame is in front of wall , next frame is behind wall

#

which meant no collision

#

but I fixed this via the prediction

#

and once it gets moved to the position of the impact

#

I calculate the new velocity after the bounce via Vector3.Reflect

#

And change the velocity of the rigidbody to that ( exactly when it gets moved to the position of the impact )

#

Hope u understand me

#

( if u want code , I can send )

#

@cerulean igloo continue here

#

so

#

Have you heard of collision detection?

#

bullet affects movemnet , when the player head in into the bullet he doesnt just take damage he also stops for seconds because of the collision

cerulean igloo
cerulean igloo
cerulean igloo
#

So he doesn’t hit it

#

it doesnt spawn in him

#

its in a gun a bit far away from the player collider

#

So he runs in the bullet?

#

oh no

#

when the enemy

#

shoots

#

and he runs into the bullets

cerulean igloo
next steppe
#

the bullets "penetrates" him and slide out

#

?

cerulean igloo
#

So it hits the gun or the player body itself?

#

Maybe show a video

cerulean igloo
next steppe
#

so lets get one concept clear, when you talking about the whole process of "shooting" in normal shooting games.

you are talking about

  1. player shoot a bullet
  2. bullet "hits" something
    2.5 bullet send message to scripts
  3. bullet dissappear
  4. effect is spawned
next steppe
#

i assume in ur shooting games, u dont want ur bullet NOT DISSAPPEAR after it hits target

#

u want it to dissappear

cerulean igloo
#

yessir

next steppe
#

but it doesnt, it penetrates players and keep travelling

#

so that is what i called slide out, from players

cerulean igloo
#

so phase

#

yes I understand

cerulean igloo
#

Using Trigger is a bandaid solution for this, especially when bounciness is the main part of the bullet

#

yes but how can I make so that it send a message at collision without collision

#

I just cant another way exept isTrigger

#

I will accept any other function solutions

#

Put the bullet to speculative dynamic, it will detect collision properly

#

You can’t check collision in a dif way

#

Getting pushed by the bullet

#

thats my issue with OnCollisionEnter

#

Is that the enemy bullet?

#

Can’t tell, it looks like it’s coming from the enemy

#

yes

#

Try putting the bullet mass to 0

#

(It will make it a tiny mass)

#

But that doesn’t look like much of an issue

#

You can destroy the bullet after the hit

#

its a beam

#

ig its the object moveing INREDIBLY fast

cerulean igloo
#

It’s ok

#

1e-07

#

The weird number is a super tiny number

#

7 zeros I think

#

think

#

I see

#

but now its even worse

#

hold on

#

what should the bullet rigidbody look like?

#

Ok nvm if it’s worse

cerulean igloo
#

Is the bullet deleted after the hit?

#

Interpolate / CollisionDetection

cerulean igloo
#

just a ray

#

Oh

#

Then in the ray script theres something that applies force to the ray hit object

cerulean igloo
#

because of how fast its going i think

cerulean igloo
#

It will still bump the player if its slow

#

well then , what should I do?

#

Hmmm

#

What if you increase player mass

#

And decrease bullet mass

#

the slow down still kinda happens

#

my whole point is to exterminate it

#

Yeah ik

#

I wonder if collision detection still works with Ignore Collision

#

That could work if it does

cerulean igloo
#

Yes

#

But the main problem is that I’m unsure if it will detect collision still

#

Detect OnCollision