Attempting my first person shooter. When I shoot, the bullet casing correctly flies from the gun, and the bullet shoots. How ever I can only shoot once, how can I repeat the same action over and over using the same bullet/casing?
Also any tips on how to have a laser pointed on objects?
Thanks for the information. I am trying to move the casing to a hidden layer and it isn’t working, can you tell me the proper way of doing that? I clicked “M” and placed it on the 2nd layer, I am guessing that will working?
change the space sensor to an always sensor wit tap enabled- this basically means that it will fire once, and only once, on the frame that the casing is created. Then, as long as it’s on a hidden layer (second layer is fine, as long as you’re running the game without the second layer set to visible) you can use an add object actuator on the gun, attached to a space sensor, to add the casing object. It’ll trigger its own motion brick with the tap sensor, and go flying.
I recommend placing an empty where the casing should leave the gun (right on the ejection port or whatever it’s called) and putting the add object actuator on that, but keeping the space sensor on the gun (you can plug logic bricks across objects if you have them both selected at the same time)
You can actually remove all the logic on the casing entirely, and give it a starting trajectory with the gun’s add object actuator (use the linV settings, make sure to enable the little L button so when you turn the gun the casing still shoots out at the right direction) I’d have said this earlier but I entirely forgot about the linV settings on add object actuators (I’m used to adding everything through python, once you figure out scripting it’s a lot more versatile)
also, make sure the casing is set to rigid body so the physics engine gives it gravity and whatnot.
Additionally, if it’s still not working, run the game in wireframe mode, and see if the casing appears inside the gun at all; there’s a chance that it’s not adding, but there’s also a chance that it is adding but isn’t moving outside of the gun’s body.
You know, it might be easiest if you just make a blend with the same problem and post it here (of if you’re fine putting your gun and casing models online, just post the one you have) so we can take a look at it.
Your problem is twofold- the first is that the gun is massive, and scaled down. This means that the casing is added in scaled down, a lot. It’s almost too small to see. If at all possible, try to keep your objects scaled to 1 (you can apply the scaling by hitting ctrl-a)
Second, added objects appear at the center of the object that added them; your gun’s center is set to the bottom of the handle. The casings appear there. Here’s a corrected version; note that I’ve used an empty as the actual object that adds the casings, so I can have them appear wherever I want without having to move the gun’s center.
Also, you’ve set the initial linV to nearly 0, so you won’t notice any significant movement as a result of that (though multiple casings appear in the same space, so they fly apart)
Other changes I made:
-applied scale to the casing- Blender’s physics engine hates scaled objects. It really does.
-re-centered the casing- physics work best in the center of the object is set to where the center of its mass should be
-changed the casing’s bounds to box- the default bounds are sphere, with a size of 1. This is like a bowling ball sized object flying out of your gun, you’d get pretty wonky results. Box bounds are automatically scaled to fit perfectly around the object’s actual mesh.
-changed the life of the casing- 50 frames is a good amount of time for the thing to fly off screen; too little time and it disappears abruptly without warning, too much time and you’ve got a lot of unnecessary objects bouncing around.
-changed the pulse delay on the space sensor, so it waits a few frames to fire. If the pulse is set to 0 that’s 60 shots a second. that’s a pretty ridiculous firing rate.
-basically made all teh same changes to the bullet, as well as tweaking its logic. Now the bullet shoots out of the barrel each time you fire, and moves on its own.
I highly recommend you just go back and forth between your file and the changed one, look at every change and make them yourself- and tweak settings, or leave them out, and see how that affects things. Hopefully that’ll give you a better understanding of what changes I made, rather than just working off a file you were provided. Also, that means if I made a change you don’t like, you can just pretend it never happened and cruise on past.
[edit] I forgot to parent the empties to the gun so they’ll follow it around. I trust you can do that part yourself though.
Ok so I parented the casing to the gun and added all the movement keys. However when I move, the casing stays in the same spot and doesn’t follow me. I selected both and did Ctrl P and clicked parent. But nothing happens.
Also I build the structure of the stage, and when I change the gun to dynamic, it falls through the floor.
In the blend you supplied neither the casing nor empty that adds the casing have a parent.
It doesn’t matter at all where on the hidden layer the casing is, or what it’s parented to- when you use an add object actuator, the object (in this case the casing) will always be added at the center of the object that adds it (in this case, the empty that sits just above the gun). Since you didn’t parent that object to the gun, it will always be added in the same spot regardless of whether or not the gun is there.
Also, just as a pointer, the BGE is designed such that 1 BU (one grid square) is equal to one meter. This is really only important when you’re working with physics; right now you have everything scaled so large that the casing is about half a meter long. This means the physics will feel extremely floaty and light.
Select the empty that adds the casings, then select the empty that adds the bullets, and then finally select the gun (so it’s the active object- it’ll have a brighter outline) then hit ctrl-p.
[edit] oh wait, you posted a screenshot that looks about right, I’m not sure why it’s not working. I tried it in the file you supplied and it worked just fine.