Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Sprites being pushy...

Author
Message
CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Oct 2011 14:18
Hi all,

So I'm playing with sprite collision and have a question regarding theory...

Lets say I have two sprites on the screen. Sprite A's movement is automated. It follows a wavy path across the screen. Round and around forever. Sprite B, however, is attached to a click-and-drag system with the mouse. If you move the mouse over it, then hold down the left mouse button, Sprite B follows after it as if being "carried" by the mouse.

Using sprite collision, what would be the best way to make it so that Sprite B gets "pushed" out of the way by Sprite A if it gets in the way while being carried by the mouse? I can get it happening if it's NOT being carried by the mouse, but the mouse seems to enjoy making things difficult.

Here's the code I'm working with (rough version)



Anyone have any ideas?

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 15th Oct 2011 16:26
Add this code somewhere in your loop:

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Oct 2011 16:55
Hi basjak,

That doesn't actually fix my problem.

1) It doesn't push the sprite correctly, it just moves it out of the way.

2) It is completely ignored when being dragged by the mouse, which is where my problem lies.

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 15th Oct 2011 17:26 Edited at: 15th Oct 2011 17:31
Usually Neuro Fuzzy is the one who provides the best answers for these mathematical problems; but here is a "simple man's" solution.

Its a generic system that use relative forces; and a visual with curved movement for smoothness. I use this kind of system in all of my projects because anything can have a position somewhere, be it a UI element, sprite or 3D object.

It needs work but with the right tweaks you should be able to get somewhere.

By using a PushPos() function, it pushes one position of the user defined type away from another.

For other situations;

The PullPos() does the opposite.

The ForcePos() causes the object follow the path of the object, however it moves.

The CurvePos() function smoothly animates movement and is actually used to cause a certain position to follow the mouse; and another to follow the follower; because sprite integer positions can get jerky.

The other functions speak for themselves.

The power# variables adjust the power of influence.

This code can be used in 3D with an additional Z property added for convinience.




Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 15th Oct 2011 17:29
Another note is to replace the IsNear() function with something similar to Distance(); it is down to what plugin preferences you have. And power should be relative to that distance so that it moves at the correct speed in the right direction.

CumQuaT
AGK Master
16
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 15th Oct 2011 17:39
Really good theory there, Chris. Taught me quite a bit, actually. I didn't end up using quite your method, but in the end I got it working Thank you for the help!

Malevolence: The Sword of Ahkranox
www.msoa-game.com
www.facebook.com/malevolencegame
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 15th Oct 2011 17:42

Login to post a reply

Server time is: 2026-07-11 04:44:03
Your offset time is: 2026-07-11 04:44:03