One, I just got flash mx, and I've been having a hard time scripting. What's this output panel where the error information goes? I can't find it anywhere, I tired going up into window and I can check and uncheck the option for it, but it doesn't show up. F2 doesn't work either. Very difficult.
Two, how do I add a projectile mc? I can't even figure out the basics... but what I want to do is create a cork that flies out of a bottle when you press "A" . The main character is a bottle, yes. So, I've animated him shooting out his cork when you press "A", but the extent of it was making him close his eyes and removing the cork. I want to atatch another mc of a cork that I can hit test against enemies. Also when either A is pressed again, or the cork reaches the end of the screen, I want it to return to the bottle. (Kind of like the boomerang in Zelda) When it returns to the bottle I want it to cork itself. I might figure it out on my own, probably won't, especially without knowing what's wrong with my code.
Thanks! By tomorrow I'll probably have enough to show you.
Last edited by Angry Safer; 09-22-2005 at 11:57 PM.
Reason: fix title
There are many more ways to do that but I need more specific knowledge on the cork thing.
As for the output window is concerned, have you actually seen it in run-time?? Try pressing ctrl+enter to go into runtime and then press F2, if it still does'nt show-up.....weird!?!
first question: can't remember but you can add this code to the main timeline:
code:
trace("output window is open")
second question: You want to use angles for this. Don't know how your code is set out so you'll have to change names and paths.
Main timeline
code:
//create movieClips: bottle, cork.
//export linkage ID for "cork".
function bottleRotate() {
var x = _root._xmouse-bottle._x;
var y = _root._ymouse-bottle._y;
var angle = Math.atan2(y, x);
var degree = Math.floor(angle/(Math.PI/180));
bottle._rotation = degree+90;
}
onEnterFrame = function () {
bottleRotate();
cork.control();
};
onMouseDown = function () {
attachMovie("cork", "cork", 1);
cork._x = bottle._x;
cork._y = bottle._y;
cork.degree = bottle._rotation-90;
cork.speed = 20;
};
Cork Clip
code:
function control() {
speed -= 1;
_x += speed*Math.cos(degree*(Math.PI/180));
_y += speed*Math.sin(degree*(Math.PI/180));
_rotation = degree;
if (speed<0) {
if (_root.bottle.hitTest(_x, _y, true)) {
this.removeMovieClip();
}
}
}
*Note* this is not the best code, i typed it pretty fast, What i does is creates a movieClip called "cork", gives that clip the correct angle to move at and the inital speed. The cork moves with these values and removes itself when it hits the bottle.
I haven't tried it yet Mr_malee, but I think I see how it works. Clever. I spent about two hours last night I got my clip to attach but I couldn't get the value correct, it showed up a a little to the left of where I wanted it to, I could get it to adjust.
Oh, and I started flash this morning and the output window took up half the screen out of nowhere. So... whatever, I have it now.
I'll probably try to get the code in between some classes, I'll post a swf tonight.
Also, I was having trouble detecting when a specific key, in this case "A" was pressed from the main timeline. I was attaching the cork from my bottle mc because I could detect which key was pressed within an on clip event. I have no idea how to do this from the timeline codes. Spent a while botching the code.
Last edited by Angry Safer; 09-23-2005 at 08:57 AM.
Alright, I checked out the script and some old stuff I had laying around, played around for a while. Read the help file, and error messages. This is what I can get working... I don't want to rotate the bottle or the cork, the bottle follows the mouse, and the cork should just fall back down towards the bottle. So, what I want to happen is:
Press A: Launch a cork then
Cork reaches top: falls back down towards bottle OR
Press A again: cork falls towards bottle
Once it hits the bottle it is removed and the bottle goes back to its first frame, ready to repeat the process. Am I making any sense?
will the cork be following the rules of physics, i.e gravity. You say the bottle will be following the mouse, is this around the whole stage or is it constrained to an axis. I'm guessing you just want the bottle to move on its X axis as you said the cork and bottle won't be rotating. If so, you don't need any of the angle detection, the code becomes much simpler.
Wow, thansk a bunch! That's pretty much what I wanted, I can tweak it a bit, I'm sure. I have MX too, no problem opening the file.
I'm a little confused by some of the coding, and I've learned quite a bit on thsi project, but I wouldn't might need a little clarification... Man, it's been so long since I coded anything, and I was never too good at it to begin with..
alright, maybe it's the fact that I have no sleep, but I can't get this to work the way I want.
var gravity = 1;
function deleteMe() {
_root.bottle.gotoAndStop(1);
this.removeMovieClip();
}
onEnterFrame = function () {
if (_this.hitTest(_root.bottle)) {
deleteMe();
}
if (_y<100) {
mode = "moveBack"
}
if (mode != "moveBack") {
y -= gravity;
_y -= y;
} else {
var ratio = 8;
var yd = _root.bottle._y-_y;
var xd = _root.bottle._x-_x;
_x += xd/ratio;
_y += yd/ratio;
}
};
I want to make the cork fall back to bottle just like it did if it you press A when it reaches the top. That's how I tried to code it, it kind of works, but now it hovers around the bottle instead of removing. Also, it kind of slows down as it reaches the bottle... I'm thinking a more realistic gravity equation might work better. It's been a year since I had physics and I'm bad a math, add my inexperience with coding, and I get reluctant to mess around with it. I know I'll probably wind of messing with it anyway. You've helped me out a lot.
I'm thinking a more realistic gravity equation might work better.
There's nothing wrong with my implementation of gravity, its just a matter of changing the gravity value to what you want. The reason your version's gravity looks weird is you've added this:
code:
if(_y<100){
mode = "moveBack"
}
that will instantly make the cork go back without slowing down. I suggest removing that code, (if you want realistic looking gravity)
but now it hovers around the bottle instead of removing.
You had an error in your code, you wrote: "if(_this.hitTest(_root.bottle))" when it should be "if(this.hitTest(_root.bottle))"
Also, it kind of slows down as it reaches the bottle
That was because i was dividing the distance between two points, as the distance got smaller so did the speed at which the object moves. There's probably a better way to code it but you need to use angles:
code:
if (mode != "moveBack") {
y -= gravity;
_y -= y;
} else {
var speed = 15;
var yd = _root.bottle._y-_y;
var xd = _root.bottle._x-_x;
var angle = Math.atan2(yd, xd);
_x += speed*Math.cos(angle);
_y += speed*Math.sin(angle);
}
}
Ok, I tweaked some of the x and y values because my objects don't line up right.. meaning the cork would fly a tad to the left of the bottle and the hands would float a bit to the right. But I fixed it up. Do you think I'm going about this the right way? What's going to happen is:
The "water" will represent life, when you get hit it will go back a frame, when it reaches the last frame you wil lose.
The hands are going to handle any power ups I add.
I'm pretty sure they must be on their own layers to handle the animation, but I was wondering if that's really the case...
Thanks so much Mr_Malee
- Main timeline: Global actions, background
- Bottle: Bottle specific actions, - Hands Clip and Water Clip nested inside on seperate layers. Remember though, if you want the hands clip to move seperatly from the bottle don't place the hands inside the bottle, however if you are going to create effect's which shoot out from the hands, then put the hands clip inside the bottle.
VERY IMPORTANT
- Its good practice to keep frames to a minimum when a movieClip contains child movieClips otherwise things tend to get confusing. Create three new movieClips inside the bottle and name them:
-BottleAnimation
-WaterAnimation
-HandsAnimation
Create the appropriate animations, so now when you want a clip to play you would do it like:
waterAnimation.gotoAndStop(2), organise your movie better and it'll be easier to code it.
That's a lot of good advice. I tried taking it, but only half of my stuff works now. I tried renaming the paths, but it only got about half of the stuff working.
So what I've got is like this:
Layers:
Actions
Background
Bottle
In the Bottle laye I have a Bottle mc with BottleAnimation, WaterAnimation, and Hands mcs all on their own layers. I guess I'm asking where do I need to move the script and what paths do I need to change. It seemed pretty simple, but I keep goofing it up.
Edit: here's the fla file if I'm not making any sense..
Last edited by Angry Safer; 09-26-2005 at 11:01 PM.
Reason: adding fla/forgot fla