Ambiera Forum

Discussions, Help and Support.

Ambiera Forum > CopperCube > Announcements and Showcase
Camera shake action for explosions

Des
Guest
Quote
2023-03-24 04:08:45

Guys I've got some code here for camera shake can any programmer make it a coppercube action for me please


Des
Guest
Quote
2023-03-24 04:09:36

// Set the duration of the shake effect (in milliseconds)
var shakeDuration = 1000;

// Set the intensity of the shake effect (in pixels)
var shakeIntensity = 10;

// Get a reference to the camera object
var camera = CopperCube.getScene().getActiveCamera();

// Get the camera's initial position
var startX = camera.getPositionX();
var startY = camera.getPositionY();
var startZ = camera.getPositionZ();

// Define the easing function to use for the shake effect
var easingFunction = CopperCube.Easing.ElasticOut;

// Start the shake effect
CopperCube.getScene().startAction(function (elapsedTime) {
// Calculate the current shake intensity
var shakeX = (Math.random() * shakeIntensity * 2 - shakeIntensity) * easingFunction(elapsedTime / shakeDuration);
var shakeY = (Math.random() * shakeIntensity * 2 - shakeIntensity) * easingFunction(elapsedTime / shakeDuration);
var shakeZ = (Math.random() * shakeIntensity * 2 - shakeIntensity) * easingFunction(elapsedTime / shakeDuration);

// Set the camera's position to the new, shaken position
camera.setPosition(startX + shakeX, startY + shakeY, startZ + shakeZ);

// End the shake effect after the specified duration has elapsed
if (elapsedTime >= shakeDuration) {
return false;
}

return true;
});


morbott
Registered User
Quote
2024-09-02 05:05:51

Hi! Did anyone ever get back to you on this and make it into an Action?
That would be great.
Sorry, not really great at the coding thing, but would this work in an Execute Java Script Action?
Thank you,
Moris


Guest2
Guest
Quote
2024-09-02 05:18:50

@morbott, there is already a camera shake extension available. The post you commented on didn't get any responses likely because the code shared by @OP seems to be AI-generated and doesn't actually use the CopperCube API.

I'm not sure of the exact links to a camera shake extension, but either @SamMhmdy or @SamGrady created one. You can also experiment with the "up Vector" of the camera to create your own shake effect.


xandor2012
Guest
Quote
2024-09-02 12:40:17

both @SamMhmdy @SamGrady AND @Hadooken made extensions that were messing with upvector, you can find them by searching on forum "upvector", the most suitable for this extension mission is one that @Hadooken wrote

(nerd emoji)


j9907
Guest
Quote
2024-09-02 20:38:38

Des wrote:
// Set the duration of the shake effect (in milliseconds)
var shakeDuration = 1000;

// Set the intensity of the shake effect (in pixels)
var shakeIntensity = 10;

// Get a reference to the camera object
var camera = CopperCube.getScene().getActiveCamera();

// Get the camera's initial position
var startX = camera.getPositionX();
var startY = camera.getPositionY();
var startZ = camera.getPositionZ();

// Define the easing function to use for the shake effect
var easingFunction = CopperCube.Easing.ElasticOut;

// Start the shake effect
CopperCube.getScene().startAction(function (elapsedTime) {
// Calculate the current shake intensity
var shakeX = (Math.random() * shakeIntensity * 2 - shakeIntensity) * easingFunction(elapsedTime / shakeDuration);
var shakeY = (Math.random() * shakeIntensity * 2 - shakeIntensity) * easingFunction(elapsedTime / shakeDuration);
var shakeZ = (Math.random() * shakeIntensity * 2 - shakeIntensity) * easingFunction(elapsedTime / shakeDuration);

// Set the camera's position to the new, shaken position
camera.setPosition(startX + shakeX, startY + shakeY, startZ + shakeZ);

// End the shake effect after the specified duration has elapsed
if (elapsedTime >= shakeDuration) {
return false;
}

return true;
});



Please don't waste people's time with this AI crap. It can be useful for some stuff (particularly if you make an extension or code and want to know if it can be optimized beyond what you can do), but this? No... As others have stated, nothing there is usable.

I understand you wanted to help, but please research how things work in this engine before just asking ChatGPT to make you something which is of no use, and pass it off as a solution, confusing others.


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