00:00
00:00
Newgrounds Background Image Theme

Almost-Ichabod just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Object hover loosely around another

394 Views | 7 Replies
New Topic Respond to this Topic

What I want is for objectA to be able to very loosely and organically hover above objectB. While objectB sits idle, objectA will just orbit right above objectB. Think of it like a halo effect. When objectB moves, objectA will move, but it will linger a little bit, float into position, and resume its usual pattern.

This could apply to all sorts of effects like Megaman's leaf shield, despite the fact that the shield just tightly followed him and I want something that can ease into and out of position.

I've yet to get into this sort of thing. If you have any ideas, I'd love to hear them.

Response to Object hover loosely around another 2014-09-12 09:34:37


And, sorry, I'm not even sure of the proper term for this concept. You could direct me to a reputable tutorial for this sort of thing.

AS3, naturally.

Response to Object hover loosely around another 2014-09-12 10:16:09


At 9/12/14 09:33 AM, Barzona wrote: I've yet to get into this sort of thing. If you have any ideas, I'd love to hear them.

An easy way to do this would be to just calculate the position for B if it moved on a fixed orbit around A.
Afterwards just move B towards this position you could give B a speed with which it moves or just always move it 1/10 (0 < value < 1) of the distance each timestep.

Response to Object hover loosely around another 2014-09-12 11:41:52


A tween library would help if you're looking for more than just a single simple ease effect, though if you just want a quick'n'dirty, try a simple "ease in" like this:

private function ease(obj:DisplayObject, newPos:Point, easing:Number = 10):void {
  obj.x += (newPos.x - obj.x) / easing;
  obj.y += (newPos.y - obj.y) / easing;
}

why does this work? Because of percentages. If you take 100 and divide it by two you get 50. Then once more you get 25, and so on. It is mathematically impossible to reduce 100 to 0 by division, the number just gets fractionally smaller depending on the numerator and denominator.

This effect is compounded by the fact that the numerator slowly decreases as well, with each time the function is called. Play around with the easing to figure out what you want.

If you want a more complex "ease in and out" (or more than one object that needs to be tweened in a more complex way) then I recommend either a lightweight tween library like TweenLite or some google-fu.


Programming stuffs (tutorials and extras)

PM me (instead of MintPaw) if you're confuzzled.

thank Skaren for the sig :P

BBS Signature

Response to Object hover loosely around another 2014-09-13 02:08:52


Thanks for the advice, guys. I've messed around with tween events before, but it's been awhile. I know there was some "rubberband" tween thing that was kind of cool, but maybe not what I need exactly.

Yeah, just moving it around like usual while also affecting it with some counter-variable might give that organic look I'm after.

Response to Object hover loosely around another 2014-09-13 16:24:33


At 9/13/14 02:08 AM, Barzona wrote: Yeah, just moving it around like usual while also affecting it with some counter-variable might give that organic look I'm after.

And use twice the processing power for something that can be done cheaply and simply?


Programming stuffs (tutorials and extras)

PM me (instead of MintPaw) if you're confuzzled.

thank Skaren for the sig :P

BBS Signature

Response to Object hover loosely around another 2014-09-13 16:46:05


At 9/13/14 04:24 PM, egg82 wrote:
At 9/13/14 02:08 AM, Barzona wrote: Yeah, just moving it around like usual while also affecting it with some counter-variable might give that organic look I'm after.
And use twice the processing power for something that can be done cheaply and simply?

I meant to be agreeing with your example.

Response to Object hover loosely around another 2014-09-13 17:24:21


At 9/13/14 04:46 PM, Barzona wrote: I meant to be agreeing with your example.

division isn't a counter-variable, it's part of the whole equation :P
I thought what you meant was add the x value and then later subtract some of it, which is a huge waste of processing power.


Programming stuffs (tutorials and extras)

PM me (instead of MintPaw) if you're confuzzled.

thank Skaren for the sig :P

BBS Signature