Hi, I have just got a script from MarcoIT, it’s a very nice script but it has a lot of glitches and it’s not that smooth. It’s for my 3rd person camera set up. If it’s complete, I’m sure to share it at the resources forum. It has some problems like: The camera doesn’t rotates quickly when the mouse is moved. The camera rotates very rigid, not smooth, stiff, you know what I mean. And I don’t need the camera scroll(for my game) but I’m sure a lot of people would like that. Please help me, this is just not for me.
Here is the script:
""" ->> Blender version 2.59.1 <<- \ \
| Created by MarcoIT 23/10/2011 / /
| \ \
|SETUP: parent the camera to player-obj/ /
|sensors-----> Always/True \ \
|controller--> Python/Script / /
"""#WWWWwwwwWWWWwWWwwwwWWWwwWWWwwwwWWWwWW
def main():
import bge
from mathutils import Vector as VEC
ob=bge.logic.getCurrentController().owner
mouseEv=bge.logic.mouse.events
#speed SETUP
speed=2 #from 0 to infinite(default=2)
########
x=0.5-bge.logic.mouse.position[0]
y= 1-bge.logic.mouse.position[1]
#first step only
if not "init" in ob:
ob["init"]=[ob.parent,ob.getDistanceTo(ob.parent)]
bge.logic.mouse.position=(0.5,0.5)
ob.removeParent()
x=0
y=0
#recurrent variable
dist=ob.getDistanceTo(ob["init"][0])
diffz=dist-ob["init"][1]
#move camera
ob.worldPosition+=ob.worldOrientation*VEC((x*speed*dist,-y*speed*dist*0.25,-diffz))
#rayCast
ray=ob.rayCast(ob,ob["init"][0])
if ray[0]!=None :
ob.worldPosition=ray[1]
else:
if mouseEv[193]!=0: #roll UP
ob.worldPosition+=ob.worldOrientation*VEC((0,0,-0.04*speed*dist))
ob["init"][1]=ob.getDistanceTo(ob["init"][0])
elif mouseEv[194]!=0: #roll DW
ob.worldPosition+=ob.worldOrientation*VEC((0,0,+0.04*speed*dist))
ob["init"][1]=ob.getDistanceTo(ob["init"][0])
#realign the Camera
v=1-abs(ob.worldOrientation[2][2])
v=max(v,0.3)
vec=ob.getVectTo(ob["init"][0])
ob.alignAxisToVect([0,0,1],1,v)
ob.alignAxisToVect(vec[1]*-1,2,1)
bge.logic.mouse.position=(0.5,1)
main()
I’d like someone to simplify it or simply fix the problems. I’m not a programmer but I understand some python. I don’t trust myself on python, lol. I know it’s a bad habit, but could someone just fix this?
BTW. Here is a blend if anyone is just too lazy to set it up. LOL. 3rdPersonCamera.blend (433 KB)
Move the mouse when the game starts, the camera doesn’t quickly move. BTW. This script is from MarcoIT. Thanks Marco.
Script looks OK. The setup is a bit broken. If I run the script on a pulsing always sensor it is much better - now the camera is only updated when the mouse moves and that’s feels odd.
Having a script running every tic I would handle the movements in it to - much easier to get what I want. Right now the setup use loc movement and that will cause collision glitches sooner or later.
seems strange to me, what he says, fullgrown.(probably in my PC work differently)
is true, there is some small inaccuracy, (which has not mouselook)
when the cam is high, but not very noticeable …
I doubt that is any object that creates a conflict … (or a different version of blender? i made it with 2.59.1)
Also make sure that the mesh of the player, are no-collision
otherwise, the ray sees it as an obstacle …
however, to make it more readable
can be replaced
ob[“init”][0]
to
ob[“target”]
and
ob[“init”][1]
to
ob[“distanceTarget”]
Unfortunately I can not change the original mouselook … otherwise I would have done;)
@LaH I do know that loc movements are glitchy, I just set it up so that I would get it posted already. My problem is, the camera is laggy and not responsive. I tried the always sensor with true pulse set to 0, but I guess there are minimal differences. Could anyone polish it? Or atleast simplify it?
It is already simple - and true pulse should be on.
The only other problem I can see is not with the camera but with the character movement. When turning the rotation of the character lags, so the visual feedback indicates it turns in the wrong direction.
That’s why I suggest controlling the characters movement from the same script - but it will not make it simpler.
Only when I run the script from the mouse sensor. Then, if I did not move the mouse, the camera don’t move at all - even if I move the character with the arrow keys. That feels real odd. But else it is fast and responsive. Only took a quick look and I’m at another computer now - can look at it again tonight.
now I have tried to “copy and paste” the script on new blend.
I see both the “glich”, and also that the cam continues to move!!!(anything good! )
then a small delay is to put into account (difficult to solve)
This delay may increase,
if the camera object is executed before to the object player (I think this is random)
in this case delay is doubled…
while for the continuous movement, I’m not sure, what is due.
In fact, in the first version, I’d put the variables(if x!=0 or similar), in order to avoid this problem.
then, after, it seemed that it worked anyway(without this variable), and then I removed.
while now is returned
then you can improve, but probably
bit delay remain
well!
I took the old script (other TD), I added a few pieces of the new one.
In short, now seems to work fine.
(attention, if copy and paste the code on another blend, the player obj, MUST be no collision (at least with this script, maybe you can add more property to raycast ()))
a little lag (1 frame) Always Remain
it is not solvable (pratically)
If I run in the BGE and not blender it’s a problem that the mouse is positioned at 0.5, 1.0 instead of 0.5, 0.5 - so You can only lower the camera - not rise it.
But I don’t notice lag - but it might take more environment to really notice it.