Alice Community  

Go Back   Alice Community > General Discussion > Questions and Comments

Reply
 
Thread Tools Display Modes
weapon shoot?
Old
simsman2011
Senior Member
 
simsman2011's Avatar
 
Status: Offline
Posts: 132
Join Date: Jul 2011
Location: somewhere on Earth
Talking weapon shoot? - 07-27-2011, 07:41 AM

I am sorry for asking too many questions recently....
I want to know how to make a method that makes the weapon shoots 'cause I can't find a method that does that......
   
Reply With Quote
Old
legolizard
Senior Member
 
legolizard's Avatar
 
Status: Offline
Posts: 242
Join Date: Jan 2011
Location: Aboard the Hyperion escaping the zerg.
Default 07-27-2011, 09:09 AM

To make something "shoot" in Alice you can't just have a method, you must also have a specific event that runs a specific method. The most common events used for shooting are the "When the mouse is clicked on something," and the "When a key is typed," but you can use any event you want. For this example I will use the latter event. So make a "When a key is typed event" and you should get something like:

Code:
When any key is typed do nothing

Now click on the "any key" part and a drop down menu will appear. Select the button you wish to use for when you want to shoot for this example I'll use the space bar. Now you should have something like.....

Code:
When SPACE is typed do nothing
Now here comes your method. After you have created a new method let's say "shoot" drag it into the "do nothing" area of the event. Making something like:

Code:
When any key is typed  do world.shoot
Now there are many different ways in which you can make a a bullet shoot an then detect if you hit something or not and collision detection isn't my strong suit. Here are some ways that I have tried in making a shooting method:

1) This method involves actual collision between two objects the bullet and the target. It is probably the easiest but most inaccurate method. In this method you must also have created two dummy objects one being where the bullet starts and the other being where it ends it also requires you to have the bullet vehicled to the camera an that the bullet is invisible while you are not shooting. It should look kind of like:

Code:
doInOrder{
     doTogether{
                    sphere move to endDummyObject duration .1 seconds
                    sphere set isShowing=true duration 0 seconds
                    gun turn backward .05 revolutions
}
      doTogethor{
                   sphere move to beginDummyObject duration .1   seconds
                   sphere set isShowing=false duration 0 seconds
                   gun turn forward .05 revolutions
}
}
Now there are two things missing: Something for collision detection and something else that takes a little imagination to envision. See the bullet moves forward and then comes back like a spring and so makes it possible to get two kills, one being on purpose the other being because you hit somebody while going backward. To counter this lets add a bool variable(true and false) to minimize the chance of this happening;this will make more sense later.You should have:
Code:
doInOrder{
     doTogether{
                    sphere move to endDummyObject duration .1 seconds
                    haveShot set equal to true
                    sphere set isShowing=true duration 0 seconds
                    gun turn backward .05 revolutions
}
      doTogethor{
                   sphere move to beginDummyObject duration .1   seconds
                   haveShot set equal to false
                   sphere set isShowing=false duration 0 seconds
                   gun turn forward .05 revolutions
}
Don't worry we are almost done with this method!


Finally create another event this one being the "While something is true." Right click it and change it to, "When something becomes true.

Now the event bar should look like this:

Code:
When any key is typed do nothing

Now click on the "any key" part and a drop down menu will appear. Select the button you wish to use for when you want to shoot for this example I'll use the space bar. Now you should have something like.....

Code:
When SPACE is typed world.shoot
When condition=none becomes true  do nothing
Next go to the sphere's functions and you will see one that looks similar to:
Code:
sphere is within threshold of object
Drag this in replace of the "condition=none" to get:
Code:
When SPACE is typed world.shoot
When condition=sphere is within some distance of target becomes true  do nothing
We now need to add two more things for this method to work with a proper result.One we need a death animation, but that will be up to you on how you want that, but we still need one more thing. Remember that bool variable we created above we are going to use it here. Go to the world's functions and find the one that says :

Code:
both a and b
Drag it onto the condition and a little popup should appear;click true. You should now have:
Code:
When SPACE is typed world.shoot
When condition=sphere is within some distance of target and true becomes true  do nothing
Finally drag your variable(my was called haveShot) in replace of true and you are done!

The final result is:

Code:
When SPACE is typed world.shoot
When condition=sphere is within some distance of target and haveShot becomes true  do world.deathAnimation
Here is another method for shooting.

In this method,unlike the method above, there is no collision between objects. Now this method is slightly harder,but is noticeably more accurate. First imagine a coordinate plane, with that imagine a picture with its center lined with the origin. The picture ,for the sake of this example, is 10 units in length and 10 units in height. Now imagine another picture with coordinates of ( 0,10) thus being five units to the right of the image at the center. Then move the second image closer to the first one until they are touching or colliding. We will use a similar principle with the exception of the all annoying Z axis, as a way to shoot or primarily as a way to detect for "collision".

So import an object preferably a cone, and then right click the cone and select set point of view to and then select the camera. After right click the cone again and then select turn forward .25 revolutions, and then move the camera very slightly backward it should look like this:
Capture.jpg

Next place your target does not really matter what it is. Here is where the fun comes in. Go to the world's function and select "Create new function" at the top. You can name it whatever you like, but for simplicity I will call it "collisionDetection." Also it is important to make this function return a bool value so you must select the bool type in the popup menu. This function will take one object parameter and will have one local bool variable. I will call the parameter object and the variable I will call "hasCollided" I will also set it equal to false. Now drop an if statement in the function and select true. Next go back to the world's functions and drop in 4 both a and b's so that it looks like:

Code:
if(both true and true and both true and true)
I must go so I will pick up on this later.


"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."-Albert Einstein

Last edited by legolizard; 07-27-2011 at 07:03 PM. Reason: continuation
   
Reply With Quote
Old
jediaction
Senior Member
 
jediaction's Avatar
 
Status: Offline
Posts: 5,064
Join Date: Jul 2009
Location: Bel Air, Maryland
Default 07-27-2011, 12:00 PM

Wow, you spent a long time on that method. I hope everyone appreciates that cuz I do.


Website: www.salokingames.com
FaceBook: www.facebook.com/SalokinGames
   
Reply With Quote
Old
legolizard
Senior Member
 
legolizard's Avatar
 
Status: Offline
Posts: 242
Join Date: Jan 2011
Location: Aboard the Hyperion escaping the zerg.
Default 07-27-2011, 12:53 PM

Thanks Jediaction.


"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."-Albert Einstein
   
Reply With Quote
Old
simsman2011
Senior Member
 
simsman2011's Avatar
 
Status: Offline
Posts: 132
Join Date: Jul 2011
Location: somewhere on Earth
Default 07-27-2011, 05:10 PM

I appreciate all of that hard working but just a small question....
what is dummy????(I can find it in Alice but I don't know what it is)





Thank you for your hard working
   
Reply With Quote
Old
legolizard
Senior Member
 
legolizard's Avatar
 
Status: Offline
Posts: 242
Join Date: Jan 2011
Location: Aboard the Hyperion escaping the zerg.
Default 07-27-2011, 09:28 PM

A dummy object is an object that during run time is always invisible and thus doesn't have properties such as color or opacity. They are most useful for positioning.


"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe."-Albert Einstein

Last edited by legolizard; 07-29-2011 at 06:36 PM.
   
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 ©2022, Carnegie Mellon University
Alice 2.x © 1999-2012, Alice 3.x © 2008-2012, Carnegie Mellon University. All rights reserved.