Interpret an item based on its specific axis in that location

Being new to three.js, I am facing a challenge with translating an object imported from Maya. The issue arises after rotating the object; when I attempt to move it afterward, it moves along the scene's axis instead of in the direction of the rotation.

This is my attempted solution:

var keyCode = event.which;

// up
if (keyCode == 87) {
    shuttle.translateZ(0.2);
    // down
} else if (keyCode == 83) {
    shuttle.translateZ(-0.2);
        // left
} else if (keyCode == 65) {
    shuttle.rotation.y-= 0.1;
      // right
} else if (keyCode == 68) {
    shuttle.rotation.y += 0.1;
  }

Interestingly, whether I use the function translateZ or shuttle.position.z+=1, there seems to be no difference in the outcome.

Answer №1

Discover a simple method to move in the object's direction

let objDirection = spaceship.getWorldDirection();
spaceship.translate(objDirection.multiplyScalar(distance));

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

Avoiding the display of a modal window during page refresh

I am encountering an issue with a modal window (bootstrap 4) and a multipage gridview on my website. When the page initially loads, the modal window appears without any problems. However, if I navigate to the next page on the gridview, the page refreshes a ...

How to Retrieve Values from HTML Using the onkeyup Function in jQuery with Element ID?

Having trouble retrieving values from HTML to jQuery using the onkeyup function to capture key pressed data by ID. I've attempted it, but I can't seem to get the value to display in an alert. Unsure what's going wrong with my code. Can someo ...

What is the proper sequence for binding jQuery to elements?

I'm currently facing a challenge with using jQuery to link a function to an element. Essentially, I'm loading a series of divs via JSON, with each item in the JSON having an "action" assigned to it that determines which function should be trigger ...

Tips for Seizing the "F2" key on ASP.NET Web Forms

I have a requirement in my web application where I need to open a new page when the user presses the F2 key. After some research, I discovered that this can be achieved with JavaScript. So, I wrote some code in JavaScript, but I encountered an issue - it ...

Troubleshooting data binding problems when using an Array of Objects in MatTableDataSource within Angular

I am encountering an issue when trying to bind an array of objects data to a MatTableDataSource; the table displays empty results. I suspect there is a minor problem with data binding in my code snippet below. endPointsDataSource; endPointsLength; endP ...

Two entities positioned on opposite extremes

Is there a way to design a div with two elements (text and image) positioned on opposite sides? The length of the text varies as it's a list of months for selection. Ideally, the text should appear on the left side of the div as a "p" element, while t ...

Struggling to make HTML5 geolocation coordinates function properly

I've attempted to work with examples in this code snippet, but I'm struggling to make the html5 geolocation coordinates function properly. Everything works fine when I hardcode the coordinates. var infowindow; var map; function initialize() ...

Managing array elements in React: removing and duplicating items

One of my tasks is to incorporate a copy and delete button within a table. My goal is to pass the index from the map to the delete and copy onclick functions, however, I am encountering an issue where copying a row results in it having the same index as th ...

Pass the selected value from jQuery autocomplete to a hidden field

I am attempting to transfer the current value of AutoComplete jQuery to a HiddenField on ASP Hidden Field: <asp:HiddenField ID="hidden" runat="server" /> Upon Page Load, I only set the HiddenField Value to a TextBox: Protected Sub PrepareSession ...

Unable to load AngularJS thumbnails from JSON file? Learn how to showcase a larger image by clicking on the thumbnail

Working with AngularJS to retrieve image data from a JSON file has been successful for me. My next task involves loading all of the thumbnail images into the gallery div and populating the src, alt, and title attributes using ng-repeat. However, this part ...

How to eliminate specific values from an array using Javascript

I'm tackling a challenge to create a custom function that can remove specified arguments from an array. While the concept is clear, my current implementation isn't quite hitting the mark yet. For instance, if given the array [1,2,3,4] and the ar ...

Tips for transforming a string into a date using Angular

What is the best way to transform a string into a date in Angular13? Here's an example: str = '2022-06-09T22:00:00Z'; needs to be converted to a datetime format of mm/dd/yyyy --:-- -- ...

React Color Input: The input format should follow the pattern of "#rrggbb", with rr, gg, and bb being two-digit hexadecimal values

The code is functioning correctly and as expected. The background color of the squares changes when each input is modified, and the squares update once the button is pressed. During development, there was a moment when the warning mentioned appeared brief ...

Listen for an event on a button to show a specific div

Looking to have a div appear when the user clicks on a button. //html-code <div class="col-md-4"> <h4 class="service-heading">Social Media</h4> <p class="text-muted">This is the first line of text.</p& ...

Sending an array of objects in JavaScript to a controller

I have a dynamic form that I'm trying to submit to my Controller. Instead of sending just a string or an array with data, I need to pass an array of objects using ajax request after building the Javascript Array. The challenge is that when I send only ...

"Creating a fixed header with jQuery by manipulating the offset and scrollTop

My goal is to create a smooth scrolling website that scrolls vertically using jQuery. I found a helpful tutorial called Smooth Scrolling Website and have been following it closely to build my site. However, I'm facing an issue with a fixed header - t ...

An issue is preventing the Angular 2+ http service from making the requested call to the server

I am looking to create a model class that can access services in Angular. Let's say I have the following endpoints: /book/:id /book/:id/author I want to use a service called BooksService to retrieve a list of Book instances. These instances should ...

Click to refresh a different component in ReactJS

My goal is to create a unique media player that can reload when a user wants to listen to an MP3 file. The concept is as follows: In media-player.js: - Display title, artist, and album art In programs.js: there is a button (LISTEN) that renders in medi ...

What could be the reason behind my inability to initiate this PHP file through jQuery/AJAX?

I'm experiencing an issue with a piece of PHP code (located at ../wp-content/plugins/freework/fw-freework.php). <div id="new-concept-form"> <form method="post" action="../wp-admin/admin.php?page=FreeWorkSlug" class="form-inline" role ...

A comprehensive guide on incorporating Jest for testing localStorage

I have attempted to mock localStorage following the advice from another source, but I am struggling to get the tests to pass despite several attempts. Below is the code for the localStorage mock: class LocalStorageMock { constructor() { this.stor ...