Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Help with CopperCube
An Object follows Player

behroz-khan
Registered User
Quote
2017-10-20 08:20:23

How can I make objects follow player? Like our army follows us when we press a key?


niko
Moderator
Quote
2017-10-23 07:57:21

Yes, you can use the AI command for this. Use the javascript function ccbAICommand(), and I guess there is also a downloadable action plugin for this available.


behroz-khan
Registered User
Quote
2017-10-25 13:16:02

Where to download or what is the script?


behroz-khan
Registered User
Quote
2017-10-27 07:47:57

Yeah I already downloaded that. It's melee attack behavior.
I need:
Following behavior. For better understanding i am creating friend soldier so when we press 1st key they start following us and when we 2nd key they stop following.

Now understood?


behroz-khan
Registered User
Quote
2017-10-27 07:51:33

@niko wrote:

Yes, you can use the AI command for this. Use the javascript function ccbAICommand(), and I guess there is also a downloadable action plugin for this available.

I searched it found about moveto. But the problem is parameter is vector3D
can it be anotherNode? By creating var in that script?


wild-master
Registered User
Quote
2017-10-27 20:56:13

Hello, behroz-khan!

I created an example for you to show you how to make a character follow a different character!

Download it here:
https://drive.google.com/file/d/...

When you open that CCB file with CopperCube, please press the "Publish" tab at the top, and then press the button shaped like a "Play" arrow to test the sample.

When the game starts, you can do this:
1. The cube named "Hero" can be moved with the arrow keys.
2. If you press the Z button, the cube named "Friend" will follow the other cube.
3. If you press the X button, the cube named "Friend" will stop following the Hero.

Study the file to discover how I did that.


behroz-khan
Registered User
Quote
2017-10-29 13:07:04

Thank you very much!

I understood the script. I was really close I was doing one mistake.

Without you I was unable to do that.
The name of the file a futuristic person behroz-khan
Futuristic person? haha


nk
Guest
Quote
2020-04-03 12:28:15

FROM WHERE I DOWNLOAD THE SCRIPT TO OBJECT FOLLOW THE PLAYER


count2rfeit
Registered User
Quote
2020-04-03 16:05:06

He didn't make a script... but he uploaded a .ccb file to show what he did. Uses "Z" and "X" key to follow a cube named 'Hero'


kartik
Guest
Quote
2023-08-10 12:28:43

how do i make a zombie follow me


Dieter
Guest
Quote
2023-08-21 01:03:49

Really depends on how perfect it must be. Most simple is to just move him a bit towards you every frame or so.

State of the art would be an A* pathfinding algorithm, that you implement in a behavior.

As a start, I'd suggest to add a behavior to the zombie: in proximity (to active camera) do something, when enter proximity, start a inFrame task, and on leaving proximity you'd unregister the task

//------ this

function onFrameTask()
{
me=ccbGetActiveCamera();
zombie=ccbGetSceneNodeFromName("zombie1");
// point zombie towards player
me_pos=ccbGetSceneNodeProperty(me,"Position");
zombie_pos=ccbGetSceneNodeProperty(zombie,"Position");
ang=Math.atan2(me_pos.x - zombie_pos.x, me_pos.z - zombie_pos.z)*57.29577951;
rot=ccbGetSceneNodeProperty(zombie,"Rotation");
rot.y=ang;
ccbSetSceneNodeProperty(zombie,"Rotation",rot.x,rot.y,rot.z);
// move him towards player
zombie_pos.x+=(Math.sin(ang)* 0.3); // 0.3 be the walking speed
zombie_pos.z+=(Math.cos(ang)* 0.3);
ccbSetSceneNodeProperty(zombie,"Position",zombie_pos);
}

ccbRegisterOnFrameEvent(onFrameTask); // this activates the zombie task

And in the "leave radius" proximity behavior you would then simply:

// ccbUnregisterOnFrameEvent(onFrameTask);  

In the whole atan2 stuff you may have to switch some things by 180 degrees, until it works.


fntstcfreddy
Registered User
Quote
2023-09-01 07:51:05

link doesn't work


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internatio?al" (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