Hi guys, I'm just wondering if anyone is able to edit the 'Rotate Towards' node to be 'Rotate Away'? The code is as follows - I'm not a programmer so I have no idea where to start Any help would be much appreciated and hopefully others might find this useful as well. Thanks, Roberto Code: // let enabled = false; let phys; let targetType; let cam; let ent; let smooth; let targetEnt; let taName; function init() { cam = this.scene().camera(); ent = this.entity(); smooth = this.attribute('Smooth'); smooth = 1 - Math.max(0, Math.min(0.99, smooth)); phys = this.entity().physics(); if (phys && phys.type() == 'kDynamic') { // warning('"Rotate Towards" node does not work with Dynamic physics.') // enabled = false; // phys = null; } else { } } function start() { targetType = this.attribute('Target'); if (targetType == 'kInputEnt') { taName = this.attribute('Target Asset').name(); targetEnt = this.scene().findFirst(taName); } } function update(dt) { if (!enabled) return; let ep = ent.position(); if (targetType == 'kCam') { if (cam.projection() == 'kOrthogonal') { let ray = cam.screenCenterRay(); let qTarg = Quaternion.lookAt(ep, ep.sub(ray.direction)); // //HARD // ent.setRotationQuat(qTarg); // //SMOOTH let qOrig = ent.rotationQuat(); ent.setRotationQuat( Quaternion.slerp(qOrig, qTarg, smooth) ); } else { //kPerspective let cwp = cam.worldPosition(); let qTarg = Quaternion.lookAt(ep, cwp); // //HARD // ent.setRotationQuat(qTarg); // //SMOOTH let qOrig = ent.rotationQuat(); ent.setRotationQuat( Quaternion.slerp(qOrig, qTarg, smooth) ); } } else { //kInputEnt if (targetEnt == null || targetEnt.isRemoved()) { targetEnt = this.scene().findFirst(taName); if (targetEnt == null) return; } let tp = targetEnt.position(); let qTarg = Quaternion.lookAt(ep, tp); let qOrig = ent.rotationQuat(); ent.setRotationQuat( Quaternion.slerp(qOrig, qTarg, smooth) ); } } function signal(name, value) { enabled = value; }
I'm not a programmer either..however, in may instances in buildbox,making it a negative number seems to work sometimes. In this case maybe a negative number would make it go away instead of towards..?
Hi Pheartok, thanks for the suggestion. I'm actually using this idea currently, but was wondering if it's actually the same as rotating away, as I was getting strange results such as objects moving towards the player much faster than they were moving away.
Hi could anyone solve this issue. I want my zombie characters to rotate towards the player and chase him but sadly the enemies are rotating away lol. so weird.