Truck & trailer application?
-
Ok, I'm so confused, and need some more direction on what I'm doing wrong or where to start. This is what I think I need to do: Make a truck and trailer with a hinge joint connecting them. Create a curve path, assign the truck and trailer to that path, and animate the sequence. At the same time that animation is running, I need to move the camera on a path (preferably with SU animate), and export the entire sequence to AVI.
I've read the 3.1 FAQ, watched tutorials on YouTube, and downloaded example models. Only one of the videos I've found actually has sound or explanations, and I've found it very difficult to follow the steps people are doing. In particular, I've had very little success recreating anything with joints that I've seen in the videos. A lot of the videos I've seen show a dialog with sliders, but I've found nothing that looks like that or anything that explains what they do or how to go about creating those options. Most of the models I've downloaded from 3DW do nothing, explode, or cause a bugsplat. CurveTest3 worked for me, but the other curve tutorials give me an error about not being able to find a parent file and/or cause a bugsplat.
I have a good understanding of SU, a rudimentary understanding of ruby, and am confident I can model what I need to model if I could find any kind of resource to teach me the basics of SP. Can someone point me towards better "starter" videos/tutorials/guides or provide some feedback on viability of the process I've described above?
-
Oh I thought you already knew SP, well here is some good data:
http://sketchyphysics.wikia.com/wiki/SketchyPhysicsWiki
Look for tutorials, and then anything else you might need.I assume you have SketchyPhysics 3.2, if not try to download that too.
You could also upload your basic model here, it's easier to help out that way.
-
Mr. K, this information is exactly the place I needed to start. Thanks for the link; not sure why I couldn't find that page on my own before. I'll post a model after I get a better understanding of things. I thought I read 3.2 was still beta so I currently have 3.1 installed. I'll get the upgrade.
-
Mr. K, thanks for all your help. I've been able to figure out so much more by following those links you gave me. Is there a tutorial/guide for working with curves? I've downloaded CurveTest3 and CurveControllers1 and tried to dissect them. I can replicate what I see in CurveTest3, but I'm not sure what is happening in the controllers file.
Is there a way to define how an SP object interacts with the curve? The attached file has a simple cube, a curve, and a tutorial car. For now I just want to figure out how to move the cube along the path keeping the bottom edge of the cube centered on the curve. As you will see, the cube moves backwards from what I want and hops up and down along the curve. Eventually I would like something more complex (like the car with joints) to move along a similar path. Can you offer any suggestions?
-
Well really getting down to the basics:
-
evalCurveAbs("curve", distance) - will simply return a 3D point at the desired distance on the curve, if your curve get's flipped(as it often does) you can simply go from max to minimum distance
-
teleport( point ) - will move the SP object to the defined point, so you can move it on the start of your curve
-
position.vector_to( point ) - will get the current object(cube) position and give you a direction vector to the specified point
-
push( direction_vector ) - this will push the object in the vector direction, so now you are pushing the object towards the next point on the curve.
But push is a very floaty way of moving objects because it only adds the new vector to previous movements, that's why you get all that jumping. -
setVelocity( direction_vector ) - so for a more sturdy movement you should use setVelocity, it will negate all previous speeds and only set the new direction of movement.
I'll make some adjustments on your model and upload it later.
-
-
Here it is, with the car now being pulled and steered.
Also made a quick camera script addition.
-
Wow, thank you so much! I'm excited to dig into this and figure out how it works.
I get an error when pressing run:
Error starting simulation: : undefined method 'parent' for nil:NilClass C:Program...Plugins/SketchyPhysics3/ClassExtensions.rb:59:in 'definition'I've gotten this error numerous times when downloading for the tuts I've worked through. Usually I have to redo all the joints to get the animation to run. There must be an easier way though.
[Edit] I reconnected two joints, then turned the camera scripting on, and voila, it works! Not sure how any of the things I did actually changed anything. Thanks again, I think this will be very helpful.
-
Seems there are some odd errors going around, it may be a SU7 -> SU8 transition issue.
Oh and don't be alarmed by the flat joints I used in the model they are just the same as others, I simply changed my joints so I get a better center point overview.
-
I've made a lot of progress understanding how the various elements fit and work together. Your example has been very helpful. In the attached model I can't figure out how to make the front axle and the hinge between the truck and trailer all turn at the same time. As they are now, the two parts are connected with the ball joint, and the hinge joints work to turn the truck properly. The front wheels also turn, but are completely independent of one another. If I regroup things in a different manner, the front hinge joints turn the wheels together, but it's as if the rear hinges aren't there and the truck and trailer unit act as one. Where have I gone wrong in the various joint connections and groups I've made?
Once I have that figured out I intend to add the cab of the truck (hopefully that won't cause problems when I group additional geometry to the base that's there now. Then I think I can use the script you provided previously to move the truck along the path and pull the trailer along behind. I feel like I'm getting close.
[edit] As I've thought about this more, I believe the front axle needs to be grouped to get the wheels to turn together. When I try grouping them and leaving the joints connected as they are in the model, the wheels don't turn at all. I must not have the hinges joined to the right part of the model.
-
Hmmm... I'm not quite sure how you want this to work, because I looked at you model and to me it seems it all works as a truck and trailer should, only need a steering column on the front wheels.
So are the rear wheels suppose to steer aswell?
Or are they suppose to be attached to the trailer?
Or is it just the front wheel problem? -
I agree, it's very close. I think the front wheels should turn right or left at the same time. Right now they swivel around the hinge independently so one wheel turns left while the other turns right. Maybe it's only the steering column that I'm missing? The rear wheels on the truck and trailer are fine as they are.
-
I have it working now, at least sort of. I had to move the steering column off the model and use a box pulling the truck like you did in your example. I can hide those groups so they won't show in the final animation, but I would expect there to be a better way. So far it's been the only way I could get the front wheels to turn properly.
Another question is why the box sinks and drags the front wheels down with it. I have it set to no collision to avoid the box bumping across the ground. Is there a way to keep the wheels from sinking with the box?
Also, is there a way to increase the speed of the truck following the curve? It would be great if the speed could actually vary (slower as it comes around the corner and then increasing to approximately 30mph).
[edit] I found this explanation at google codes:
setVelocity takes a vector that is the direction the object will
#be moving and the length of the vector is how fast. It is different
#from push because it actually sets the objects velocity rather than
#just try to push it.
onstart{
setVector([0,0,10]) #set object to moving straight up at speed 10
}
The sample code you had written has setVelocity(dir.to_a). I'm a little confused why this code starts setVector, but setVelocity([0,0,10]) works as described. I assumed dir.to_a would replace the distance and direction in this code. Adding the third variable doesn't seem to do anything.
-
Ya the model is as it should be now, needs just a couple of tweaks.
- since you don't want the box to pull downwards you should just align everything at wheel height, even the curves, then it will pull at the same height
- new ball joints come with angle restrictions, best to make them 0 for this system
- you put motors on the front wheels, and motors don't like to be pulled, hinges are the best choice for this sort of setup
- you steering rack seems to be a bit off center, that messes with steering a little
The speed... well that need a bit of script tweaking, you know what I'll just add an updated example.
And I made this steering example since it requires the least code, and the rest is just plain physics, I can try set up other examples if you need them.setVelocity(dir.to_a), dir.to_a is used because dir was a Sketchup class called Vector3d(allows easy vector manipulation), but since SketchyPhysics only needs the raw numbers the .to_a addition changes that vector class into an array like [0,0,10].
I guess I could have mentioned it before, I just forget others aren't as familiar with these scripts
-
This is beautiful Mr. K! Thank you for all the examples, and for your patience as I attempt to learn the plugin. I greatly appreciate all your help.
One question about integrating this with the rest of my model... The final animation I am making needs to have the camera drive down the road towards the truck as it pulls off a side street, comes toward the camera, and passes by it. I want the camera to remain looking straight ahead and not track the truck as it goes by. I have other plugins that animate the camera and create scenes. I have read that in previous versions SP was not scene-based but it might be in the future. I see that I can export animations from SP to skp's and it will create a series of skp files with the truck moving incrementally. Without a scene-based export, it seems that I could manually create the animation by copying the truck into each scene of my base model, but that seems difficult. I know you included a camera script earlier. Would modifying that be the best way to create my animation? When I started this project I had always envisioned doing a scene-based animation; but now that I've gone the SP route I guess I may need to go totally SP to finish it.
-
I've inserted the truck into my base model, set the base terrain group to static mesh and all the other objects (buildings, light poles, cars) to ignore (I've also tried static), an when I press play nothing happens. SU just locks up. After about 10 minutes of waiting I close out and try again. The model is only 108K faces. I've tried freezing all layers except the static mesh and the truck, as well, but that doesn't seem to have any effect. Is there something I'm forgetting to do?
-
Most likely there are too many groups to handle or your static-mesh is too complex(too many faces), that is usually the problem of freezing on startup.
It's best to make statimesh only the portion of road you really need, and set all non essential groups/components to ignore.As for the camera, well the example script should work quite well, as long as you give it a good curve to follow.
Exporting the animation tho I have no clue about, haven't used that myself, but I know there are alot of threads on these forums about those things.
-
I know you may not have much experience with exporting, but I can't find much on Sketchy Replay in the forums. Is there a reason that the exported images using Sketchy Replay wouldn't follow the camera? Yesterday I had everything working perfectly, recorded the animation and exported to jpgs. But when I opened the jpgs this morning I see the objects moving, but the camera is located in a random position off to one side, not following the desired object as the on-screen animation showed. Maybe I need to try a screen-capture program to get the animation.
For some reason after that export fiasco, without saving the model, the curve I want the camera to follow has now reversed. Is there a way to force a curve to reverse? It doesn't seem to matter which way I draw it, SP always assumes the opposite end is the beginning. I have tried modifying the speed control script to use the max_distance-frame script you wrote earlier, but adding those lines seems to disable the script altogether.
-
Ya SP recording doesn't have on option to add camera recording, I guess in this case that is quite crucial... I don't know howmuch work it would be to add this, but I'll have a look at the files.
You could also record it with Fraps, not really ideal but it's the only thing I know.Curves tend to flip directions at random, and not just when created but also when you open/close the file, it can't really be helped because only SU has full control over curves, so scripts need to be adapted.
If you can't fix the script make a model with just the curve in question and your scripted object and I'll fix it up to work. -
Yeah, recording the camera view is really important. I have a screen recorder so if I can get the camera and curves working properly, I think I can get something usable, even if the files can't be modified.
I attached a file with the curve reversed. The model actually contains two curves, an "original" that follows the terrain and a "simplified" that is a roughly straight-line approximation of the original. My first intention was to have the camera follow the actual terrain so I would have a constant 5' eye height, but the one time I actually got everything to work correctly that seemed to create jitters in the camera that I didn't like. So if the simplified curve will be smoother, I'm fine with the relatively constant eye height. I replaced the camera script I had tried previously with the one you wrote for softsoap. I only need the camera to move along the curve. The box pulling the car is only there because I want the view angle of the camera to adjust to the curve as it wiggles near the end, and to help achieve the more accurate eye height described above. Using the steering column is the only way I've been able to get the camera angle to adjust in that manner. Other than that, I have no need for the "car" itself.
I am using your "speed control" script with the max_distance-frame lines added to try and reverse the curve. When I switched the equation to read distance=(frame-max_distance) the camera stayed at the proper end of the curve, but did not actually move as desired.
-
Alright did a quick fix up of SP files to add camera recordings, but make sure you backup your original files in case this doesn't work for you.
So make sure you backup your /Sketchup/Plugins/SketchyPhysics3 folder, and then extract these two files in there.
Advertisement