Animating Object3D to move closer to the camera in a Three.js environment - currently functional, just requires adjustment of screen position

I have some code that animates an object towards the camera and resizes it to fit half of the screen

    var vFOV = camera.fov * Math.PI / 180; 
    var ratio = 2 * Math.tan( vFOV / 2 );
    var screen = ratio * (window.innerWidth * 0.6 / window.innerHeight * 0.6) ; 
    var size = getCompoundBoundingBox( object ).max.y;
    var width = getCompoundBoundingBox( object ).max.x;
    var dist = (size/screen) * (object.scale.x * 2); 

    //get final position in front of camera
    var pLocal = new THREE.Vector3( 0, 0, -dist );

    //apply the direction the camera is facing
    var target = pLocal.applyMatrix4( camera.matrixWorld );

    //animate the object towards the camera
    var tweenMove = new TWEEN.Tween(object.position).to(target, 1500).easing(TWEEN.Easing.Cubic.InOut);

Now, I want to be able to move the object either left or up for other UI requirements and responsiveness.

For example, moving it to the left third or top third while keeping it square onto the camera.

I've attempted changing the pLocal value to something like (1, 0, - dist) but this only causes the object to rotate when tweened upwards.

Any suggestions on how I can implement this functionality?

Answer №1

Resolved by incorporating a fresh viewing angle to the camera's left side

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using AngularJS, we can create a nested ng-repeat with an expression to filter the

I'm having trouble using a value from the initial ng-repeat as a filter in the nested ng-repeat. The issue lies with {{alpha.value}}. It displays correctly in the first repeat, including the filter and the h3 tag. However, in the second repeat, it s ...

Utilizing local JSON data with Morris.js: A beginner's guide

I am working on dynamically plotting a Morris line using data from a local file called sales.php (in json format): [ { year: '2008', value: 20 }, { year: '2009', value: 10 }, { year: '2010', value: 5 }, { year: ' ...

Aggregate the data entered into input fields on one page and display them on a separate page

Can you help me with this task? - I have 2 pages set up (page 1 has input fields & page 2 is where the entered data should be displayed) - I want to retrieve all the text input from the first field and insert it into the "content" tag on the second page. ...

Using VueJS to apply filters to an object causes a decrease in my application's performance

Recently, I've been working on implementing a filter for a search bar. However, I've noticed that whenever I input something into the search bar, there is a noticeable delay as it loads the entries. I'm not sure if this issue is related to ...

What is the process for incorporating a custom attribute in Quasar?

My goal is to include custom properties in the Quasar framework, but I am encountering an error with ESLint. It displays the following message: Array prototype is read only, properties should not be added I am looking to implement an extend method for Arr ...

The hover feature on my website is making the picture flicker

I am experiencing an issue with a map on my website that contains four colored squares. When I hover over one of the squares, the image of the map changes to show the route corresponding to that color. However, this causes the image to shift position and i ...

Issue with Mjpg paparazzo.js functionality not functioning as expected

I am currently exploring alternative methods to view my security cameras without relying on browser support for mjpg streaming. I have come across Paparazzo.js, which appears to be a promising solution that I want to experiment with: https://github.com/rod ...

Compiling error occurred while attempting to start ReactJS with npm

npm start [email protected] [email protected] react-three-renderer App.js import React3 from 'react-three-renderer'; import * as THREE from 'three'; import React from "react"; import ReactDOM from 'react-dom'; ...

Struggling to display Firestore data in a React component - useRef() does not trigger re-render and useState() throws an error

I am currently working on a project involving a React component called Dashboard. The component includes various features such as loading data from a Firestore database and displaying it on the page. While implementing this functionality, I encountered an ...

Encountering a VueJS error with Google Cloud Logging Winston: "TypeError: The 'original' argument must be a Function."

I have been attempting to integrate @google-cloud/logging-winston into my VueJS project by closely following the guidelines provided in both the npm package and Google Cloud docs. However, I am encountering an error message stating "TypeError: The &q ...

Using React to Calculate the Total Value of Child Components within the Parent Component

In this scenario, the parent component has access to the values of the child components but struggles to calculate the sum correctly. Instead of displaying the accurate total, it shows 0. https://i.sstatic.net/1etAx.png The expected behavior is for the To ...

Utilizing the power of Vuetify.js for a sleek top-right menu

I'm diving into Vue and looking to create a horizontal top-right menu with Vuetify. However, I'm getting a vertical menu instead of the desired horizontal layout. The Vuetify documentation doesn't offer a clear example of how to implement th ...

Node js does not support iteration for DirectoryFiles

I am currently working on a program aimed at mapping all the json files within a specific directory. As I am new to JavaScript, this inquiry may not be ideal or obvious. Here is my code: const fs = require('fs'); const { glob } = require('gl ...

What is the best way to duplicate a text using a button in ReactJS?

Hey there, I'm working with an array and trying to figure out how to copy the text in a p element ({item.adress} => this is part of an array item) when a button is clicked. Could you lend me a hand? import classes from './CryptoBox.module.css& ...

When conducting tests using Selenium and the headless Google Chrome browser in Java, the dynamic JS content fails to load

Currently, I am in the process of testing a website that I have developed as part of a Spring Boot project using Selenium. While I can successfully test basic functionalities such as page loading and title verification, I am encountering difficulties when ...

Creating personalized functions in Object.prototype using TypeScript

My current situation involves the following code snippet: Object.prototype.custom = function() { return this } Everything runs smoothly in JavaScript, however when I transfer it to TypeScript, an error surfaces: Property 'custom' does not ex ...

The functionality of Skrollr on mobile is currently not working properly due to the inability to prevent default actions

Encountering the following error on all chromium browsers while using the Skrollr library and accessing the website through mobile: "[Intervention] Unable to preventDefault inside passive event listener due to target being treated as passive. See < ...

Looking for a prerequisite for running this script?

Seeking assistance from a skilled Javascript expert. I specialize in template development and utilize a specific script to display my footer link in all the free templates I create. If someone attempts to remove the footer link, their site will be redirec ...

Using dynamic imports in Next.js allows us to efficiently load modules based on variables defining the path

When utilizing dynamic import in Next.js, I am encountering an issue. The component renders successfully when the path is used directly, but fails to render when the path is accessed from a variable. const faq = dynamic(() => import('../faq/faq&apo ...

Implementing Do Not Track in an express application

I am trying to implement a feature named "consent" in my Nodejs express app that utilizes the Do Not Track (DNT) functionality from browsers. This function is supposed to integrate Google analytics on rendered pages only when DNT is not active or its state ...