#Pooling bullets from gun
1 messages · Page 1 of 1 (latest)
I'd like to request a screenshot.
Enter Play Mode and Pause it while a bullet is moving towards a wall.
Screenshot so I can see the bullet and the wall in the scene, while showing me the actual script component of the inspector for the bullet.
whats the pause hotkey?
oh
i just found my issue
the bullets fly in the air in such a way that it looks like there touching but there not
there way up
so the real issue
is how tf i make them go where i shoot
rn they just fly off in a weird direction
and spawn in a weird spot
once again the 3 scripts
Best make those into pastebin links
alr
https://gdl.space/equbapudiv.cs - Gun.cs
https://gdl.space/uvobijulel.cs - Bullet.cs
https://gdl.space/zurasixile.cs - ObjectPool.cs
// This will make the bullet constantly move towards an arbitrary direction (always the same)
rb.velocity = Vector3.right * speed;
What you probably want to do when getting a new bullet from the pool, is position it in front of your player, inherit the player's rotation, and move in direction of transform.forward
it looks like that's already what you are doing in the Gun script
the only thing missing then, is the direction.
Read the comment I wrote in the previous code segment.
transform.right is relative to the game object
Vector3.right will always be the same direction.
so with Vector3.right you're telling it to go east,
or rather, increase it's X position, rather than decreasing it.
rb.velocity = transform.right * speed; this?
That's relative instead of absolute, yes.
But I believe you want it to move forward, not sideways.
Yes.
oooh that works
ok now
issue num 2
its spawning weird places arround the gun
like above or below the barrel it changes
Gun script, Line 25:
// Remove this
bullet.transform.position = bulletPosition;
// Replace with
bullet.transform.position = transform.position;
sec
ah true
I just didn't see that.
so ye why does it spawn above or below the barrel
It's difficult to know exactly what the problem is, when the symptom is visual. If you could make a video with OBS and upload it to Streamable.com or wherever, that would be helpful.
sure
Actually, I think I might know what it is.
Wait, how is the player character moving?
Rigidbody or Transform?
uhh
transform i think
or the playercontroller?
idk
tutorial
character controller*
Did you write the CharacterController script, or use Unity's built in one?
built in
kk
I actually can't recall how it works, but that's easy enough to check.
Does the player have a Rigidbody?
mhm
that purple thing is the bullet
So both the player and bullet have colliders.
Perhaps you are actually positioning the bullet inside the player collider bounds.
That would effectively push it out.
so i should test moving it away really far
sec, a simple test
hmm moving it out didnt affect where it spawned
same thing
Alright. Make a video then.
it happens more towards the end
also a future issue after we fix this one, they go right through the floor
also brb rq
bac
From looking at the video, I'm not entirely sure if there is an actual issue. It could perhaps be a visual inconsistency.
I asked a friend with more hands-on experience if he could have a look. No reply there yet.
hmm
There are a few more things we can try:
- Use a different camera angle
- Make the gun's visual component invisible
- Slow down bullet velocity
alr hol up
oh ye nahh its definetely going above and below the barrel
i just want to make it spawn infront of the barell which im certain it dont do rn
how can i make it spawn at the location of the existing bullet and shoot out from there
bulletPosition = bullet.transform.position; this didnt work
I can see why
Does the placeholder bullet always exist, or is it used in the pool?
always exist
And is it referenced?
u want me to paste that
No, sec
is it still off after entering Play mode?
mhm
First off, you don't need the bulletPosition variable
y
second, you have two variables named bullet
it's best to use logical names
Like bulletSpawn and bullet
nvm i see
I'm feeling the need for coffee, because I already ran two circles around my head with this thing,
but I'll unload what I have for now.
dont stress yourself i appreciate your help so far but ima head to bed, and i wont have access to my computer for the following 2 weeks so i guess cya
The bulletSpawn bullet object should have its collider and rigidbody disabled. The collider can stay if you offset the position.
For testing purposes, make Player and Bullet not collidable, with the Collision Layer Matrix
hm
Two weeks sounds like a horribly long break for a beginner.
At least your scripts are still simple at this point.
ye well family vacation sucks but when i get back i have 3 weeks of holidays to grind
Two weeks break means you can't comprehend your previous code, unless you actually made it readable and used comments.
Haha nice
Good luck with all that.
Break problems down to simpler bits, solve each one, then combine.
Good night and have a nice vacation o/
will do