Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Programming and Scripting
Help me fixing this vehicle script.

john123
Registered User
Quote
2023-09-24 02:35:11

So I asked ChatGPT to write a vehicle script for CopperCube to me, and it write this below :

---

// Define the vehicle object
var vehicle = {
speed: 0,
maxSpeed: 10,
acceleration: 0.2,
deceleration: 0.1,
steeringAngle: 0,
maxSteeringAngle: 30,
steerSpeed: 2,
isAccelerating: false,
isDecelerating: false,
isSteeringLeft: false,
isSteeringRight: false,
};

// Update function called every frame
function update(deltaTime) {
// Acceleration and deceleration logic
if (vehicle.isAccelerating) {
vehicle.speed += vehicle.acceleration * deltaTime;
if (vehicle.speed > vehicle.maxSpeed) {
vehicle.speed = vehicle.maxSpeed;
}
} else if (vehicle.isDecelerating) {
vehicle.speed -= vehicle.deceleration * deltaTime;
if (vehicle.speed < 0) {
vehicle.speed = 0;
}
}

// Steering logic
if (vehicle.isSteeringLeft) {
vehicle.steeringAngle -= vehicle.steerSpeed * deltaTime;
if (vehicle.steeringAngle < -vehicle.maxSteeringAngle) {
vehicle.steeringAngle = -vehicle.maxSteeringAngle;
}
} else if (vehicle.isSteeringRight) {
vehicle.steeringAngle += vehicle.steerSpeed * deltaTime;
if (vehicle.steeringAngle > vehicle.maxSteeringAngle) {
vehicle.steeringAngle = vehicle.maxSteeringAngle;
}
}

// Apply movement and rotation to the vehicle object
vehicle.moveForward(vehicle.speed * deltaTime);
vehicle.rotate(vehicle.steeringAngle * deltaTime);
}

// Function to move the vehicle forward
vehicle.moveForward = function(distance) {
// Implement your movement logic here
// Example: vehicle.position += vehicle.forwardDirection * distance;
};

// Function to rotate the vehicle
vehicle.rotate = function(angle) {
// Implement your rotation logic here
// Example: vehicle.rotation += angle;
};

// Function to handle input events
function handleInput(event) {
if (event.type === "keydown") {
if (event.key === "ArrowUp") {
vehicle.isAccelerating = true;
} else if (event.key === "ArrowDown") {
vehicle.isDecelerating = true;
} else if (event.key === "ArrowLeft") {
vehicle.isSteeringLeft = true;
} else if (event.key === "ArrowRight") {
vehicle.isSteeringRight = true;
}
} else if (event.type === "keyup") {
if (event.key === "ArrowUp") {
vehicle.isAccelerating = false;
} else if (event.key === "ArrowDown") {
vehicle.isDecelerating = false;
} else if (event.key === "ArrowLeft") {
vehicle.isSteeringLeft = false;
} else if (event.key === "ArrowRight") {
vehicle.isSteeringRight = false;
}
}
}

// Register the input event listener
window.addEventListener("keydown", handleInput);
window.addEventListener("keyup", handleInput);

---

So how I make this work, I already put the name of the file as behavior_simplevehicle.js but its something wrong, like no "behavior" inside the code, etc, I don't know nothing about coding.


okeoke
Registered User
Quote
2023-09-24 07:07:09

Hi John123,

There is nothing you can do to make it work.

Take a look into:https://www.codecademy.com/resou.... There is a section called "Break things down into building blocks", try to do for your task without any code. Then try to think how to make every step work using tools CopperCube provides.

Or you can look into using another tool like 3dRAD for example.


Guest
Guest
Quote
2023-09-24 08:47:08

@John123,

try this: http://make-everything-ok.com/


andgameplay
Registered User
Quote
2023-09-24 19:57:47

Hi, you don't need this script, you already have a vehicle script called SM car behavior and it's very good! Unless you don't mind the lack of advanced physics, this script will serve you well!

I'm sharing with you a ccb file with the script and working example:



https://drive.google.com/drive/f...


john123
Registered User
Quote
2023-09-25 04:57:29

SM Controller is better than the standard player script, but it is still problematic, but this is not limited to the script, but collision, regardless of the script used, is a problem in CC.


VP
Guest
Quote
2023-09-25 08:19:05

What specific problem are you experiencing with cars in coppercube?

Check Sven's Tank demo on Itch.io, the physics and mechanics are great - no major problems at all with vehicles on terrain... https://5v3n.itch.io/coppercube-....

If it's an inertia/momentum script (rather than a controller script), you're looking for. The one you've posted wouldn't fix that problem - you'd simply need to play around with the gravity/collision settings with the "physics simulation" (not bullet physics) in coppercube to add mass to your models, then combine it with the Tank demo and a controller of your choice.

As for centripetal forces of a car/vehicle, I've not seen an example of that in Coppercube yet, you can simulate that quite simply using the built-in A.i. and some visual coding (Same method as the "Point-mass" demo I uploaded to itch.io). I'll hopefully be adding the same inertia and centripetal force mechanics to my games with cars and helicopters - I'll upload a demo of it when it's done and explain how I achieved it, once I get it implemented. I'm busy working on the terrains, maps, buildings and textures for each Country at the moment.


luposian
Registered User
Quote
2023-09-25 20:56:04

wrote:
SM Controller is better than the standard player script, but it is still problematic, but this is not limited to the script, but collision, regardless of the script used, is a problem in CC.

I sense a contradiction...

You say you don't know how to program and don't WANT to learn, yet you claim that you KNOW something is wrong with CopperCube itself. How is that possible? You don't even know the first thing about how CopperCube functions... how could you? You don't program nor WANT to learn.

You can only KNOW there is a problem, specifically within CopperCube, when you understand the functions within CopperCube. And, in order to do that, you have to have SOME concept of programming, even on the smallest level, which you have clearly claimed you have no knowledge of nor desire to learn.

I have discovered, in more than a few instances, that what I didn't think CopperCube could do (or someone else has said likewise), someone else found a work-around that made the impossible... possible!

Don't blame the hammer for not hitting nails straight, when you don't know how to hold/use a hammer properly and don't want to learn how to.



john123
Registered User
Quote
2023-09-25 22:42:28

To VP : I'm using SM Car Controller, which is a little better than the default player controller script. I tested this Tank controller and really liked it, the movement is more realistic. I tested both in the same time with a tank, and it worked properly, but it would be better if you could unify SM Car Controller and Sven Tank Controller into just one script.

Anyway, you said that you also want to put helicopters in your game, see, I would like a script that has similar control and behavior to the N64 game Body Harvest, in it there are cars, tanks, planes, helicopters, boats, hovercraft and I think a submersible, and it has reasonable physics, similar to that Sven Tank Controller. Here is a video about it :

http://iteroni.com/watch?v=qiZkzbMJ3Ec

So what I want is that the physics, movement and behavior don't need to be completely realistic, just be like from this game called Body Harvest, but a multi vehicle type of controller, and for that it need to be better than the current ones from CC, for example, the reverse gear on the SM Car Controller doesn't work properly because you can't maneuver the vehicle, it doesn't have built-in sound, etc, I think, to be enough, need these things, in Unity, you could get the Realistic Car Controller, that came with everything, scripts, vehicle controller and sound, vehicles meshes, camera positions, all in a single prefab/asset for free and ready for action.


andgameplay
Registered User
Quote
2023-09-26 22:20:42

jhon 123, please, just be more polite and grateful here, you were ironic with me in another post and the group here on the forum is very proactive and helps a lot when you need it!

Stop blaming the engine for limitations, because you can do everything in it , but first you need to know it well. Otherwise, you can count on me for any help with your games and developing!


Create reply:


Posted by: (you are not logged in)


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