Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
this is a mowing game and i can't get the grass to delete when the "blades" go over that scene node can anybody help? thankshttps://1drv.ms/u/s!AiaHd2kpdCny... |
||||
|
I've added another extension called Mower. Basically, it checks distance to every node put into grassFolder. It checks the distance from the node it's attached to so please reattach it to knives node if required. grassMowedCheckDistance - is distance from the node to grass patch there grass is considered "cut" action - is action on cut, so you can add sound or any other logic that happens on cut like incrementing variables or play sound there. // The following embedded xml is for the editor and describes how the behavior can be edited: Updated file https://drive.google.com/file/d/... |
||||
|
thankyou so much it works great, I had tried to make this game over a year ago and could never get that system to work you've helped me allot |
||||
|
Is there any way you know of to make the performance better? Even when I use billboards for grass the frame rate is very bad Thanks |
||||
|
Divide the whole map into small squares, identify in which square the mower is located, and only do distance check for the grass nodes inside that square. |
||||
|
@paperbag Just do it like I did in this example: https://files.catbox.moe/wci1qd.... I added a function to make some grass patches, too. You can paste the code from the JS file into an Execute JS action in the Before First Draw behavior to get rid of the extra file. I commented the code to make it more explanatory. About the performance issue: it's inadvisable to run loops inside of frame events. Loops in loops is amateurish code. Pre-calculate lists in the load instead. |
||||
|
hey man, I really appreciate that thankyou |
||||
|
I had some time to experiment with the approach I mentioned. I.e. to divide the whole field into the smaller squares and only check node inside that squares. So, I have 150x150 field, that is divided into 2500 little squares. Each square is represented by its own node, which is a clone of a base field node. Each of the copied nodes has 3 children billboard grass patches. Which means there are 7500 grass patches in total. I use a 2d array implementation which is basically a "flat" 2d array: function Array2d(rows, cols) {This allows me to store data for all 2500 squares in a 1d array, but still be able to get any of its elements by x and y indexes, like in a normal 2d array. It's also super easy to find the square there the mower currently is, by simply flooring it's x and z position divided by the square node size. I also need to substract initial field position since it can be not at 0, 0 (which is in my case -75, -75): var xi = Math.floor((px - fieldPos.x) / nodeSize); I actually have to check up to 9 squares. The one there mower is and 8 around it, so: function findNodesToCheck(px, py) {The last thing is to get this 0 to 9 squares, and distance check to every child of them using a juicy nested loop: var pos = ccbGetSceneNodeProperty(this.mower, 'Position'); Using that approach I'm able to get almost stable 60 fps, with some spikes for 7500 grass patches, which seems good enough for me:) demo project: https://drive.google.com/file/d/... |
||||
|
I really appreciate you guys putting your time into it, is it scalable and if it is how would I do it? like can I make unusually shaped lawns? And just in general how do I scale it and customize it, I'm not to good with code thankyou |
||||
|
The demo I made is just a way of how you check for collision. If you need a more complex shape, you can either create a field manually, or write a generator that will spawn the vegetation inside a polygon shape. Then create square "field", which completely covers the polygon shape even if some parts of it do not have grass at all. Unfortunately, I don't think this could be done without coding. I also believe, that in general in games like lawnmower simulator and similar, they somehow utilize shaders in order to get that effect, not 3d models or billboards. |
||||
|
|