How can I change the size of my shadow by using the distance from the floor?

vikingviking Member, PRO Posts: 322
Hey guys,

Can anyone please help me figure out a simple math problem...? I have a shadow under my ball and the shadow position X is constrained to the self.position.x of a ball in the scene. This works great as my ball bounces on the "floor" and the shadow is glued to the ball. Looks great! Then I wanted to add some more "realism" and added a size constraint to the shadow with the self.position.y. The idea was to make the shadow object that is constrained to the position under my ball smaller when the ball is further from the ground and bigger when it gets closer to the ground.

However, since the Y coordinates are increasing the higher it is from zero, my shadow is getting bigger -- not smaller -- when the ball is high in the air and shrinks down to the correct size when the ball hits the floor in my scene.

Any suggestions as to how I can use the increasing Y attribute to make my shadow smaller rather than bigger?

Pretty sure there is a super-simple duh math solution that I am not thinking of...

Thanks!

-E

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited November 2012

    Sorry, misread... back soon!
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    Here is one way to do it --
    make three game-level attributes: heroWidth, heroY, and heroOriginalY

    in the hero actor:
    Change Attribute: game.heroOriginalY To: self.Position.Y
    Constrain Attribute: game.heroWidth To: self.Size.Width
    Constrain Attribute: game.heroY To self.Position.Y

    Then in the shadow actor
    Constrain Attribute self.Size.Width To: game.heroWidth-((game.heroY- game.heroOriginalY ))/5
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited November 2012
    Hi @viking, back again with another way, as I've now been beaten to it by @RThurman!
    :-)

    I hope the following test is useful to you as it assumes the ball is moving to and from fixed positions only on the y-axis, (i.e wouldn't take into account random changes of direction) – although it'll still work if the ball is moving anyway along the x-axis.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @gyroscope -- That is one sweet demo! (I think I'll be keeping that one. hee...hee...)
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598


    @RThurman, why thank you RT, glad you like it!

    I'm just about to update the zip file and upload a newer version (in about a minute), as I forgot to use ease in and out on the ball; done now and look more realistic bouncing of course. :-)
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited November 2012

    Edit: I can't seem to delete the zip file above for some reason, so here it is again, updated (using ease in/out in Interpolate and cleaned up redundant attributes):
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,881
    @gyroscope -- yup! I'll be appropriating that one as well. Very nice!
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited November 2012

    @RThurman Thanks again :-) I have noticed though that the shadow gets bigger slowly over time.... it'll need the shadow minimum and maximum widths reset on the boolean, as you know.... ah well, bit late here, time for sleep, maybe I'll sort that tomorrow.... goodnight!
  • vikingviking Member, PRO Posts: 322
    @RThurman and @gyroscope Thanks guys. I tried both of these approaches and while they give me most of what I need the solutions don't work for all my scenarios. I tried a simpler solution and this is what worked for me.

    I needed a number that was decreasing in size perfectly with the increase in size of the y coordinates of my ball. I found that the highest point of my ball arc was around 900 so I did the following: I constrained the self.size.width of my shadow actor to 900 minus my ball y attribute and divided the number by 20, which game me a shadow that became smaller when the ball goes high up in the air and goes back to normal size when the ball lands on the ground. Maybe this is a bit of a hack, but it gives me a very accurate shadow. Thanks again for the help :)
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited November 2012

    Hi @viking , glad it worked for you; pleased also we pointed you in the right direction and you worked it out. :-) (It's interesting to me the amount of ways to solve the same problem sometimes...)
Sign In or Register to comment.