Flash Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignFlash Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 1st, 2004, 01:47 AM
madskater212 madskater212 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 27 madskater212 User rank is Private First Class (20 - 50 Reputation Level)madskater212 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 h 31 m 56 sec
Reputation Power: 0
Ball bouncing off of a box

I have a movie clip (square) that moves from the top of the page to the bottom of the page, then another one (a ball) bouncing all over the place. I have it so when they hit, the ball bounces off depending on which part of the square it hits (top, bottom, left, right). The problem is, the way it picks which way to bounce (if it hits the top or bottom side it reverses it's y direction, left and right side chang x direction) doesn't seem to be working. The code is attached, and you can find the swf at www.madskater.com/randfiles/brokenswf.swf (just check the second checkbox on the initial frame, and set the speed to 5 or so to slow it down). It works probably 60-70% of the time, but for some reason when it should bounce off of the bottom, for example, it will act as if it had bounced off of the side. Help would be appreciated.

if (Math.abs(this._y-(_root["fallingblock"+k]._y))>Math.abs(this._x-(_root["fallingblock"+k]._x))) {
if (this._y>(_root["fallingblock"+k]._y) && yspeed<0) {
yspeed *= -1;
} else {
if (this._y<(_root["fallingblock"+k]._y) && yspeed>0) {
yspeed *= -1;
} else {
xspeed *= -1;
}
}
} else {
if (this._x>(_root["fallingblock"+k]._x) && xspeed<0) {
xspeed *= -1;
} else {
if (this._x<(_root["fallingblock"+k]._x) && xspeed>0) {
xspeed *= -1;
} else {
yspeed *= -1;
}
}
}

Reply With Quote
  #2  
Old February 1st, 2004, 05:40 PM
Tann San Tann San is offline
Gotta get to the next screen..
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Nov 2003
Location: Legion of Dynamic Discord
Posts: 4,716 Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)Tann San User rank is Colonel (50000 - 60000 Reputation Level)  Folding Points: 11326 Folding Title: Novice Folder
Time spent in forums: 3 Weeks 1 Day 12 h 25 m 15 sec
Reputation Power: 580
Facebook MySpace
Hi, I think it's a speed problem. When it was slowed to 5 it happened almost all the time but when it's faster it works fine. Maybe the ball isnt clearing the square fast enough so when it appears to have contacted the bottom first it then touches the left hand side (for example) and shoots off left. It's a bit hard to explain but I hope you get what I mean. You could set a value on the ball or in the main movie which holds the name of the last object to touch the ball. Then when a contact is made check whether the current contact is the same as the last one. if thats the case dont do anything so it keeps on it's original trajectory.
__________________
-Tann

-Vote for your favorite ActionScript editor here.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignFlash Help > Ball bouncing off of a box


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT