ambiera home ambiera home

Ambiera Forum

Discussions, Help and Support.

Create a new account, Search, or Login:
Name:  Password:
Ambiera Forum > CopperCube > Help with CopperCube
freeze y?
Author Text

aloan
Registered User
Quote
2019-09-11 22:39:58

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);
}


Create reply:


Posted by: (you are not logged in)


Enter the missing letter in: "Internat?onal" (you are not logged in)


Text:

 

  

Forum Codes


Feature Code
Link [url] www.example.com [/url]
Bold [b]bold text[/b]
Image [img]http://www.example.com/image.jpg[/img]
Quote [quote]quoted text[/quote]
Code [code]source code[/code]

Emoticons


   





Software: Ambiera Light Forum. © 2008-2019 Nikolaus Gebhardt, Ambiera e.U.