Mounting camera outside of sprite
by USC - IMD student 2 · in Torque Game Builder · 07/28/2006 (4:47 pm) · 14 replies
I'm trying to mount the camera to a sprite, and have the camera offset outside of the sprite. unfortunately, T2D only lets you offset by object space coordinates, which seems to imply that you're only supposed to mount something on the sprite itself. when i try to offset the camera outside the sprite, then the sprite swings like a pendulum when it moves back and forth. I think it might have something to do with the fact that i rotate my sprite a little bit.
About the author
#2
07/28/2006 (5:12 pm)
There is also mount force, if you can get nothing else working.
#3
07/28/2006 (5:21 pm)
I guess i didn't explain my problem very well. i can get the camera to mount to the sprite and offset outside the sprite. but the problem is, when that sprite rotates, it no longer rotates on its own axis. instead, it rotates around the point that the camera is mounted to, which makes it swing like a pendulum. any ideas as to why its doing this?
#4
07/28/2006 (5:25 pm)
Huh, Are you sure that this isn't an optical illusion? I didn't think it possible to rotate a sprite around anything but it's pivot point.
#5
edit: as Kevin says, the sprite can only rotate about its centre. At the moment, TGB doesn't support alternate pivot points.
07/28/2006 (5:31 pm)
I tried mounting the camera to a sprite and rotating the sprite. For me, the camera just went round with the sprite, but don't forget that the camera can't actually rotate. So while my sprite rotated using setAutoRotate, the camera kept going round in circles. What command are you using to rotate your sprite and is it mounted to anything else?edit: as Kevin says, the sprite can only rotate about its centre. At the moment, TGB doesn't support alternate pivot points.
#7
07/28/2006 (5:52 pm)
;) lol. subtle....
#8
07/28/2006 (8:37 pm)
Lol, yeah, subtle. oddly enough, it seems like whatever i did, i am getting an alternate pivot point. i am mounting a camera to a sprite, and offsetting it greater than 1 (offsetting outside the sprite). then for some reason, when i rotate that sprite, instead of rotating around its center, it rotates around the point that the camera is mounted to. am i just losing my mind or what?
#9
07/29/2006 (5:31 am)
Oh I get what you mean now, but I can't seem to recreate it. I tried mounting the camera at different places, but the sprite rotates about its centre. I tried using the setAutoRotation() command and rotateTo() command, but both have the sprite rotate around its middle. It must be to do with something else in your code. Is your sprite mounted to anything else, or have you tried mounting the camera somewhere else as well by mistake? When you run the game, check the console and see if there are any error messages.
#10
%mountPosition = $foo.getLocalPoint($foo.getPositionX( ),$foo.getPositionY( ) + 25);
sceneWindow2D.mount($foo,%mountPosition,0,true);
$foo.setAngularVelocity(90);
07/30/2006 (7:45 pm)
Btw, i fixed the problem, by mounting an invisible non-rotating sprite to the main sprite, and mounting the camera to that. but if anyone wants to try to recreate the alternate pivot point effect that I had, this is how i did it. mount the camera to a sprite, but offset greater than 1, then rotate the sprite. something like this...%mountPosition = $foo.getLocalPoint($foo.getPositionX( ),$foo.getPositionY( ) + 25);
sceneWindow2D.mount($foo,%mountPosition,0,true);
$foo.setAngularVelocity(90);
#11
That works for me. You can change the 3 to whatever suits your game. However, I haven't tried your method using an invisible sprite so the effect might be different. However, your code it slightly wrong I think. This:
07/31/2006 (5:41 am)
Instead of mounting it like that, couldn't you have done:sceneWindow2d.mount($foo, 3, 3, 0, true);?
That works for me. You can change the 3 to whatever suits your game. However, I haven't tried your method using an invisible sprite so the effect might be different. However, your code it slightly wrong I think. This:
%mountPosition = $foo.getLocalPoint($foo.getPositionX(), $foo.getPositionY() + 25);returns two numbers, the X and Y. Therefore you should have this :
%mountPosition = $foo.getLocalPoint($foo.getPositionX( ),$foo.getPositionY( ) + 25); sceneWindow2D.mount($foo,getWord(%mountPosition,0),getWord(%mountPosition, 1),0,true);
#12
07/31/2006 (7:17 am)
Seems like the console would return: Invalid Number of Parameters if #2's way didn't work. Maybe the mount function can use "x y" or x, y That doesn't really seem right, but I would be much easier to put all your info in the mount function, #2.
#13
07/31/2006 (8:10 am)
I was mounting my object to the background, so it wasn't using the camera's mount function. However, when I tried to input my equivalent of %mountPosition, it didn't seem to work and I didn't get any errors. So I tried using the method I wrote and it worked. Not sure why it decided to work like that and have no error messages before.
#14
07/31/2006 (12:16 pm)
I think the official convention is to use 2 arguments for the mount position (as per the reference doc), but for backwards compatibility the function will take a space-delimited parameter, too. I didn't test that, just a guess.
Torque Owner Apurva Amin
function myClass::onLevelLoaded(%this, %scenegraph){ $sprite = %this; SceneWindow2d.mount(%this, -3, 0,0, true); }This should offset the camera to the left slightly.