PDA

View Full Version : Simple gunfire how to


azgrimm
06-23-2015, 08:31 PM
I discovered a relatively simple method to fire projectiles in Alice2.4, I imagine it would work the same in 3.1

1) Add your gun and bullet to the scene, scale your bullet and place it inside the gun *In order to ensure that the bullet fires straight,make sure that you adjust it's rotation.*

2) under the bullet's properties tab, set it's vehicle to the gun

3) create a new bullet method, I called mine Fire
[ Bullet move forward 20 meters duration= 0.1 seconds]

4) create a new event:
While [select key] is pressed
Begin [Bullet.fire]
During [do nothing]
End (drag the bullet's point of view from it's properties tab, ensuring that the numbers match) (set duration to 0.0)



This will ensure that the bullet returns to it's exact position and rotation in relation to it's gun vehicle at the end of it's .fire movement.

Alternatively you could set a second object in the distance that also uses the gun as a vehicle and change your fire method to [Bullet move forward Bullet distance to Target duration 0.1]

you can use the point towards method to adjust your sights, though make sure you change the point of view in your event if you adjust the bullet's rotation.

Hope this helps

CodeMan
06-24-2015, 06:34 AM
Putting the bullets vehicle to the gun creates issues such as when the guns orientation changes the bullets follows creating a weird movement.

There is a better 'ray casting' of sorts way to do it that is much more efficient. You can find it in most of the FPS games created by forum members (residence penguin, halo 1/2, heros mission).

MrMoke
06-24-2015, 07:09 AM
The problem that you mention is easily overcome by changing the bullets vehicle to world when it's fired using duration zero. When it returns, you reset it's vehicle to gun to reload.
Actually mimics reality.

Problem disappears:rolleyes:

Have fun at Summer Camp.

x2495iiii
06-24-2015, 12:17 PM
Resident Penguin doesn't use bullet collision, actually. It uses two dummy objects on either side of the penguin to determine roughly which enemies are directly in front of it. Then it highlights one of those enemies. If an enemy is highlighted when the gun is fired, the hit is automatic.

That old top-down shooter I made a little after RP uses bullet collision, though. The problem we consistently ran into was that bullet collision is inaccurate unless everything in the world has accurate collision detection, which isn't true.

Still, good job for the OP for sharing his methods with the community. Thanks!

azgrimm
06-24-2015, 11:59 PM
I have noted that if the bullet is using the gun as a vehicle (nested as it were)
that the bullet will turn with the gun. The effect seems rather negligible if you minimize the travel/return duration though.

Collision detection seems relatively accurate to me, aside from the fact that Alice only allows for box colliders rather than more form fitting mesh colliders.
It would require more checks, but you could set up sub-object collision, thusly registering head/limb/body shots reducing some of the empty collider space.

MrMoke
06-25-2015, 09:12 AM
I'm onboard with you AzGrimm. Instant hits only work if the target is inanimate, or you're using a Phaser. Time lag and target movement are important parts of the puzzle that saved me several times.

Tricks:
1) Assuming that the axis of the gun is not the barrel, manually position the bullet inside the barrel so that it points forward.
2) Drop a Dummy on the bullet, and make the barrel it's vehicle.
3) Use the Dummy as the bullet's vehicle only when it's loaded/reloaded. This way it comes out of the barrel instead of the gun's axis. Definitely necessary if you are using a tank :-)

The idea of using subparts for collision detection is interesting, and might involve some tricky logic assuming that the axis of any given sub-part is a single point in space that's pretty close to the others. The proximity game is just another challenge for gifted young programmers to experiment with and solve.

Summer Camp Fun.

CodeMan
06-25-2015, 05:53 PM
Resident Penguin doesn't use bullet collision, actually. It uses two dummy objects on either side of the penguin to determine roughly which enemies are directly in front of it. Then it highlights one of those enemies. If an enemy is highlighted when the gun is fired, the hit is automatic.

That old top-down shooter I made a little after RP uses bullet collision, though. The problem we consistently ran into was that bullet collision is inaccurate unless everything in the world has accurate collision detection, which isn't true.

Still, good job for the OP for sharing his methods with the community. Thanks!

Yea, its a raycasting of sorts... :)

sfunk
06-26-2015, 10:23 PM
Instead of vehicling to the gun, try vehicling to the camera/player, so the bullet isn't affected by gun animations. So drop a dummy where you want the bullet to be placed( Inside the barrel of the gun, vehicle the dummy object to the player/camera, then the bullet to the dummy object.)

This way the gun animations don't cause any interaction to the bullet path. And don't have to worry about the finicky vehicle changes while the world is running.

Just a suggestion. But cool to see you thinking how this would work in your own way.

MrMoke
06-27-2015, 09:15 AM
And if you drop the gun, where does that leave the bullet?:confused:

And the shot follows the path viewed by the camera rather than the barrel if the gun is moved/turned? :confused:

azgrimm
06-27-2015, 10:13 PM
Well, I didn't account for flashy gun animations as this is a program for novices and I was attempting to keep it simple as the thread title suggests.

If I wanted to make a game with animations an weapon swaps I would likely do so in Unity where I can .addChild all day long.


Otherwise:

vehicle a dummy to the camera and the bullet to the dummy. Move the bullet backwards until it is just behind the camera.

Bullet var:canShoot boolean = false;
Gun var: isUp boolean = false;

function gunToggle; // pick a button to execute this
[
rotate gun backwards 180 degrees in respect to the dummy

if Gun.isUp = false
[Gun.isUp == true; Bullet.canShoot == true;]
else
[Gun.isUp == false;]
]

function fireGun; //pick a different button to do this ( I like Spacebar)
[
if (canShoot = true)
[ Bullet.Fire;]

else()
[ // do nothing, or firegun2, or stab w/ knife, etc.]
]

Everyone happy now?

CodeMan
06-28-2015, 07:46 AM
Well, I didn't account for flashy gun animations as this is a program for novices and I was attempting to keep it simple as the thread title suggests.

If I wanted to make a game with animations an weapon swaps I would likely do so in Unity where I can .addChild all day long.


...

You use unity?