ambiera logo

Ambiera Forum

Discussions, Help and Support.

folder icon Ambiera Forum > CopperCube > CopperCube Open discussion
forum topic indicator Using AI for scripting
person icon
chicoporter
Registered User
Quote
2023-06-10 22:01:56

I did this for fun and haven't even gotten around to trying it out. I simply asked chatgpt to write a script that would allow a follower/companion. Again, I haven't even played around with it. Would it even work?
Here's what it spat out.

GENERATED BY CHATGPT
To create a script that allows an allied NPC to follow, interact, and help the player, you can use JavaScript in your CopperCube extension. Here's a step-by-step guide on how to implement this functionality:

// Get references to the player and NPC objects in the scene
var player = scene.getObjectByName("PlayerObjectName");
var npc = scene.getObjectByName("NPCObjectName");

// Set the following distance and movement speed for the NPC
var followDistance = 5;
var movementSpeed = 2;

// Register the update event to control the NPC's behavior
scene.OnAnimate = function() {
// Calculate the distance between the player and NPC
var distanceToPlayer = player.getPosition().getDistanceFrom(npc.getPosition());

// Check if the NPC is too far from the player
if (distanceToPlayer > followDistance) {
// Move the NPC towards the player
var direction = player.getPosition().substract(npc.getPosition()).normalize();
var moveVector = direction.multiplyWithScal(movementSpeed);
npc.addToPosition(moveVector);
}

// Add additional logic as needed for NPC interactions and helping the player
// For example, triggering specific animations, attacking enemies, etc.
};

// Add additional logic to handle NPC interactions and helping the player
// For example, detecting specific triggers, attacking enemies, etc.


In this example, we assume that you have already defined the player object and the NPC object in your CopperCube scene and provided names for them (replace "PlayerObjectName" and "NPCObjectName" with the actual names you assigned to the objects).

The code sets the desired distance for the NPC to follow the player (followDistance) and the movement speed for the NPC (movementSpeed).

Inside the OnAnimate event handler, the code calculates the distance between the player and the NPC using the getDistanceFrom method. If the distance is greater than the specified follow distance, it moves the NPC towards the player by calculating the direction vector between them and applying movement to the NPC using the addToPosition method.

You can add additional logic inside the OnAnimate event handler and elsewhere in the code to handle NPC interactions and helping the player. For example, you can detect triggers, attack enemies, play specific animations, or trigger other actions based on certain conditions.

Remember to save the extension code file, build the extension, and import it into your CopperCube project. Test the NPC behavior to ensure it follows, interacts, and helps the player as expected, and make any necessary iterations or adjustments to the code.

person icon
chicoporter
Registered User
Quote
2023-06-10 22:09:08

I'm mainly playing with it, not as a short cut but a tool for non coders. I fully understand the script would need tweaking. I really hope the resident coding geniuses (too many to name and you know who you are :) ) have some input

person icon
Guest
Guest
Quote
2023-06-11 02:23:23

Funny part is by the time a "non-coder" learns to "tweak" that code he will effectively be a programmer. Here's the code translated to CC. It's not a 1-for-1 translation as I didn't feel like doing a bunch of encapsulation because frankly I hate OOP. Maybe you or someone else can learn something from it. Enjoy.

https://files.catbox.moe/nur176....

person icon
chicoporter
Registered User
Quote
2023-06-11 15:52:46

that's pretty cool.

person icon
hanicraft
Registered User
Quote
2023-06-22 17:46:32

you should train the chatgpt by fully sending api refrence and a few written script so he can learn and give you coppercube js api code

person icon
Idontwannasignin
Guest
Quote
2023-06-26 07:39:16

What exactly did you tell chat Gpt to get it to spit out code that works? Every time I’ve asked it doesn't

And yeah It would be cool if somebody trained chat GPT to work with Coppercube They did it with unity

person icon
hanicraft
Registered User
Quote
2023-06-27 06:31:39

Idontwannasignin wrote:
What exactly did you tell chat Gpt to get it to spit out code that works? Every time I’ve asked it doesn't

And yeah It would be cool if somebody trained chat GPT to work with Coppercube They did it with unity

just copy the api refrence with all function names and tell chatgpt to learn it
then send chatgpt a few code example so he can get general knowledge of what a script looks like

person icon
Idontwannasignin
Guest
Quote
2023-06-27 20:10:24

I did And I still couldn't ever get it to work

person icon
Guest
Guest
Quote
2023-06-27 21:21:20

@Idontwannasignin
You do realize I translated the code in OP's post to work inside CC, right?

person icon
Idontwannasignin
Guest
Quote
2023-06-28 02:48:02

what? I'm just saying I can't get it to work

person icon
Guest
Guest
Quote
2023-06-28 03:45:10

Of course you can't because you don't understand programming. Learn to code and then play with AI. Or you can just keep asking it questions and maybe eventually one of the results you copy and paste will work. Good luck.

person icon
Idontwannasignin
Guest
Quote
2023-06-28 05:38:03

I know lua I'm still working out the kinks with JavaScript and coppercube API I just didn't understand what you said

person icon
Guest
Guest
Quote
2023-06-28 06:26:17

Sure you do. Good luck.

person icon
Idontwannasignin
Guest
Quote
2023-06-28 14:36:05

why are you trying to hate on me so hard

person icon
chicoporter
Registered User
Quote
2023-06-28 21:37:01

I'm still playing around with it. I'm still trying to train in. Now it spits out stuff like this:

/* <behavior jsname="behavior_SpaceshipController" description="Spaceship Controller">
<property name="RollSpeed" type="float" default="0.2" />
<property name="BankingSpeed" type="float" default="0.2" />
<property name="MovementSpeed" type="float" default="5" />
<property name="MaxSpeed" type="float" default="10" />
<property name="MinSpeed" type="float" default="0" />
<property name="MouseSensitivity" type="float" default="0.1" />
<property name="SpeedIncrement" type="float" default="1" />
<property name="SpeedDecrement" type="float" default="1" />
</behavior> */

// Behavior: SpaceshipController
// Description: Controls the movement of a spaceship using mouse and keyboard

// Properties
behavior_SpaceshipController = function() {
this.RollSpeed = 0.2;
this.BankingSpeed = 0.2;
this.MovementSpeed = 5;
this.MaxSpeed = 10;
this.MinSpeed = 0;
this.MouseSensitivity = 0.1;
this.SpeedIncrement = 1;
this.SpeedDecrement = 1;
this.CurrentSpeed = 0;
};

// Called when the behavior is added to a node
behavior_SpaceshipController.prototype. = function(node) {
this.CurrentSpeed = 0;
};

// Called every frame
behavior_SpaceshipController.prototype.onAnimate = function(node, timeMs) {
// Get current position and rotation
var pos = ccbGetSceneNodeProperty(node, "Position");
var rot = ccbGetSceneNodeProperty(node, "Rotation");

// Get mouse input
var mouseDelta = ccbGetMouseDelta();

// Mouse pitch and yaw control
rot.x += mouseDelta.y * this.MouseSensitivity;
rot.y += mouseDelta.x * this.MouseSensitivity;

// Keyboard controls
var keyState = ccbGetKeyState();

// Bank left control
if (keyState[65]) { // A key
rot.z += this.BankingSpeed;
}

// Bank right control
if (keyState[68]) { // D key
rot.z -= this.BankingSpeed;
}

// Speed control
if (keyState[87]) { // W key
this.CurrentSpeed += this.SpeedIncrement;
if (this.CurrentSpeed > this.MaxSpeed) {
this.CurrentSpeed = this.MaxSpeed;
}
}
if (keyState[83]) { // S key
this.CurrentSpeed -= this.SpeedDecrement;
if (this.CurrentSpeed < this.MinSpeed) {
this.CurrentSpeed = this.MinSpeed;
}
}

// Update position based on current speed
var forwardVector = new ccbVector3D(0, 0, -1);
forwardVector.rotateY(rot.y);
forwardVector.normalize();
forwardVector.multiply(this.CurrentSpeed);
pos.add(forwardVector);

// Update position and rotation
ccbSetSceneNodeProperty(node, "Position", pos);
ccbSetSceneNodeProperty(node, "Rotation", rot);
};

// Create instance of SpaceshipController behavior
var spaceshipController = new behavior_SpaceshipController();

// Add behavior to the spaceship node
ccbAddBehavior(player, spaceshipController);

In the provided code snippet, you'll need to replace `player` with the actual reference to your spaceship node in CopperCube.

For example, if your spaceship node has the name "mySpaceship", you should replace `player` with `"mySpaceship"` in the line `ccbAddBehavior(player, spaceshipController);`.

Additionally, you may need to adjust the property values in the behavior's header code (`behavior_SpaceshipController`) to suit your specific needs.



It still doesn't work.


Create reply:










 

  

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


icon_holyicon_cryicon_devilicon_lookicon_grinicon_kissicon_monkeyicon_hmpf
icon_sadicon_happyicon_smileicon_uhicon_blink   






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