Rick Posted November 13, 2013 Share Posted November 13, 2013 I'm playing around with a physics camera for an RTS style (top/down angled). I'm setting a high friction value but that still doesn't seem to make the camera stop smoothly when I release the keys that move the camera. Any ideas on how to get a smooth start/stop using a physics camera? When I let go of the keys I'd want maybe 1-2 seconds of small movement in the same direction from the point at which I let go of the keys. Also I'm just adding force while the keys are down so it gets faster and faster. I like the idea of acceleration but only to a point where I'd want to maintain that velocity and never go over it. Quote Link to comment Share on other sites More sharing options...
Rick Posted November 13, 2013 Author Share Posted November 13, 2013 Does the SetFriction() function even work? The value I pass to the keneticfriction param (the one that as I understand stops the physics body when I stop applying force) is 50000000 but no matter how many more zeros I add the body still slides way too long after I let go, and I was able to cap the velocity of movement so it's not moving that fast. Quote Link to comment Share on other sites More sharing options...
tjheldna Posted November 13, 2013 Share Posted November 13, 2013 I'm using set friction for an entity however the values are more like this. For me it is making a difference. entity->SetFriction(0.05F, 0.05F); Quote Link to comment Share on other sites More sharing options...
Rick Posted November 13, 2013 Author Share Posted November 13, 2013 What's the force you are adding to it? What's the mass it has? Also note that I'm not applying gravity so it's not moving against the ground, which might add extra friction? Quote Link to comment Share on other sites More sharing options...
tjheldna Posted November 14, 2013 Share Posted November 14, 2013 mass = 100 move speed = 1.7 gravity = true Quote Link to comment Share on other sites More sharing options...
Admin Posted November 14, 2013 Share Posted November 14, 2013 I would use the Math::Curve function for this rather than physics. Quote Link to comment Share on other sites More sharing options...
Rick Posted November 14, 2013 Author Share Posted November 14, 2013 Yeah, it seems I will have to do that. Although it would seem one should be able to get the physics to do this. I don't know why it slides for so long after not applying force to it. Quote Link to comment Share on other sites More sharing options...
Flexman Posted November 14, 2013 Share Posted November 14, 2013 Isn't linear and angular damping different from friction? Friction is applied when a body interacts with another body. Dampening occurs over time. Just a thought. Not sure what you're doing with your camera. edit: Oh I just looked at the Leadwerks 3 commands, are there any commands for setting linear and angular dampening like you can in LE2 using SetBodyDamping()? It's not obvious to me. edit2: I guess you could just multiply the velocity of the body by a value less than 1.0 in an UpdatePhysics() callback. That would do it. 1 Quote 6600 2.4G / GTX 460 280.26 / 4GB Windows 7 Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT Tricubic Studios Ltd. ~ Combat Helo Link to comment Share on other sites More sharing options...
Rick Posted November 14, 2013 Author Share Posted November 14, 2013 I guess I thought the friction settings would be applied no matter what but maybe I'm wrong. Quote Link to comment Share on other sites More sharing options...
Admin Posted November 14, 2013 Share Posted November 14, 2013 Friction only effects an object sliding along a surface. It isn't air resistance. Quote Link to comment Share on other sites More sharing options...
Rick Posted November 14, 2013 Author Share Posted November 14, 2013 Is there any air resistance available? Dampening as Flex put it? Seems like it could have some uses. I'm sure I could do it by applying opposite forces, but that's seems like a pain. Quote Link to comment Share on other sites More sharing options...
Josh Posted November 14, 2013 Share Posted November 14, 2013 This will do it, if you can get to the Newton body object: http://newtondynamics.com/wiki/index.php5?title=NewtonBodySetLinearDamping Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Flexman Posted November 14, 2013 Share Posted November 14, 2013 If you can do what Josh says, that's the easy option. If that fails you don't need to apply opposite forces. Just multiply it's own force by a smaller value than 1.0 psudo code... cameraBody->SetVelocity( cameraBody->GetVelocity() * (0.9 * appspeed()) ); Do that when not moving the camera. Might want to add commands to set the dampening values to the suggestion box. I suspect AddForce is not what I think it is. It reads like it's additive rather than absolute. BUT if you have write access to the velocity properties (can't test atm) it should be easy to multiply those values by 0.9 every frame to reduce them close to zero over time. You don't notice missing commands until you try and do something that needs them. Quote 6600 2.4G / GTX 460 280.26 / 4GB Windows 7 Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT Tricubic Studios Ltd. ~ Combat Helo Link to comment Share on other sites More sharing options...
Rick Posted November 14, 2013 Author Share Posted November 14, 2013 I just want to see if I can get this working with physics now I'll check out setting velocity directly to slow it to zero when not pressing a key down. If not opposite force should basically do the same thing although I have a feeling I'll always get more sliding than I want when trying to stop :-/ Quote Link to comment Share on other sites More sharing options...
Admin Posted November 14, 2013 Share Posted November 14, 2013 Use SetVelocity, not AddForce. Adding a force would make the object get faster and faster. Quote Link to comment Share on other sites More sharing options...
Rick Posted November 15, 2013 Author Share Posted November 15, 2013 _pivot->SetVelocity(_pivot->GetVelocity() * (0.9 * Time::GetSpeed())); This works but it's an instant stop which I find odd. I would think it would take longer to reduce it to zero. Quote Link to comment Share on other sites More sharing options...
Flexman Posted November 15, 2013 Share Posted November 15, 2013 It's possibly not working because my psudo code above didn't take into account that GetVelocity returns a vector. You need to multiply the returned velocity. Vec3( 0.9 * Time::GetSpeed() , 0.9 * Time::GetSpeed() , 0.9 * Time::GetSpeed() ) You can't multiply a Vec3 by a single value and expect a Vec3 in return. If your code is LUA you're passing a weird value and that's why it's coming to a halt. Quote 6600 2.4G / GTX 460 280.26 / 4GB Windows 7 Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT Tricubic Studios Ltd. ~ Combat Helo Link to comment Share on other sites More sharing options...
Rick Posted November 15, 2013 Author Share Posted November 15, 2013 I'm pretty sure Josh overloaded the multiply operator on Vec3 class otherwise I'm thinking this wouldn't even compile. I'm using C++. Quote Link to comment Share on other sites More sharing options...
Flexman Posted November 15, 2013 Share Posted November 15, 2013 C++? Oh...you should be good then. I'm guessing you tried a range of values then? 0.999 etc. When in doubt (C4) debug the hell out of it. Quote 6600 2.4G / GTX 460 280.26 / 4GB Windows 7 Author: GROME Terrain Modeling for Unity, UDK, Ogre3D from PackT Tricubic Studios Ltd. ~ Combat Helo Link to comment Share on other sites More sharing options...
Rick Posted November 15, 2013 Author Share Posted November 15, 2013 Yeah, I did a little debugging but because it's tied to key presses it's a pain to do normal breakpoints and step through because code runs when no key is pressed which stops it completely. I will need to print values out but I was lazy last night and just watched a movie instead I'll see what my motivation is like tonight. Thanks for the help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.