Pinball Flipper Rotate
by Goerkem Tuncay · in Torque Game Builder · 10/12/2006 (1:14 pm) · 11 replies
Hey people, this is my ever first thread so I need welcomes first =)
I am not new to Torque, have the licence for more over than a year but haven't got the time to mess with this great engine. Let me get to the point and my question.
My Father's birthday is near, he is a pinball addict he plays to death with both pinball machine and PC games, so I decided to make him a personalized pinball game. I started to make art for now I haven't got much coding experience I'll ask more. But at first point I wish to ask about Pivot points. I made up two flippers for the game, I wish them to rotate about 30 degrees when the necessary key pressed but the end of flippers (which screwed down on table) won't move. Anyone can help me with that? How can I apply the Pivot points of rotate, I don't want to rotate whole image?
Thank you and welcomes appreciated =)
I am not new to Torque, have the licence for more over than a year but haven't got the time to mess with this great engine. Let me get to the point and my question.
My Father's birthday is near, he is a pinball addict he plays to death with both pinball machine and PC games, so I decided to make him a personalized pinball game. I started to make art for now I haven't got much coding experience I'll ask more. But at first point I wish to ask about Pivot points. I made up two flippers for the game, I wish them to rotate about 30 degrees when the necessary key pressed but the end of flippers (which screwed down on table) won't move. Anyone can help me with that? How can I apply the Pivot points of rotate, I don't want to rotate whole image?
Thank you and welcomes appreciated =)
#2
10/12/2006 (3:54 pm)
Well yeah it works thanks ^^ But is there any way to change Pivot point?
#3
10/12/2006 (4:06 pm)
Have you tried mounting the flpper object's pivot point to an invisible object's center and then rotating the object?
#4
10/12/2006 (4:22 pm)
Ben's suggestion solved my problem already with this. But making an invisible pivot object sounds logical too thanks Jerry.
#5
10/12/2006 (8:04 pm)
Glad you got it working. To answer your question directly, no, there is no way to change the pivot point. All sprites rotate about their center.
#6
10/14/2006 (3:32 am)
Ben has already given you a great solution and the answer... you cannot (currently) change the pivot point. Though by either taking Ben's suggestion of oversizing the image (as you have already done) or taking Jerry's suggestion of using an invisible t2dSceneObject to mount the flipper to you can acheive what you want :)
#7
The problem appears to be that the mounted object (the flipper) will always mount from its center. How would I attach the "pin" of the flipper to the center of the invisible mount?
04/09/2011 (5:13 pm)
This is an old topic, I know, but can somebody elaborate on how you would move a pinball flipper by attaching it to an invisible scene object? I'm wracking my brain here and it seems impossible.The problem appears to be that the mounted object (the flipper) will always mount from its center. How would I attach the "pin" of the flipper to the center of the invisible mount?
#8
I've got a little script like so:
CreateRotatorPoint takes an x and y PIXEL offset from the upper left corner. That makes it easy to lift the desired rotate-around point from photoshop or MS paint or whatever. It makes the little invisible rotator object at that location, and then mounts your thing to it with the correct offset.
For extra fun, these can be chained as much as you like. Pinball flippers and double pendulums for everybody!
04/10/2011 (9:57 am)
Hey Charlie,I've got a little script like so:
function mountatcurrentposR(%obj, %mountto)
{
if(!isObject(%obj))
return;
%ox = %obj.getpositionx();
%oy = %obj.getpositiony();
%mx = %mountto.getpositionx();
%my = %mountto.getpositiony();
%x = (%ox - %mx) / (0.5 * %mountto.getsizeX());
%y = (%oy - %my) / (0.5 * %mountto.getsizeY());
%obj.mount(%mountto, %x, %y, 0,1,1,0,0);
}
function t2dSceneObject::createRotatorPoint(%this,%x,%y)
{
if(!isObject(%this.rotator))
{
new t2dStaticSprite(rotator@$rotators) {
scenegraph = $g_sg;
imageMap = "whitepixel";
frame = "0";
Visible = "0";
canSaveDynamicFields = "1";
Position = %this.getPositionX() + %x -(%this.getWidth() / 2.0)SPC %this.getPositionY() + %y - (%this.getHeight() / 2.0);
size = "2 2";
Layer = "0";
mountID = "3";
};
mountatcurrentposR(%this,(rotator@$rotators));
%this.rotator = (rotator@$rotators);
$rotators++;
}
}
function t2dSceneObject::rotateAroundTo(%this,%rot,%angVel)
{
%this.rotator.rotateTo(%rot,%angVel);
}
function t2dSceneObject::setRotateAroundSpeed(%this,%angVel)
{
%this.rotator.setangularvelocity(%angVel);
}CreateRotatorPoint takes an x and y PIXEL offset from the upper left corner. That makes it easy to lift the desired rotate-around point from photoshop or MS paint or whatever. It makes the little invisible rotator object at that location, and then mounts your thing to it with the correct offset.
For extra fun, these can be chained as much as you like. Pinball flippers and double pendulums for everybody!
#9
It makes me also understand a "standard" way that perhaps was the method discussed here before. Let's say I have a flipper of length 16 and an arbitrary height. It points to the "left" meaning it will rotate around its right edge.
I can create an invisible t2dSceneObject of size 32 by 32. Then I can mount the center of my flipper, which is the only way it mounts, in the left half of the scene object and halfway down the height. Because the flipper it 16 pixels long, it should be long enough to touch the left hand side of the scene object and go to the center of the object. When I rotate my scene object, the flipper will rotate around the flipper's right edge. To mount at this location I can set my "link point" in the scene object at (-0.5, 0) which is in object coordinates. If the object worked in world coordinates, this would be (-8, 0).
Finally, if I wanted to rotate my flipper around some point that wasn't quite the exact right edge, I would need to tweak it closer to the center of the scene object. Alternatively I could make my scene object a few pixels smaller.
04/15/2011 (1:14 pm)
Cool, Tim! I think I have this.It makes me also understand a "standard" way that perhaps was the method discussed here before. Let's say I have a flipper of length 16 and an arbitrary height. It points to the "left" meaning it will rotate around its right edge.
I can create an invisible t2dSceneObject of size 32 by 32. Then I can mount the center of my flipper, which is the only way it mounts, in the left half of the scene object and halfway down the height. Because the flipper it 16 pixels long, it should be long enough to touch the left hand side of the scene object and go to the center of the object. When I rotate my scene object, the flipper will rotate around the flipper's right edge. To mount at this location I can set my "link point" in the scene object at (-0.5, 0) which is in object coordinates. If the object worked in world coordinates, this would be (-8, 0).
Finally, if I wanted to rotate my flipper around some point that wasn't quite the exact right edge, I would need to tweak it closer to the center of the scene object. Alternatively I could make my scene object a few pixels smaller.
#10
The other method (and the one I'm using here), you mount your flipper TO a small invisible object, offset such that the invisible object ends up at the "pin point". This rotator object doesn't have to be "big enough" for the center of your flipper image to rest on top of it -- the mounting process doesn't care if the objects overlap or anything like that.
But yeah, that's the gist. Most of what my code is doing there is just centered around getting the link points from a convenient pixel offset, so that you can get the exact rotate point you want from photoshop or whatnot (even half-pixels are OK).
04/15/2011 (1:24 pm)
Hm... I'm not quite sure why you're making a 32x32 invisible object. The first method mentioned in this thread involved making the image of flipper itself bigger and full of alpha such that the center of the image IS the point you want to rotate around. Then you can just rotate it however you'd like.The other method (and the one I'm using here), you mount your flipper TO a small invisible object, offset such that the invisible object ends up at the "pin point". This rotator object doesn't have to be "big enough" for the center of your flipper image to rest on top of it -- the mounting process doesn't care if the objects overlap or anything like that.
But yeah, that's the gist. Most of what my code is doing there is just centered around getting the link points from a convenient pixel offset, so that you can get the exact rotate point you want from photoshop or whatnot (even half-pixels are OK).
#11
It took me a while to figure out that you had a flipper creating its own mount scene object. But once I got it, very clever!
04/15/2011 (2:01 pm)
I agree. I was just trying to imagine what I thought the older posters were claiming. For some reason I just didn't get it at first. I guess I'm used to graphs that allow rotation about an arbitrary point. I like your idea of a "pin point" rotator.It took me a while to figure out that you had a flipper creating its own mount scene object. But once I got it, very clever!
Torque Owner Ben R Vesco