Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Announcements and Showcase
Path finding in Coppercube

just_in_case
Moderator
Quote
2019-12-13 08:23:17

Here is a video showing basic path finding system in which the player will ignore the obstacles in his way and change its direction and then reach to the final position....

This implementable is not accurate it won't calculate the shortest distance but it works pretty good.... Currently this works for 2D Games i didn't yet tried it with 3D objects. it might work for the 3D object as well.

it might look in the video that the Villager is walking over the house but actually/technically he was walking behind the house not over the house the path finding system works correctly so far.

hope you guys will like it.

here is the link to the video showing path finding in my small version of age of empire clone which is still a work in progress.contains line of sight, collision detection, building creation,player locomotion and path finding all in
complete
2D.


https://www.youtube.com/watch?v=...


niko
Moderator
Quote
2019-12-13 08:28:48

There must be something wrong, you've clearly linked a video of Age of Empires, not CopperCube.


astronomical
Registered User
Quote
2019-12-13 08:34:03

This is very cool. Thank you for sharing


crusly
Registered User
Quote
2019-12-13 23:30:10

Wow... you made a great job for that, looks it works amazing...


Robo
Guest
Quote
2019-12-15 08:03:11

very nice !

any code you can share that might help us noobs ?


srfstudio
Registered User
Quote
2019-12-15 13:56:20

Wow this is great! I think that pathfinding is a big, BIG, problem when it comes to CC usage.
Is movement based on grid or is free-moving posibble? I suppose entities are 'marked' as non-passable with some data in what direction to avoid them?


Robo
Guest
Quote
2019-12-17 00:33:33

I thought to implement something a few months back using the melee enemy AI extension.

My idea is to record and save the length or distance between the player and enemy if that distance remains the same for maybe 2-5 repetitions then move the enemy either left or right and keep checking the distance again... This way the enemy should be moving around obstacles unless hits a wall then maybe have it move back the other way....


just_in_case
Moderator
Quote
2019-12-17 10:38:52

what I did was compared the target position's direction and made 4 points around the object of collision. if the target position's x axis is greater than the x axis position of the colliding object then make a new target position then move to that target position then on reaching new target position set old target position as the main target position. This can also be done with the 3d objects too. But this is not ideal path finding but a workaround which might help.

the whole block of code looks like this.


// check collision and path finding
// For GoldMine
this.unit_pos = ccbGetSceneNodeProperty(node, "Position"); //get player pos
var goldmine = this.goldmineFolder; // folder in which the colliding object reside
var goldminecount = ccbGetSceneNodeChildCount(goldmine); // number of colliding objects in the folder

//looping through all the colliding objects in the folder

for(var goldminei=0; goldminei<goldminecount; ++goldminei)
{
var goldminechild = ccbGetChildSceneNode(goldmine, goldminei);
var child_name = ccbGetSceneNodeProperty(goldminechild, "Name");
var goldminepos = ccbGetSceneNodeProperty(goldminechild, "Position");
ccbSetSceneNodeProperty(goldminechild,"Scale",88,0,54); //this is optional my game uses planesmesh with initial scale of 1 and then scale it accordingly to the object during gameplay.

// collision if player collides from left of the colliding object. Numbers subtracting and adding to the colliding objects position vary for each object according to the size/scale of the object.
if (this.unit_pos.x > goldminepos.x-45 && this.unit_pos.x < goldminepos.x-43 && this.unit_pos.z > goldminepos.z-15 && this.unit_pos.z < goldminepos.z+25 )
{
if (this.Old_TargetPosition.x > goldminepos.x && this.Old_TargetPosition.z > goldminepos.z);//if target position is higher on the z axis than the collding object
this.TargetPosition= new vector3d(goldminepos.x,this.TargetPosition.y,goldminepos.z+35);//sets new target position
if (this.Old_TargetPosition.x > goldminepos.x && this.Old_TargetPosition.z < goldminepos.z);//if target position is lower on the z axis than the collding object
this.TargetPosition= new vector3d(goldminepos.x,this.TargetPosition.y,goldminepos.z-25);//sets new target position
}
// collision if player collides from right of the colliding object.
if (this.unit_pos.x < goldminepos.x+40 && this.unit_pos.x > goldminepos.x+38 && this.unit_pos.z > goldminepos.z-15 && this.unit_pos.z < goldminepos.z+25 )
{ if (this.Old_TargetPosition.x < goldminepos.x && this.Old_TargetPosition.z > goldminepos.z);
this.TargetPosition= new vector3d(goldminepos.x,this.TargetPosition.y,goldminepos.z+35);
if (this.Old_TargetPosition.x < goldminepos.x && this.Old_TargetPosition.z < goldminepos.z);
this.TargetPosition= new vector3d(goldminepos.x,this.TargetPosition.y,goldminepos.z-25);
}
// collision if player collides from upside of the colliding object.
if (this.unit_pos.x > goldminepos.x-45 && this.unit_pos.x < goldminepos.x+40 && this.unit_pos.z > goldminepos.z-15 && this.unit_pos.z < goldminepos.z-13 )
{ if (this.Old_TargetPosition.x > goldminepos.x && this.Old_TargetPosition.z > goldminepos.z)//if target position is higher on the X axis than the collding object
this.TargetPosition= new vector3d(goldminepos.x+50,this.TargetPosition.y,goldminepos.z);//sets new target position
if (this.Old_TargetPosition.x < goldminepos.x && this.Old_TargetPosition.z > goldminepos.z);//if target position is lower on the X axis than the collding object
this.TargetPosition= new vector3d(goldminepos.x-55,this.TargetPosition.y,goldminepos.z);//sets new target position
}


code continues below


just_in_case
Moderator
Quote
2019-12-17 10:49:00


// collision if player collides from downside of the colliding object.
if (this.unit_pos.x > goldminepos.x-45 && this.unit_pos.x < goldminepos.x+40 && this.unit_pos.z < goldminepos.z+50 && this.unit_pos.z > goldminepos.z+48 )
{ if (this.Old_TargetPosition.x > goldminepos.x && this.Old_TargetPosition.z < goldminepos.z)
this.TargetPosition= new vector3d(goldminepos.x+50,this.TargetPosition.y,goldminepos.z);
if (this.Old_TargetPosition.x < goldminepos.x && this.Old_TargetPosition.z < goldminepos.z)
this.TargetPosition= new vector3d(goldminepos.x-55,this.TargetPosition.y,goldminepos.z);
}
}

/if not reached to initial target position then move to initial target position when reached to new target position
if ( !this.bMovingForward && this.TargetPosition != this.Old_TargetPosition)
this.TargetPosition= this.Old_TargetPosition;


Note:- This uses values from behavior move object by position click and from my project. this is not actual path finding but it mimics path finding and works for spaced object this won't work if you want to make objects placed closed to each other there must be gap between them. hope soemeone will find this useful.
I know that the code can be of just one line but i wanted to check the direction thats why i have to make it longer. if you want you can use
ccbGetCollisionPointOfWorldWithLine or
ccbDoesLineCollideWithBoundingBoxOfSceneNode


Thank You for your valuable respones


srfstudio
Registered User
Quote
2019-12-21 18:53:42

Damn, that's good problem-solving skill, never even occurred to me that I can place four references around the object of collision to enable a choice for colliding node :/ I seem to be stupider than I thought :)
Cheers for giving me an excellent thinking-material!


raulc96
Registered User
Quote
2019-12-24 11:34:24

This system need to Traffic System.


creaturefreak
Registered User
Quote
2019-12-28 08:22:07

Excellent! coding just_in_case

Your skills as a coder and a contributor to the community is fantastic! thank you for sharing.

I tried to mimic your results in 3d by using your code but failed.
I kept getting a

"this.Old_TargetPosition is undefined" in the Debug window.

I know your very busy and we appreciate all your help and contribution. If you have a little time to view the ccb file below , perhaps you can tell me where I went wrong, I would be very grateful.
I am using the "Move 3d object by click" behavior and running your code every 3 MS on the "man" 's Behaviour.

No rush my friend, again when and if you have time .

kind regards,

https://drive.google.com/open?id...


just_in_case
Moderator
Quote
2019-12-28 11:31:45

First of all am not a good coder or programmer at all. Am just good with logic's....

second yes am a quite busy due to health related problems. I love being here on the forums and i've read almost every single post since 2015, and some older posts too. In the beginning I was so curious about this engine and so eager to learn and help people out there on the forums. During that period the forum was filled with my posts everywhere, i used to reply every post.

But then there are some questions which were repeatedly asked by some newcomers which i'had already answered and then i started to reply to those post which were something new to me. And something which has not been answered on the forums Already.

But i Stilled continued Using Coppercube Then one day i thought of creating a website for this game engine and that https://Neophyte.cf was created.

I uploaded Tutorials there , Some Cool demos to play around with.
And after that i found that Developer lost some interest in this Cool piece of software and so am I. Then he made it free and released it with new features and with a complete new UI. and since then i saw a lot of new comers coming here asking this and that and there was no reply to these posts because they were asking same question which many of us had already answered so many times.

and now i ignore new posts too. Maybe because am too lazy to reply or maybe my expectations with this engine is too much that i have tried and failed more than 200 projects
and started with a new project with anew hope but at some point or another every-time there happens something and i drop the project. Same has been with this age of empire clone am thinking of dropping it. there is nothing wrong with this project but it took too much time creating this into a complete playable demo. Either i need a team or i should accept the fact that you need to be a good programmer to create a sucessfull game.

In Short here is the work done on this RTS Clone here. I have Removed sprites from the data folder and left it with the sprites which my project uses...
It loads assets dynamically and you can also create more than 8 Directional unit maybe like the new definitve edition which uses 32 direction instead of the 8 direction. And yes it is possible to succefully create a 2 Dimensional HD or definitve edition version of the game with coppercube. If you guys are intrested in this project and want me to complete it then plzz let me know i dropped the project because its too time consuming. Villagers are really hard coded.... The behvior is not commented very well but you will get the idea.


https://drive.google.com/file/d/...

For any further info you can ask me. And sorry for making this post so boring and long.


creaturefreak
Registered User
Quote
2019-12-28 13:39:38

Thank you Just_in_case,

For the response! and wow thank you for uploading the project. I completely understand how sometimes it can be hard to answer all questions..that are repetitive.
I remember you helping me out with the shooting Turret sometime ago moving it around with the mouse. I will look through the files you kindly have posted and will see how it works. I will post some videos soon of some of the coppercube tests with pathfinding I have done.

best,

CF


Robo
Guest
Quote
2019-12-29 10:56:59

The above code looks very promising but instead I tried to program some logic into an enemy AI myself - and after a lot of trying got it to go around corners now and find the player even if hid behind an object. It was very hard for me though...will post a video of it soon...


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internati?nal" (you are not logged in)


Text:

 

  

Possible Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   






Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact