Alice Community  

Go Back   Alice Community > Alice 2 > How do I...?

Reply
 
Thread Tools Display Modes
Simple gunfire how to
Old
azgrimm
Junior Member
 
Status: Offline
Posts: 5
Join Date: Jun 2015
Default Simple gunfire how to - 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
   
Reply With Quote
Old
CodeMan
Member
 
CodeMan's Avatar
 
Status: Offline
Posts: 36
Join Date: Aug 2013
Location: Northern Virginia
Default 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).


Im really RavenOfCode... shhhh....

Currently work on my first app :)
   
Reply With Quote
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default 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

Have fun at Summer Camp.

Last edited by MrMoke; 06-24-2015 at 07:24 AM.
   
Reply With Quote
Old
x2495iiii
Super Moderator
 
x2495iiii's Avatar
 
Status: Offline
Posts: 3,508
Join Date: Dec 2008
Location: Somewhere in the Continental U.S.
Default 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!


(')>
   
Reply With Quote
Old
azgrimm
Junior Member
 
Status: Offline
Posts: 5
Join Date: Jun 2015
Default 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.
   
Reply With Quote
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Thumbs up 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.

Last edited by MrMoke; 06-27-2015 at 09:18 AM.
   
Reply With Quote
Old
CodeMan
Member
 
CodeMan's Avatar
 
Status: Offline
Posts: 36
Join Date: Aug 2013
Location: Northern Virginia
Default 06-25-2015, 05:53 PM

Quote:
Originally Posted by x2495iiii View Post
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...


Im really RavenOfCode... shhhh....

Currently work on my first app :)
   
Reply With Quote
Old
sfunk
Senior Member
 
sfunk's Avatar
 
Status: Offline
Posts: 1,112
Join Date: Mar 2011
Location: I don't know
Default 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.


If you are stuck on a project, check out the tutorials I made here at this link:

http://alice.org/community/showthread.php?p=36778#post36778

There are lots of tutorials on it so far, including some youtube videos, check it out

Or..

Go to my youtube channel to check out my alice 2.2 tutorials I have there..

http://www.youtube.com/user/sfunk1992?feature=mhsn
   
Reply With Quote
Old
MrMoke
Senior Member
 
MrMoke's Avatar
 
Status: Offline
Posts: 501
Join Date: Sep 2007
Location: Austin, Texas
Default 06-27-2015, 09:15 AM

And if you drop the gun, where does that leave the bullet?

And the shot follows the path viewed by the camera rather than the barrel if the gun is moved/turned?
   
Reply With Quote
Old
azgrimm
Junior Member
 
Status: Offline
Posts: 5
Join Date: Jun 2015
Default 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?
   
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



Copyright ©2024, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.