# Adding reflectionsto random object

**URL:** https://forum.kirupa.com/t/adding-reflectionsto-random-object/367
**Category:** Uncategorized
**Created:** [July 15, 2002, 4:57pm UTC](https://forum.kirupa.com/t/adding-reflectionsto-random-object/367 "2002-07-15T16:57:24Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![dizy](https://avatars.discourse-cdn.com/v4/letter/d/9dc877/32.png) [@dizy](https://forum.kirupa.com/u/dizy)
#### Post date: [July 15, 2002, 4:57pm UTC](https://forum.kirupa.com/t/adding-reflectionsto-random-object/367/1 "2002-07-15T16:57:24Z")

</div>

I found the random movement code somewhere, and tried making it work with an object and its reflection. Object moves fine, but since its reflection has the be mirrored in the y axis, it acts funny… it makes the reflection keep rising and rising very slowly untill it goes behind the object.

the problem is because of the “-” on a line marked with \*

see the movie at [http://babiy.net/reflect.html](http://babiy.net/reflect.html)  
it might not be obvious at first, but reflection VERY SLOWLY moves up and up untill it goes behind the bottle

code:

onClipEvent (load) {  
width = 5  
height = 5  
accelFactor = Math.ceil(Math.random()\*4) + 2;  
newX = Math.round(Math.random()\*width);  
newY = Math.round(Math.random()\*height);  
}

onClipEvent (enterFrame) {  
currentlocx = this.\_x;  
currentlocy = this.\_y;  
differencex = newX-currentlocx;  
differencey = newY-currentlocy;  
accelx = differencex/accelFactor;  
accely = differencey/accelFactor;  
this.\_x = this.\_x+accelx;  
this.\_y = this.\_y+accely;  
\_parent.reflect.\_x = \_parent.reflect.\_x+accelx;

- \_parent.reflect.\_y = \_parent.reflect.\_y-accely; \_parent.shade.\_x = \_parent.shade.\_x+accelx;  
if (Math.round(this.\_y) == Math.round(newY) && Math.round(this.\_x) == Math.round(newX)) {  
newX = Math.round(Math.random()\*width);  
newY = Math.round(Math.random()\*height);  
accelFactor = Math.ceil(Math.random()\*4) + 2;  
}  
}

How do I get around the problem ?  
TIA!
