Trying to do a bumper game
I have a platform and 2 spheres on it. I want upon collision both spheres to push back (like billard)
Is there a native function to do that?
Also some “problems” (probably natural things but I want to disable them):
Is it possible for the spheres to not rotate from collision (rotate only on Y axis based on user’s mouse cursor position not because of collision)
After some time the spheres start bouncing on the platform is it possible to disable the Y force (although I do want whenever a sphere go off the platform to fall down)
Thanks!!!
I tried “programmatically” but it’s not very natural xD (I saw on net something like addInPulse or angular/linear velocity is this the correct approach? )
// Calculate the direction from car1 to car2
const direction = item.position.subtract(car.position).normalize();
// Define the transition distance (4 units in this example)
const transitionDistance = 2;
const multiply1 = car.metadata.multiply;
const multiply2 = item.metadata.multiply;
// Calculate the target position for both cars (move back by transitionDistance)
const targetPosition1 = car.position.subtract(
direction.scale(
multiply2 *
transitionDistance *
(item.metadata?.scaling / car.metadata?.scaling || 1)
)
);
const targetPosition2 = item.position.add(
direction.scale(
transitionDistance *
multiply1 *
(car.metadata?.scaling / item.metadata?.scaling || 1)
)
);
// Create animation for car1 to smoothly transition to the target position
const animation1 = new Animation(
"moveBack1",
"position",
40,
Animation.ANIMATIONTYPE_VECTOR3,
Animation.ANIMATIONLOOPMODE_CONSTANT
);
// Define keyframes for the animation of car1
const keys1 = [];
keys1.push({
frame: 0,
value: car.position.clone(), // Start position
});
keys1.push({
frame: 60, // Duration of animation (in frames, adjust as needed)
value: targetPosition1, // Target position
});
// Set keys to the animation of car1
animation1.setKeys(keys1);
// Apply animation to car1
car.animations.push(animation1);
scene.beginAnimation(car, 0, 60, false, 3); // Start the animation for car1
// Create animation for car2 to smoothly transition to the target position
const animation2 = new Animation(
"moveBack2",
"position",
40,
Animation.ANIMATIONTYPE_VECTOR3,
Animation.ANIMATIONLOOPMODE_CONSTANT
);
// Define keyframes for the animation of car2
const keys2 = [];
keys2.push({
frame: 0,
value: item.position.clone(), // Start position
});
keys2.push({
frame: 60, // Duration of animation (in frames, adjust as needed)
value: targetPosition2, // Target position
});
// Set keys to the animation of car2
animation2.setKeys(keys2);
// Apply animation to car2
item.animations.push(animation2);
scene.beginAnimation(item, 0, 60, false, 3); // Start the animation for car2