|
HOKAY, so here's my issue. In the following code, I'm having an issue where I don't want to use the smooth camera (mostly because I hate the look of it), so I found some nice code for a camera that "slides" into place whenever you turn. It really looks quite nice when you're turning. Unfortunately, whenever you stop moving, the camera still attempts to slide into place, even though there's nowhere to slide. This causes it to slowly flip-the-hell-out, shooting from side to side. It also has the issue that when you first get into car, it's always facing to the side, rather than just automatically setting behind the car. Halp plz!
(comments are locked)
|
|
If your currentVelocity is 0, newPosition and newTargetPosition will refer to the same location. At the end of your code you set the transform's position to newPosition, and then try to look at newTargetPosition, which in this case, is the same point. I am not sure how transform.LookAt() behaves in such a case, but in theory it should be undefined, because it can't determine a viewing direction if your position and the lookat-target are identical. Similarly, I can well imagine that transform.LookAt() will start to behave unpredictable and jerky once currectVelocity approaches zero (for example if the car slows down and stops), since the length of the viewing direction vector, required to determine the transform's rotation, will also approach zero. A solution to this dilemma could be, to define a "forward" direction, and always subtract this forward vector (or a fraction of it) from newTargetPosition. This will not only prevent the zero-length problem, but also solve the issue of initial orientation, and making sure that your follower will always adjust itself directly behind your object, looking towards it, once your object becomes static.
(comments are locked)
|
|
I suspect that this might be a "physics" issue rather than a camera issue. You should assure that's the case or not by attaching the camera script to a static object in the scene. If the issue is physics related (it's your camera's target jittering, not the camera), you'll need to tweak your camera target's motor. On the other case, you might just need a dampener value for your camera interpolations which are possibly better off like
oh and regarding the camera's initial rotation: let's just solve one problem at a time I'm pretty sure you were right. Now, I was a bit lazy and tested this by setting the .isKinematic setting to true on the car, making it completely immobile. This would have the same effect as attaching it to a static object, correct? If it is, then I'm a bit curious as to what sort of tweaks I would make to the car's motor. Also, haha, sorry in advance if these are dumb questions - I'm new to programming, and was just sorta thrown into this project, so it's a mildly daunting thing for me right now - still trying to get used to the whole "using a game engine" thing!
Aug 17 '11 at 02:03 PM
Kulahan
heh, yeah, setting iskinematic is equivalent to reattaching the camera. regarding the car's motor fix, you need be sure that rigidbodies have proper weights in your gameobject. One thing that's commonly ignored is that the MASS parameter is in kilograms, and if all your rigidbodies have 1 mass they actually weigh 1 kilogram! Of course you need to properly set all vehicle values to be sure that the engine has no trobule stabilizing. So you can try to set the wheels to, say, 2.5 mass, and the vehicle to 100 mass (docs suggest to avoid mass differences of more than 100 units).
Aug 17 '11 at 04:05 PM
roamcel
Interestingly enough, I'm not 100% sure that anything on the car other than the wheels even has a mass. They've all got a mass of 3 themselves, but I wonder if that's the issue?
Aug 17 '11 at 07:20 PM
Kulahan
(comments are locked)
|
