tipforeveryone Posted January 21, 2018 Share Posted January 21, 2018 Hi, I want to make a small game in which playerObject can move and collect coins around it among stones (demonstrated in below images) when player moves to a point, press a key to make every coins within its aura radius be collected (sucked to) by player except stones and is there any way to get only the closest coin ? Those stones and coins are randomly generated and not moving any idea for this ? how to make it in lua? Thanks for helping Quote Link to comment Share on other sites More sharing options...
gamecreator Posted January 21, 2018 Share Posted January 21, 2018 Shouldn't be too bad using the GetDistance function to get the distance between the player and any coin and if the distance is within the desired radius, pull the coins to you. I would then use Point to point the coin to the player then Move it forward (toward the player). That way, you can keep the coin moving toward the player even if the player is moving (by pointing and moving every turn). Quote Link to comment Share on other sites More sharing options...
tipforeveryone Posted January 21, 2018 Author Share Posted January 21, 2018 I thought about GetDistance() before. yes, that is only one solution for this, and using entity:Point() for pulling coins to player is brilliant. But if there are multiple objects like player (may be a random enemy which wants to collect coins too then you must collect more coins than them to win) how can those coins use GetDistance() to all player like objects and only move toward the closest one? Quote Link to comment Share on other sites More sharing options...
Rick Posted January 22, 2018 Share Posted January 22, 2018 I would probably use a bounding box around each actor. You can get all coins that are within the box and tell them to move towards you. https://www.leadwerks.com/learn?page=API-Reference_Object_World_ForEachEntityInAABBDo Call this every so often in each Actors UpdateWorld() and for each coin entity that is in the bounding box tell it to move towards you. Maybe check that if it's already moving towards another actor to ignore moving towards another but maybe not, maybe that's part of the game. Each actor should have an AABB object and you define it by setting it's center point to be the players position in the UpdateWorld() so it moves, and give it a radius of however big you want. https://www.leadwerks.com/learn?page=API-Reference_Object_Math_AABB This will probably be faster than GetDistance() checks on all coins by all actors. 1 Quote Link to comment Share on other sites More sharing options...
AggrorJorn Posted January 22, 2018 Share Posted January 22, 2018 If your coins don't need to interact with physics once they are moving towards you and you don't want them to rotate towards the player you can move them like this: --UpdateWorld local velocity = (playerPos - coinPos):Normalize() * self.coinMoveSpeed * Time:GetSpeed() local newCoinPos = coinPos + velocity; coin:SetPosition(newCoinPos) 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.