Math question

vikingviking Member, PRO Posts: 322

I have been banging my head against the wall trying to solve a seemingly simple math problem. Hopefully someone out there can help me with this...

When my ball actor is 800 pixels away from the target I need the power attribute that will drive the speed using the change velocity behavior of the ball actor towards the target to be around 720 so that the ball actor will roll all the way over to the target or even just past it. (in other words the power has to be less than the distance). So far so good...

However, when the ball actor is only 100 pixels away from the target, the power attribute has to be more than 180 to reach the target, which means that the speed attribute in change velocity is not linear. Therefore I can't use the distance from target to drive the power since the ball will stop way short of the target. The power needed to reach the target when the ball actor is close is relatively much greater than amount needed when the ball actor is far away from the target.

The perfect solution for me would be to have the ball actor always reach the target by measuring the distance and then adjusting the speed needed in the change velocity behavior to just reach the target each time.

Any ideas?

Best Answer

  • SocksSocks London, UK.Posts: 12,822
    Accepted Answer

    Very confusing question ! For example, does this paragraph . . . .

    "When my ball actor is 800 pixels away from the target I need the power attribute that will drive the speed using the change velocity behavior of the ball actor towards the target to be around 720 so that the ball actor will roll all the way over to the target or even just past it. (in other words the power has to be less than the distance). So far so good..."

    . . . . simply mean . . .

    'When the actor is 800 pixels away from the target I need its velocity to be around 720 (moving towards the target) . . .

    ?

    Same deal with the rest of the question, it seems a bit confused (to me at least), if I am able to hack through the dense undergrowth you seem to be asking . . .

    I have a value that wants to be around 720 when the input is 800 and around 180 when the input is 100, anyone know what calculation will do this ?

    If this is sorta' what you are asking, then try this:

    ((Distance * 0.77142857142857) + 102.857142857143)

    This will give you 720 for an input of 800 and 180 for an input of 100.

    P.S. " . . . which means that the speed attribute in change velocity is not linear. . . "

    It is still linear.

Answers

  • UtopianGamesUtopianGames Member Posts: 5,692

    Not sure i completely understand but can't you do a change velocity to distance*2 then it won't stop short?

    Darren.

  • vikingviking Member, PRO Posts: 322

    Thanks for the suggestion Darren, but I can't make it work that way because even though distance2 gives me the power I need to move the ball to the target from a short distance, the distance2 makes the power to move the ball way exponentially stronger as the distance increases. It means that the ball will have enough power to move further and further past the target the longer the distance is when the change velocity is executed.

    Hope that is clear. Not sure I explained it well...

  • vikingviking Member, PRO Posts: 322

    Socks! You the man --- again :)

    Thank you for digging through the mess of my post to find a solution. If I multiply my distance by 0.77 and add 196 I do indeed get the perfect distance every time. (The ball is stopping just past the target) I appreciate the help.

Sign In or Register to comment.