How to replicate the pointing direction of an object in Three Js

For my current school project, I am developing a 3D space fighter game. However, I am facing an issue when trying to spawn a projectile based on the direction of my ship's front face.

I have managed to find a solution using vectors to spawn projectiles according to the direction we are facing. An example can be found at

Despite this, I still do not fully understand how vectors work in this context. Can someone please provide an explanation?

Answer №1

To truly grasp this concept, it is essential to shift your focus from programming to linear algebra. Understanding the core definition of a Vector and what it represents is crucial.

A common misconception is viewing a Vector as simply a point in 3D space (x,y,z). This oversimplification hinders the ability to work with vectors effectively in spatial scenarios, leading to confusion like the one presented here.

For more information and resources on vectors and spaces visit:

Explore vector introduction in linear algebra at:

When copying object rotation, utilize

obj2.rotation.set(obj1.rotation.x,obj1.rotation.y,obj1.rotation.z)
. To place an object relative to another object's orientation, consider using the second object as a parent:

var my_vect = new THREE.Object3D(); // create a vector
obj1.add(my_vect); // add it to your object
obj1.rotation.set(1,2,3); // rotate the object
my_vect.position.translateX(1); // move the vector 1 unit ahead of the object
obj1.localToWorld( my_vect.position); // transform local coordinates into global coordinates

In essence, my_vect.position.x, my_vect.position.y, my_vect.position.z represent the positional values before considering the object's orientation within your scene.

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

JavaScript - An unexpected error occurred: Syntax error, unrecognized expression: [href=#contact] (WordPress)

I am currently working on a feature that involves adding a class to a specific menu item when a certain section is in view. However, I encountered an error that reads: Uncaught Error: Syntax error, unrecognised expression: [href=#contact] Your help would ...

When the user clicks on the iframe, they will be redirected to the

My goal is to create a scenario where clicking on an iframe opens the same URL in a new browser tab, while ensuring that scroll and other mouse events within the iframe are not affected. I have experimented with various approaches but none have been succe ...

Attempted to utilize zipstatic but received no feedback

I attempted to utilize the Zipstatic API with jQuery in my code, as shown below. However, I am not receiving any response. Could there be something missing? jQuery(function() { jQuery("#form").hide(); jQuery("#postcode").keyup(function() { var c ...

Creating a multiline textarea with ellipsis using ReactJS

Looking to create a component with a multiline textfield that displays ellipsis (...) for text overflow beyond 2 lines. How can I achieve this through CSS only without modifying the actual stored text? Utilizing the React component found at: link Appreci ...

Switched from btao to Buffer, however encountering a TypeError while trying to push to Vercel

I am currently working on an application in Next.js where I need to encode my image to base64. Initially, I used btao and it worked well until I tried deploying to Vercel, which resulted in an error stating that btao was undefined. After researching a solu ...

Wcf Service does not define Angular JS methods

I am utilizing a WCF Service within an AngularJS application. The WCF Service is functional, and I am attempting to display a list of user records from a SQL database. However, upon running the application, I encountered the following errors: angular.js: ...

What is the best way to update image CSS following a rotation using JavaScript?

Discover a neat CSS trick for always centering an image in a div, regardless of its size or aspect ratio. <style> .img_wrap { padding-bottom: 56.25%; width: 100%; position: relative; overflow: hidden; } #imgpreview { display: bl ...

Manipulate SVG elements using svg.js and svg-pan-zoom, allowing for double-click interactions

Using Ariutta's svg-pan-zoom with svg.js, I've disabled the native doubleclick functionality and implemented my own custom doubleclick behavior involving pan adjustment and animation. While this setup usually works fine, occasionally the doublec ...

Ways to extract a particular item from a dataset

{ type: 'Text', firstLanguage: { translation: 'When did the Constituent Assembly approve the Objective Resolution?', option_a: '14th February 1949', option_b: '12th March 1949', option ...

When invoking the Angular function to make an HTTP request, it will generate a recurring loop

When trying to call a function in mg-repeat that makes an HTTP request with an ID to find a list of data, I encountered an error message. Here is the function call: <div ng-repeat="ListeReponse in reponsefonction(Listechamps.keyQuestion)" > < ...

Having trouble with making a POST request in Node.js using Express.js and Body-parser?

Just starting out with nodejs and currently in the learning phase. I've encountered an issue where my POST request is not functioning as expected. I set up a basic html form to practice using both GET and POST requests. Surprisingly, the GET request w ...

What is the best way to add extra plugins to a library that has already been imported through JSPM?

After successfully importing a 3D rendering library with JSPM, I encountered an issue while trying to import the Orbit Controls plugin for Three.js import THREE from 'three.js/build/three'; import OrbitControls from 'three.js/examples/js/ ...

Establishing a website tailored specifically to each city's needs and interests, such as city1.example.com and city2

How can I create a website with subdomains dedicated to different cities like http://philly.example.com, http://maine.example.com, and http://sandiego.example.com? The majority of the site will remain the same in terms of layout, wording, database, and int ...

I am experiencing some issues with my AngularJS JavaScript code. The root scope is updating correctly, but the other two scopes are not working as expected. Can

My attempt at writing AngularJS JavaScript code seems to be malfunctioning. While the root scope updates properly, the other two scopes FirstCtrl and SecondCtrl do not update as expected when the root scope is updated. I would like all three scopes to upd ...

The FedEx API Rate Quote is currently unavailable and returns a 404 error message stating: "The requested resource is no longer accessible."

I am encountering issues while attempting to integrate the FedEx API into my Node.js application to obtain shipping rate quotes. Despite closely following the provided documentation, I consistently encounter a 404 error accompanied by the message: " ...

Pushing items to an array is causing the loss of previously added data

Currently, I am working on developing a prototype of a Restaurants application using Angular 8. In this project, I have implemented @Input() to transfer individual restaurant data as an object from the parent component to the RestaurantCardComponent for pr ...

Using jQuery and PHP to send a dynamic form through AJAX

I'm currently working on a pet registration form where users can add new pets. When a user clicks the "add pet" button, I use jQuery to clone the pet section of the form and give each cloned section an id like #pet-2, #pet-3, and so on. Although my ...

Formatting dates in Angular 2 and handling them in MongoDB with Express

I am currently working with Angular 2 and ExpressJS along with MongoDB. I have a date format that is being retrieved as 2016-06-02T14:20:27.062Z, but I need to display it in the format 06/02/2016 14:20:27 Express: In models/user.js: var userSchema = Sch ...

Is there a way to identify the subdocument ids that have been updated in Mongoose when performing an

Is there a reliable way to retrieve the _id of subdocuments that are inserted into an array within my document using doc.updateOne? I am concerned about getting incorrect _id values when multiple updates occur. This is my current approach, but I'm wo ...

What is the best way to transform the request query id = ' [12eetftt76237,jhgasduyas7657] ' into an array of elements or strings like [12eetftt76237,jhgasduyas7657]?

Hey there, I am working on a project using hapijs and typescript. I have a requirement to send an array of IDs as parameters through the request URL. Here is an example of the URL: localhost:3444/?id='[askjajk78686,ajshd67868]' I attempted to u ...