Rotate slowly and cheap

Hi guys , try to finde a way to rotate an object slowly and at minimal effort for pc,now i have tried the look at,and read some previose topics ,but i still has not fount what i needed. The fact is i need to rotate an object slowly,and actually i need no other then X slow rotation ,as Y can move fast (i dont minde and it have to be cheaper :slight_smile: ).Right now i’m using // java
player.lookAt(player2.getLocalTranslation(), Vector3f.ZERO);
i’ve seen some suggestions on use look at,clone and slerp ,but im not pretty shere on if this is the best way,as some 1 told game gone slow on use it.
Now i do intend to set great ammounts of units on field and need some thing really cheap for that.
Any help is well apreciated :slight_smile: thnx

/what i need is to move a 3D object lets say Soldier who is controlled by npc,but i need it to turn it slowly like u would do in real life and not just insta turn/

Why don’t you use spatial.rotate() ?

The first link is more about how to deal with nodes in general, the second one does exactly what you are requesting.

Or do you mean orbiting a node (in your case maybe player2) with a camera? Maybe then you look for the ChaseCam? There is one, I use it a lot expecially when I want ot inspect something in a game or example.

i have read 2nd link with a lot of attention (i’ve did all tutorials but ,reconsidering it was pretty usefull :smiley: ) and it is close to what i need may be… but i cant get how to make it rotate right to the right direction.Its like i have npc theat should use rotate,and i have a player run around,how should npc rotate/chase (chase not intend follow,just turn body around) the moving player,should i go for some form of soldir.getLocalTransletion vs players location? ehh im a bit confused :smiley:

Sorry if I’m wrong about what you’re trying to do exactly, but it sounds like you want the spatial’s vision to gradually follow the player so that its like the spatial is always looking at the player, much like you can achieve by updating the view direction of a character control in the update loop?

I just finished doing something like this for my game and made some small mistakes myself while implementing it. I’m not sure if your variable “player” is a spatial or quaternion, but I got this code to work by using Quaternion.lookAt() to get the desired rotateQuat, and then I applied that to the player . Another error you may have is if your using the method “Spatial.rotate(rotation);” rather than" spatial.setLocalRotation();"the first one will spin your model out of control, wihle the second one is the correct way to set the rotation regardless of a spatial’s current rotation

        Quaternion rotateQuat = new Quaternion();
        Vector3f lookDir = npc.getTarget().getLocNoY().subtract(getLocNoY());
        rotateQuat.lookAt(lookDir , upVar);

I hope this helps some, but the only other way I could think to achieve this without using a characterControl is by subtracting the desired rotation from the players current rotation, and then use Spatial.rotate() to change the rotation by the difference; i personally thought the lookAt() method would be more efficient than this, but I also didn’t look for many alternatives (i typically focus on optimization as a last step, and since using lookAt() hasn’t casued me any significant raises in memory or drops in fps i’ve been using that method, I hope the same can end up working for you)

Vector3f.ZERO is wrong it should be the up vector most often this is Y, but for sure not ZERO. I think then it does what you want.

And btw. I now got what you are looking for and I think you was on the right path. But doing the beginners tutorial was anyway not a waste of time, so I’m glad you did it :slight_smile:

I actually manage to make npc look at player,thats not the problem,what i need is to make him look slowly,lets say i come to u from back,if u use look at u will instantly teleport your self to look at me ,but in real life u will use some time to turn around completly… thats what a looking for

Oh that makes sense I see why you’re probably having some touble doing that, I’ve done this with vectors using the Vector.length() method in a while loop that scales the vector in a loop until the length is less/greater than the desired amount. It doesn’t look like theres any method for Quaternion.length() or Quaternion.magnitude() though, so I’m pretty certain this is possible in some way but you may need to do the math to make that on your own. Here’s the code I use for scaling my vectors upwards this way

        launchSpeed = (getMainAgent().getHeadLoc().subtract(caster.getHeadLoc()));
        while(launchSpeed.length() < speed){

so this makes me think you’d want to do something like this, I don’t have any code to copy and past so this is just an outline of where I’d start from

        Quaternion desiredRotation = lookAt();
        Quaternion currentRotation = getCurrentLocalRotation();
        Quaternion difference = desiredRotation.subtract(currentLocation);
        while(difference.magnitutde() > desiredIncriment){

that would achieve what you’re looking to do except like I said, I’m not aware of any way to easily determine the size/magnitude of quaterniuons the way you can with vectors, I’m not great with Quaternions but it may even be easier to do this with an X, Y, and Z float to represent rotation instead of using the Quaternion object

1 Like

Maybe next time provide your code as a simple app in one class so we see what you do instead guess what we think you do. Less time consuming for everybody.

This is really a steering problem… but especially if you ever want to limit the rate of turn instead of just some arbitrary percentage of the difference.