FixedPrismaticJoint lowerlimit/upperLimit

Topics: Developer Forum
Mar 11, 2013 at 2:05 PM
Im trying to play around with a 'FixedPrismaticJoint' to create a rectangle that moves from bottom of screen to top. In a lift type fashion.

I was just wonder what the lowerLimits and upperLimits do. Also I have notices that my lift which I am controlling its speed by its MotorSpeed does not move at a constant speed. Is there a reason why. My code for creating the joint is:

prismJoint = new FixedPrismaticJoint(elevator2.body, ConvertUnits.ToSimUnits(elevator2.body.Position), new Vector2(0, 1f));
        prismJoint.LimitEnabled = true;
        prismJoint.LowerLimit = -45;
        prismJoint.UpperLimit = 45;
        prismJoint.Enabled = true;
        prismJoint.MotorEnabled = true;
        prismJoint.MaxMotorForce = 1000.0f;
        prismJoint.MotorSpeed = -0.61f;
Thanks
Mar 12, 2013 at 6:29 PM
Looks like there are some cases where the Fixed versions of the joint are not behaving properly. See this post: http://farseerphysics.codeplex.com/discussions/431837

Not sure if that's related to the problem you're seeing, but you might try using a non-fixed version of the joint (as suggested in posts-reply) to see if that gives you better results.

Sorry I'm not more help, haven't had to use the PrismaticJoints yet in my game (but probably will before too long).

Good luck,
Mike.

http://www.youtube.com/watch?v=omjKgRen6vw
Mar 12, 2013 at 10:17 PM
Thanks for the reply. I tried using non fixed and got some erratic behaviour with my joint.
Mar 13, 2013 at 3:16 AM
I'd probably need to see more code to be more helpful. A couple of things in the code you shared look a little suspicious to me. For example, why are you converting the elevator body position to SimUnits? It should already be in SimUnits no? Also, that MaxMotorForce seems really high. How big is your elevator fixture? Are you properly using SimUnits verses ScreenUnits (i.e. keeping simunits and screenunits seperate)?

If you can post more code and/or share a video of the behavior I can try to be more helpful.

Mike.
Mar 13, 2013 at 1:19 PM
Hi Mike.
Here goes

I have a sprite class and I also have my farseer object class that inherits from Sprite class. This then enables my object to hold common data.

So this is how I create my Object:
elevator2 = new GameObject(game.Content, game.spriteBatch, world);
            elevator2.createRectObject("elevator", new Vector2(740, fltEle2), 0f, 0f, true, "elevator2");
from my GameObject that inherits from sprite
        public void createRectObject(String strFileName, Vector2 _position, float _bounce, float _friction, bool _fixedRotation, String _strObjectName)
        {

            //Creates a dynamic object that can be rotated
            this.Load(strFileName);
            //this.origin = new Vector2(this.image.Width / 2, this.image.Height / 2);
            this.position = _position;
            this.alive = true;
            this.body = BodyFactory.CreateRectangle(myWorld, ConvertUnits.ToSimUnits((this.image.Width / 2) ), ConvertUnits.ToSimUnits((this.image.Height / 2) ), 250.5f);
            this.body.BodyType = BodyType.Dynamic;
            this.body.Position = ConvertUnits.ToSimUnits(this.position);
            this.body.Restitution = 0f;      //Bounceability
            this.body.Friction = 1f;
            this.body.IsSensor = false;
            //this.body.IsBullet = true;
            this.body.UserData = _strObjectName;
        
        }
My sprite class contains the draw method:
public virtual void farseerDraw()
        {
            body.Rotation = rotation;

            p_spriteBatch.Draw(image, ConvertUnits.ToDisplayUnits(body.Position), null, color, rotation,
                    origin, scaleV, SpriteEffects.None, zindex);
        }
If you like I could email you the project so you can see how it all fits together?

Thanks for taking the time to help.

Dave
Mar 13, 2013 at 2:37 PM
Hi Dave,

Okay, I think I see a potential source of trouble. Keep in mind that I'm not a Farseer expert or anything, have just been using it for the past few months, but I suspect you're making things in your physics simulation too big/heavy to see the behavior you want. Not sure how big your Sprite textures are, but there's no real reason to use their size (even converted to SimUnits) when creating your bodies. You want the same aspect ratio for your rectangle, but the size of the body does not need to be tied to the size of the texture. The way you're doing it now, if you created a higher resolution (i.e. bigger) texture, it would change the behavior of your physics. You're already scaling when you draw, so I would recommend changing you're call to CreateRectangle so it is divorced from the size of your texture, and just adjusting your scaleV when you draw so that it is drawn at the correct size. Also, 250.5f is a very high density, and it looks like you're using it for all of your rectObjects. For reference, almost all of the densities in my simulation are less than 1f.

When creating my physics simulation I found it very helpful to think about what I was trying to create in the real world (forget about game/screen/pixels). Farseer units are meters. So when I wanted to model a motorcycle, I thought it should be about 7 feet long, so I made my body/shape to be 2 meters (called CreateRectangle with 1f for the width). Then, once you're creating things with the proper proportions and densities, its just a matter of tweaking the scale of your sprites when you draw to match what you modeling in the physics world.

Hopefully that makes sense. Long story short, I'd try tweaking your Rectangle size and density -- I suspect you might be making things too big/heavy to get the behavior you want -- an elevator 2 meters by 2 meters (about the size of an elevator you'd find in a hotel) will behave much differently from an elevator 200 meters by 200 meters (about the size of a hotel).

Cheers,
Mike.
Mar 13, 2013 at 3:20 PM
Thanks for this Mike i will take a look over the weekend. I think the density ended up that high out of frustration. Trying different values etc. But you could be onto something with the sizes. I will let you know how it turns out.
Thanks
Dave


On 13 March 2013 14:37, mheydlauf <notifications@codeplex.com> wrote:

From: mheydlauf

Hi Dave,

Okay, I think I see a potential source of trouble. Keep in mind that I'm not a Farseer expert or anything, have just been using it for the past few months, but I suspect you're making things in your physics simulation too big/heavy to see the behavior you want. Not sure how big your Sprite textures are, but there's no real reason to use their size (even converted to SimUnits) when creating your bodies. You want the same aspect ratio for your rectangle, but the size of the body does not need to be tied to the size of the texture. The way you're doing it now, if you created a higher resolution (i.e. bigger) texture, it would change the behavior of your physics. You're already scaling when you draw, so I would recommend changing you're call to CreateRectangle so it is divorced from the size of your texture, and just adjusting your scaleV when you draw so that it is drawn at the correct size. Also, 250.5f is a very high density, and it looks like you're using it for all of your rectObjects. For reference, almost all of the densities in my simulation are less than 1f.

When creating my physics simulation I found it very helpful to think about what I was trying to create in the real world (forget about game/screen/pixels). Farseer units are meters. So when I wanted to model a motorcycle, I thought it should be about 7 feet long, so I made my body/shape to be 2 meters (called CreateRectangle with 1f for the width). Then, once you're creating things with the proper proportions and densities, its just a matter of tweaking the scale of your sprites when you draw to match what you modeling in the physics world.

Hopefully that makes sense. Long story short, I'd try tweaking your Rectangle size and density -- I suspect you might be making things too big/heavy to get the behavior you want -- an elevator 2 meters by 2 meters (about the size of an elevator you'd find in a hotel) will behave much differently from an elevator 200 meters by 200 meters (about the size of a hotel).

Cheers,
Mike.

Read the full discussion online.

To add a post to this discussion, reply to this email (FarseerPhysics@discussions.codeplex.com)

To start a new discussion for this project, email FarseerPhysics@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com