View Full Version : Checking Area around objects
GhostToast
07-07-2005, 09:30 PM
I am working on my speedometer/car thing, and right now.
I need to have it check the area around the car object for the character object.
So if the character is near the car, it will "enter".
I'm just not sure how to check if its around the car :P :rolleyes:
eatmorchikin6464
07-07-2005, 10:21 PM
hitTest.
Durr....
GhostToast
07-07-2005, 10:31 PM
durr
I'll go do a few searches on that then.
Can I use a mask to create the area around the car?
eatmorchikin6464
07-07-2005, 10:32 PM
if (_this.hitTest._root.MCNAME){
do action;
}
I think that's right.
GhostToast
07-07-2005, 10:47 PM
if(_root.character, hitTest(_root.car1)) {
//Stuff to happen
}
Thats working now at least :D
---
Next thing I cant get working.. is when exiting the car, how to set the x and y of the character to be beside the car.. so far it does move the character.. just nowhere near the car :P
eatmorchikin6464
07-07-2005, 10:51 PM
erm...
the comma has to be replaced with a period. Other than that you have it.
For the x and y thing do something along the lines of
_this._x = Car._x+5
_this._y = Car._y
I don't think that's exactly right. But the point of it puts it at the same y value, making it next to the car. And making the x a little more so it will not be on the car.
GhostToast
07-07-2005, 10:58 PM
OMG Thank you lol...
I had that earlier.. except, I had it changing the x and y, so I decided to take out to y so it would have the same y as the car.. not realizing that it wouldn't set the y at all without it.. so the character was just moving along the top of the screen.
*is a genius* .. I dont even know how I missed that :P
GhostToast
07-07-2005, 11:07 PM
Ok more questions for now...
Is there a way to hide an object and make it show up only when a variable is equal to some number or when a key is pressed?
eatmorchikin6464
07-07-2005, 11:09 PM
_visible = false;
_visible = true;
so....
if (VARIABLE=5){
car._visible = true;
}
The Brown Cow
07-08-2005, 10:22 AM
You could also do a little bit of math...
var xdist = player._x - car._x;
var ydist = player._y - car._y;
var dist = Math.sqrt(xdist*xdist + ydist*ydist);
if (dist < 100) {
// Enter the car
}
This way detects in a circle around yuor car. If the player is within 100 pixels of the car's center, they will enter it. This also makes it easy to change the range of detection. I used this method in the Box of Fun.
GhostToast
07-08-2005, 04:50 PM
Some new questions:
--Fixed--
Still need help with these two things though:
-- Next is when the character exits the car, if the car is turned facing horizontal, the character appears on the hood or trunk of the car :P
--Lastly would be, something tbc could probably help with the best.. is button toggles.. so if I have the button to play a sound or enter the car, that when it is pressed it only does the action once.
eatmorchikin6464
07-08-2005, 05:15 PM
LMAO! Kirupa is stupid for once in it's life!
There is a code using _x and _y for the hitTest. it is something like
it(_this.hitTest(_x._y.car)){
That is not even close to being right but it's all I can remember.
Secondly, about the car thing. The onl thing I can think of is to ask TBC ;)
The Brown Cow
07-08-2005, 07:39 PM
Strange syntax there, EMC.
The point-shape collision form of hitTest looks like this:
clip.hitTest(x, y, true);
The true sets shapeflag to true. shapeflag determines if the hitTest should be done with the shape of clip (if true) or it's bounding box (if false).
eatmorchikin6464
07-08-2005, 07:51 PM
LMAO. I meant if instead of it. Then I just made everything else up. Gah, I'm such a n00b.
GhostToast
07-08-2005, 10:31 PM
--Fixed stuff on my own... yay!--
vBulletin® v3.7.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.