I want to “animate” the dynamic rocket cages of the dronecar in this simulation.
Similar to how car racing games “animate” the wheels of its cars: I want to apply physics to the rocket cages to “rotate” about the gear axis according to the relative movement and keypress.
For example, all four rocket cage gears tilt forward on KeyPressW.
There are two ways of doing this, one involves adding an animation component, and the other is to, I think, treat each “Dynamic Rocket Cage” (“DRC”) as an array [0], [1], [2], and [3] for DRC-front-right, DRC-front-left, DRC-back-left, DRC-back-right, or something similar, and then rotating each respective gear according to the relative directional controls. I want to do the latter.
If I understand you correctly and you want to hear an unprofessional suggestion without using animations, you could try to rotate the part(s) with 0.01 until the maximum rotation is reached when the specific key is pressed. You do the same the other way when the specific key is not pressed to bring them back in the default state.
I’m trying to implement the yaw left script component to the back right DRC rigidbody, but it does not seem to be working. The script and process of attaching the script is the same.
But the animation is unresponsive on KeyPressA. Am I overlooking something? By the way, this is the image I’m after:
I am working on the front and back cage individually since each one rotates in different x directions.
if (this.app.keyboard.isPressed(pc.KEY_A)) {
if (this.entity.getEulerAngles().x < 33) {
this.entity.rotate(0.1,0,0);
}
}
else {
if (this.entity.getEulerAngles().x > 0) {
this.entity.rotate(-0.1,0,0);
}
}
Sorry, I was referring to the “Dynamic Rocket Cage” (DRC) as I established the convention in the first post lol and yaw just means “rotating about an axis.” The code is above. It’s the same as the other one with the only difference being pc.KEY_A.
I think you can use this way also with applyTorqueImpulse like you did in your first post here, but when I looked at your project there was no rigidbody on that part of the model. So you can try it again if it has a dynamic rigidbody. Otherwise it has to be a kinematic rigidbody.
To prevent it from breaking you have to use rotateLocal instead of rotate, sorry for that. Apart from that, there are a number of other issues in your project.
You use diffrent types of rigidbodies. My solution is only working for kinematic rigidodies, if you need to use a dynamic rigidbody you could try to use applyTorqueImpulse instead of rotateLocal. So, first determine whether or not you need to use dynamic rigidbodies. (Kinematic rigidbodies do not respond to obstacles and dynamic rigidbodies do).
Your logic is wrong. The keys are conflicting with each other. Using different rotation speeds doesn’t make it any better. If you’re using kinematic rigidbodies then your code for drcFrontRight.js should look something like below. I’m not sure if this adjustment is enough, but I hope this is enough for you to see the problem.
if (this.app.keyboard.isPressed(pc.KEY_W) && this.entity.getLocalEulerAngles().x <= 33) {
this.entity.rotateLocal(0.1,0,0);
}
else if (this.entity.getEulerAngles().x >= 0) {
this.entity.rotateLocal(-0.1,0,0);
}
if ((this.app.keyboard.isPressed(pc.KEY_S && this.entity.getLocalEulerAngles().x >= -33)) ||
(this.app.keyboard.isPressed(pc.KEY_D) && this.entity.getLocalEulerAngles().x >= -33)) {
this.entity.rotateLocal(-0.1,0,0);
}
else if (this.entity.getEulerAngles().x <= 0) {
this.entity.rotateLocal(0.1,0,0);
}
I want to keep developing the simulation to include more detailed artwork, and features like 1st person mode; walking around and getting into the dronecar, like in GTA, as well as the same perspective view of the dronecar so that the camera is not locked on to it, but it’s more fluid, like so:
Before I start a new thread, is there anyway to prevent the following?
Also I advice to set the value of the Camera Clip Far of the editor settings a bit higher to prevent your models are disappearing in the black background while you working in the editor.
The reason why your drone loses control also has to do with this. I’ve seen you haven’t modified all your scripts yet. The scripts drcBackLeft.js and drcBackRight.js need to be improved. Since you are now using rotateLocal you should probably also use getLocalEulerAngles instead of getEulerAngles. However, the code below seems to start the problem.
Firstly, I would just like to thank you for all your patience with me and attentiveness to this project!
Secondly, awesome! You managed to fix, like, 3 of the problems I was having. I believe the reason I didn’t modify the remaining scripts is because they conflict with each other. For instance, the code works here because “x<=0” applies to both instances of the “else if” statement with respect to pc.KEY_S, and pc.KEY_A
But not here, because the “else if” statement for x is “<” and “>” for pc.KEY_S and pc.KEY_A. respectively.
So, I left it the way it was originally. I don’t know if there is a way around this.
Basically, once the dronecar “yaws”, or rotates about its axis, 180 degrees: the WASD controls don’t follow, if that makes sense.
After the dronecar rotates 180 degrees, ‘W’ no longer makes it go relatively forward, and ‘S’ no longer makes it go relatively backward with respect to the front and rear of the drone car respectively.
Is there a localApplyImpulse of some sort that applies a force relative to the axis of the dronecar rather than relative to the axis of the map level?
In the drcBackRight.js script the W and A key are conflicting and in the drcBackLeft.js script the W and D key are conflicting. You have to combine these keys to one if statement.