Limiting rotation-angle

Ok, I’m rather new with blender and this might be a newbies miss, but is there a way to in blender or using a simple python-script to limit the rotation-angle of an object? I’m creating a tank game where you control both the canon and the machine-gun and clearly those can not be allowed to be inside the tank, this would also be useful for other games like fps’s and such, to make the player not turn upside down if you move too far down or up.

I’d be grateful if someone of you guys out ther could help me with this.

I didn’t think those worked in the GE, but I don’t really know what I’m talking about. For a tank gun, I would just rotate it using an ipo.

I’ll try and see if it works.

Thanks for the answers!

Ok, i think you were right withh that it didn’t work unless i made some mistake somewere.

Also i read that if you rotate outside the limit it you have to rotate the same amount as you rotated out to be able to rotate again.

Ok, I also got another matter, making the tracks, you can’t have a tank without tracks, right. But the trouble is to make tracks that follow the ground and not when you press a button.

Do a search in the forum for a “uv scrolling script” that should take care of your track

Don’t that only scroll the texture? Isn’t it better making a chain like motion or something like that… I’m not sure how to use soft body or such, but don’t that work? :confused:

I have the same problem in a sci fi racing game. I want my vehicle to rotate over its length axis for about 30-60°. Making this rotation part of the in game control is not fun, since it does not really controls the movement itsself, it just to make it look a bit more real.

I might have to try to make a python script for this, but since I am no good at python, and only have analyzed or edited python script, it may take some time, but if anybody wants to help, I really appreciate it.

I got the basic idea, making something like “If the barrel is rotated to … degrees (something with minus) rotate around y axis 0.001 degrees when moving down (to make it not get stuck instead of using a thing that stops rotation when reaching here, it moves it out of reach for the limit, so there is no loop locking you to that angle) and make the opposite when rotating up” (and maybe with a different rotating limit)

This is how the code should look, I think… This might help someone out there who can help to create a python script for this.

Since this is very usful for just any of all first player shooters and other games were its not ok to rotate all the way around (like when you control the camera). I think that this might not only help me, but also a lot of other people trying to make fps’s and such…

I don’t know if you’re still interested in this sort of thing, but I think I’m about to write a script for the same thing. If you already have one, I wouldn’t object to some guidance. If not, I’ll let you know when I’m finished.

Well, i beleive this was covered in a previous post, you might just google this forum for stop rotation or gun rotation or tank gun rotation.

I think it was last oct/nov?

I saw a few threads that just wrote off the idea of a script in favor of IPO’s, and stuff like that. I didn’t see any that resolved the issue by limiting rotation of an object with a python script.

I thought you just wanted an answer to the problem? As per your first post. And you said you didnt know python anyway?

If you want someone to write the script for you, you should probably post your file for them. Or maybe you did that?

Anyway good luck

IPOs are definitely the easiest solution, fastest to set up, and probably near the most efficient resources-wise.

Although this method is briefly described, I thought I’d go into a little more detail to help the noobs (like me) figure this stuff out.

Sorry it’s so long winded, but I hope it helps.

In the Blender Game Engine, a “property” is something you can use to count numbers, store data, etc. In this case, we’ll be counting numbers. The thing that confused me at first was that I expected the property to be something that already existed in the game engine (like RotX, if I were doing stuff with a python script, for example) – it isn’t that way. Just remember that the property you set up is its own thing, separate from the object properties in Blender (there’s probably a way to change this with a python script or something, but I don’t know how).

So to get this rotation boundary thing to work, you need to add some numbers to your property. This is done with a property actuator. You also want to give the property some upper and lower bounds – this can be done with a sensor set to “interval.” Now the nice thing about the AND controllers is that you can wire up more than one thing on either side of it. So in my case, I wired a keyboard key (Sensor) and property interval (sensor) to an AND (controller) and that gets wired to a motion (actuator) that makes the thing move and a property (actuator) that adds numbers to my property.

So, in the game every pulse from the keyboard key moves the object 10º AND every pulse also adds 0.1 to my property. A property value greater than or equal to 1.8causes the “AND” statement to be false, thus the keyboard control stops working in that direction. (The opposite is wired for the opposite direction.)

You “visual learners” should have a look at this:

You might need to tweak the max and min values in the interval to deal with rounding errors. Selecting the “D” next to your property (on the left) displays debug info (shows you what the numbers are in real time while you’re testing your game) and is very helpful.

Let me know if you have any questions. Good luck with your projects!

Sorry for bumping the thread, but how do I set it up using IPOs? At the moment I’ve got an animation with 50 frames, frame 1 looking completely up and frame 50 looking down. What now? None of the play modes (play, pingpong, etc.) seem appropriate.

Never mind, I got it.

i dunno if anyone wil still look at this thread but…

is there anyway of doing this with a mouse look script??

If you look at Social’s fps template, it seems to have a constraint for the mouselook. I am pretty sure it is through python. Either that or properties.