MusicallyInspired, on 27 April 2018 - 05:25 AM, said:
A function that works a lot like the con command faceplayer, but for evaldraw with the z axis included.
faceplayer3D(s) { mapgetspri(s,MAP_XYZ,&sx,&sy,&sz); dx = ipos.x-sx; dy = ipos.y-sy; dz = sz-ipos.z; ha = atan2(dy,dx)+(PI/2); va = atan2(dz,sqrt(dx*dx + dy*dy)); mapsetspri(s,MAP_HVANG,ha,va); }
My initial animation is a voxel that uses faceplayer3d, so it rotates in all three axis, it also spawns a child voxel which is positioned at the top of the parent like a hat, but using this block of code;
mapgetspri(parent[k].ind,MAP_HVANG,&ha,&va); mapgetspri(parent[k].ind,MAP_XYZ,&px,&py,&pz); mapsetspri(i,MAP_HVANG,ha,va); r = child[j].radius; va = (va+PI); ha = (ha+(PI/2)); dx = r * sin(va) * cos(ha); dy = r * sin(va) * sin(ha); dz = r * cos(va); ix=px-dx; iy=py-dy; iz=pz+dz; mapsetspri(i,MAP_XYZ,ix,iy,iz);
Using that code for the child keeps the hat on the parent voxels head, as the parent voxel moves around in the world and tilts and rolls and yaws to face the player at any angle. I've got a few other types of animations in the works, one spawns two legs that stay facing the player horizontally but oscillate a vertical rotation back and forth like walking. Next I want to make a child also be a parent and get a hierarchy structure of bones animated, like an arm with an elbow with a hand.