Setting camera to an object
-
Does anyone know how to use "setCamera()" to attach the camera to an object? I need the object to turn and the camera to turn with it. It only seems to accept vectors but I can't work out how to find the position vector of the object. Is there some way to turn the position of the object into a separate variable?
-
Hey,
To make the camera look at an object you'd use
setCamera
with the camera position and target position (https://fuzearena.com/help/view/setCamera).So essentially, if you want a camera to follow an object, you keep calling
setCamera
with the second parameter set to the new location from the target object. -
I'm using this to follow the object but the problem is that when the object turns, it doesn't take the camera with it, it just follows while the object rotates in view. I came up with a way to make the camera turn at the same time so it kind of turns with it now, I just have to work on the numbers to get them to synchronise, but the object still stays the same amount away from the camera in the same direction as before.
So for example, what I have now is:
Pressing right on the left stick rotates the object to the right, rotates the camera to the right and shifts both the camera and object slightly forward and to the left.What I want to make is:
Basically the same as above but the object should move slightly to the right and back in order to look like it's turning around the camera and not just in front of it.Edit: Or for the camera to swing around the object as it rotates, which is what I wanted with the original post. I wanted to attach the camera to an invisible object that's then attached to the object in view.
@mario-bodemann Was it you who made the space themed JUMP game for the JAM? Because I'm going for something similar, I had a look inside that game to figure out how to do it but couldn't understand how any of it worked. Anyway, imagine the view being similar but I also want the camera to allow the player to look around slightly.
I had an idea for a different method of achieving this while writing this so I'll try later and see what happens.
Edit 2: Found the problem! I "setObjectPos" with a specific vector. When the camera turned, it did not alter the vector and therefore didn't move the object. I changed the vector to 0 and it solved most of the problem. Only now it's a slightly different camera angle but I can live with that.
-
Hey @Something,
yes, that was me with the space jump Stargate asteroid shooter game. (And the fancy transition once in the gate: gotta love 2D in 3D😁)
I think I stored the orientation of the ship with a vector: whenever I rotated the ship, I used
atan2
to create a rotation from the vector, added my rotation change to the rotation just calculated and then usedsin/cos
to calculate the direction vector for the ship again from the new rotation. So instead of using the rotation angle for everything, I use vectors.Why? The directional vector makes movement of the ship way easier: the new location of the ship is it's old location plus a fraction of the directional vector. Applying forces and so on to the ship makes the impact of the directional vector a bit smaller.
Plus I can calculate the camera position: take the position of the ship, subtract (!) the directional vector from it, so we are moving "behind" the ship, and add some "up" vector to it: This way you'll always have the camera strictly behind (and a bit up) of the ship.
Then setting the camera to this new vector as a location and the position of the ship as a target and we have the result of the asteroid shooter jumping through wormholes game.
As long as you don't tilt the object up and down and want the camera to follow, this method works kinda nicely. If more freedom is needed, we need matrixes and quaternions to fight evil gimbal locks. But that is a story for another time ... 😁
Hope it helped and I didn't ramble too much. 🤔😁
-
Still stuck on this part. Everything I tried so far has failed. I even accidentally made a camera similar to the original Resident Evil games which could be useful in the future but not what I'm going for now.
@mario-bodemann I looked again in your program and I couldn't find how you stored the ship orientation vector. I think this is the missing piece to make my program work. I know I'm missing something obvious.
-
Hey @Something , I'm back online so will download your project now to check it out :)