 lucas007 Registered User |
Quote
|
2024-12-12 14:39:31 |
|
Hi everyone.
I made a simple Nim Game on CopperCube. If you don't know how to play there is the rule on the link. It's a simple 2 player game.
If you have comment or suggestion, you can tell me.

the itch link:
https://turtlehorizon.itch.io/ma...
|
 Monks Guest |
Quote
|
2024-12-12 18:20:16 |
|
Hey lucas, it's been a while how have you been doing
|
 lucas007 Registered User |
Quote
|
2024-12-13 20:05:14 |
|
Hey Monks, I'm fine.
It's been a long time I don't use coppercube cause of studies.
So I don't know what's news on coppercube.
I have a question, there is another command to control the physique of an scene than ccbSetPhysicsVelocity .
Because I want to use physique on my game Path of Cube but I don't know how to get the velocity or something like this.
As a reminder here is Path of Cube https://turtlehorizon.itch.io/pa...
|
 sam_grady Registered User |
Quote
|
2024-12-14 10:12:55 |
|
I have a question, there is another command to control the physique of an scene than
ccbSetPhysicsVelocity
.
Because I want to use physique on my game Path of Cube but I don't know how to get the velocity or something like this.
Hi, if I understand correctly, you need to move an object to which physics is applied?
In that case, CopperCube has a function called ccbSetPhysicsVelocity, which works perfectly for moving objects using physics. Unfortunately, rotating physics-applied objects is not possible. Below is a simple example of code for moving a node:
function move(node, speed, x, y, z) { // Create a new vector representing the direction of movement. // The vector is initialized with the specified x, y, z values, // which determine the direction in which the object will move. let direction = new vector3d(x, y, z); // Normalizing ensures the vector has a length of 1 (unit vector), // which makes it independent of its initial magnitude. direction.normalize(); // Scale the normalized direction vector by the given speed. // This adjusts the length of the vector to match the desired movement speed. direction.x *= speed; direction.y *= speed; direction.z *= speed; // Set the velocity of the physics-enabled node using CopperCube's function. // `node`: The target node to apply velocity to. This node must have a // behavior "Object moved by physics engine." // Note: This function works only if physics simulation is enabled and available // for the platform where the application is running. ccbSetPhysicsVelocity(node, direction.x, direction.y, direction.z); }
|
 sam_grady Registered User |
Quote
|
2024-12-14 10:17:39 |
|
This function is just a basic example of the principle for moving a node. In a real project, you can implement movement in any way you wish. You can use rotation angles to define direction, apply different speeds to the axes if you need to simulate a jump, move towards a specific node, and so on.
|
 sam_grady Registered User |
Quote
|
2024-12-14 10:39:25 |
|
Here’s the code to move to a point represented by the coordinates X, Y, Z:
function moveToTarget(node, speed, x, y, z) { // Get the absolute position of the node in the scene. let movingNodePos = ccbGetSceneNodeProperty(node, "PositionAbs"); // Define the target position as a vector with the given x, y, and z coordinates. let targetPos = new vector3d(x, y, z); // Calculate the direction vector from the moving node to the target point. // The direction is the difference between the target position and the current position of the node. let direction = new vector3d( targetPos.x - movingNodePos.x, targetPos.y - movingNodePos.y, targetPos.z - movingNodePos.z ); // Normalize the direction vector to ensure it has a unit length (magnitude = 1). direction.normalize(); // Scale the direction vector by the speed to adjust the movement velocity. direction.x *= speed; direction.y *= speed; direction.z *= speed; // Apply the calculated velocity to the node using CopperCube's physics system. // The node will move towards the specified target point at the given speed. ccbSetPhysicsVelocity(node, direction.x, direction.y, direction.z); }
|
 lucas007 Registered User |
Quote
|
2024-12-14 12:34:34 |
|
Thanks for your help sam_grady. I will try to make my own script to control scene with beahavior move by physics engine and tell you when I finish. Thank your for your example
|
 sam_grady Registered User |
Quote
|
2024-12-14 12:55:13 |
|
No problem at all, feel free to reach out! If you need, I can write more examples (I actually tried to, but the forum doesn't allow posting multiple messages in a row to prevent spam, so I couldn't send the rest right away).
|
 sam_grady Registered User |
Quote
|
2024-12-14 12:57:13 |
|
Here, I’ve added a couple more functions to better explain how it works:
function moveToTargetNode(node, speed, targetNode) { // Get the absolute position of the moving node in the scene. let movingNodePos = ccbGetSceneNodeProperty(node, "PositionAbs"); // Get the absolute position of the target node in the scene. let targetNodePos = ccbGetSceneNodeProperty(targetNode, "PositionAbs"); // Calculate the direction vector from the moving node to the target node. // The direction is the difference between the target node's position and the moving node's position. let velocity = new vector3d( targetNodePos.x - movingNodePos.x, targetNodePos.y - movingNodePos.y, targetNodePos.z - movingNodePos.z ); // Normalize the direction vector to ensure it has a unit length (magnitude = 1). velocity.normalize(); // Scale the direction vector by the speed to adjust the movement velocity. velocity.x *= speed; velocity.y *= speed; velocity.z *= speed; // Apply the calculated velocity to the moving node. // The moving node will approach the target node at the given speed. ccbSetPhysicsVelocity(node, velocity.x, velocity.y, velocity.z); }
function moveByAngle(node, speed, angleX, angleY) { // Get the absolute position of the node in the scene. let nodePos = ccbGetSceneNodeProperty(node, "PositionAbs"); // Calculate the target position based on the specified angles (angleX, angleY). // These angles are interpreted in degrees and converted to radians for trigonometric calculations. let targetPos = new vector3d(0, 0, 0); targetPos.x = 10 * Math.sin(angleY / 57.29) * Math.cos(angleX / 57.29); targetPos.z = 10 * Math.cos(angleY / 57.29) * Math.cos(angleX / 57.29); targetPos.y = -10 * Math.sin(angleX / 57.29); // Calculate the direction vector from the node to the target position. let velocity = new vector3d( targetPos.x - nodePos.x, targetPos.y - nodePos.y, targetPos.z - nodePos.z ); // Normalize the direction vector to ensure it has a unit length (magnitude = 1). velocity.normalize(); // Scale the direction vector by the speed to adjust the movement velocity. velocity.x *= speed; velocity.y *= speed; velocity.z *= speed; // Apply the calculated velocity to the physics-enabled node. // The node will move in the direction specified by the input angles at the given speed. ccbSetPhysicsVelocity(node, velocity.x, velocity.y, velocity.z); }
|
 sam_grady Registered User |
Quote
|
2024-12-14 12:58:10 |
|
function moveToPositionWithCollision(node, speed, targetX, targetY, targetZ) { // Get the current position of the node in the scene. let currentPosition = ccbGetSceneNodeProperty(node, "Position"); // Cast a ray from the node's current position toward the target position. // If the ray intersects with a collision point, that point is returned. let rayCollider = ccbGetCollisionPointOfWorldWithLine( currentPosition.x, currentPosition.y, currentPosition.z, targetX, targetY, targetZ ); // Determine the final position to move toward. // If a collision point is detected, use it as the final position. // Otherwise, use the original target position. let finalPosition = rayCollider ? rayCollider : new vector3d(targetX, targetY, targetZ); // Calculate the direction vector from the current position to the final position. let velocity = new vector3d( finalPosition.x - currentPosition.x, finalPosition.y - currentPosition.y, finalPosition.z - currentPosition.z ); // Normalize the direction vector to ensure it has a unit length (magnitude = 1). velocity.normalize(); // Scale the direction vector by the speed to adjust the movement velocity. velocity.x *= speed; velocity.y *= speed; velocity.z *= speed; // Apply the calculated velocity to the physics-enabled node. // The node will move toward the target position or stop at the collision point if one is detected. ccbSetPhysicsVelocity(node, velocity.x, velocity.y, velocity.z); }
|
 lucas007 Registered User |
Quote
|
2024-12-15 11:38:13 |
|
Tank you very much. I think it's enougth to finish my projet
|