Ambiera ForumDiscussions, Help and Support. |
|
|
|||||
|
I have an awesome lookToObject behavior script, but the only thing it does wrong is, when I get close to a plane, it makes it tilt back. I'd love it to stand straight even if I get close. I know I can use a billboard, but billboards don't work with shadows. Bear in mind that when you create a plane, coppercube creates it laying down instead of standing. Poor CopperCube :D - so to be upright and facing north, I had to rotate it like so: 0.0, 0.0, 90.0 see pic! here is the source code: /* <action jsname="action_LookToObject" description="Look in direction of target object 3D"> <property name="targetNode" type="scenenode" /> </action> */ action_LookToObject = function() { }; action_LookToObject.prototype.execute = function(currentNode) { var position_target = ccbGetSceneNodeProperty(this.targetNode, "Position"); var position = ccbGetSceneNodeProperty(currentNode, "Position"); var rotation = ccbGetSceneNodeProperty(currentNode, "Rotation"); pos_o_x=position_target.x-position.x; pos_o_z=position_target.z-position.z; pos_o_y=position_target.y-position.y; var dist=Math.sqrt( Math.pow( (position.x-position_target.x) ,2) + Math.pow( (position.y-position_target.y) ,2) + Math.pow( (position.z-position_target.z) ,2) ); var pi=Math.PI; var look_angle_horz=( (Math.atan2(pos_o_x,pos_o_z) )*180/pi )-180; var look_angle_vert=( (Math.atan2(pos_o_y,dist) )*180/pi ); ccbSetSceneNodeProperty(currentNode,"Rotation",look_angle_vert,look_angle_horz,rotation.z); } |
|