point enitity
Blitz3D Forums/Blitz3D Programming/point enitity
| ||
Im creating a 3D Verlet Ragdoll and what Im trying to do is point an entity at another entity (or point it at xyz, doesnt matter), I have tried using pointentity command and also the following code found in the archives :- ;=========================== ;Point Entity at x,y,z ;=========================== Function Point_Entity(entity,x#,y#,z#) xdiff# = EntityX(entity)-x# ydiff# = EntityY(entity)-y# zdiff# = EntityZ(entity)-z# dist#=Sqr#((xdiff#*xdiff#)+(zdiff#*zdiff#)) pitch# = ATan2(ydiff#,dist#) yaw# = ATan2(xdiff#,-zdiff#) RotateEntity entity,pitch#,yaw#,0 End Function ;=========================== But when both the entity and target are moving, the entity tracks the target and points at it, but it sometimes spins (thats the best way to describe it), this happens when using both the above methods. I've tried using aligntovector but no success. Has anybody else come across this problem and managed to find a solution. |
| ||
The only trouble with pointing one entity at another is that the roll of the entity can end up being anything - this is probably the spinning you're talking about. Just off the top of my head, try adding the following after pointing the entity at the target: RotateEntity ent,EntityPitch(ent,True),EntityYaw(ent,True),0,True Does that help? Probably not. lol. :) |
| ||
Thanx big10p, but unfortuanately that didn't fix it, and thanks for the speedy response. |
| ||
Use this instead ... should be quicker too.global PIVOT = createpivot() ;=========================== ;Point Entity at x,y,z ;=========================== Function Point_Entity(entity, x#,y#,z# ) positionentity PIVOT, x, y, z Dy# = deltayaw( entity, PIVOT ) Dp# = deltapitch( entity, PIVOT ) turnentity Entity, Dp, Dy, 0 End Function ;=========================== |
| ||
Stevie, you've come to my rescue once again, cheers mate, works great. I'll soon be giving your ragdoll-'Bender' a run for his money. oops, spoke too soon, its still has a spin to it. If I put this code in on its own, my entity seems to rotate out of control, if i put it after pointentity command, then I get the same results as before. |
| ||
I've believe I've used this ones - in psuedo: pointentity ent, Target p = entitypitch(ent) y = entityyaw(ent) rotate ent, p,y,0, 1 or if you have a vector, reset the object before pointing: rotate ent,0,0,0, true aligntovector ent, xvec,yvec,zvec, 1 (xaxis / pitch) aligntovector ent, xvec,yvec,zvec, 2 (yaxis / yaw) hope this helps (sorry was in a hurry ;) d. |
| ||
Is the entity you're rotating parented to another entity? If so then you probably just have to use the global flag for turnentity. |
| ||
Thanks Danny, the "pointentity" code worked but not the vector one, which is a shame because the vector one would of been faster and would of saved me aditional work creating pivots for the enity to point at. @ Stevie G, Stevie, no the entity is not parented to anything, just positioned at the verlet co-ordinates and constarined to the tail verlet, I dont know why it didn't work, especialy if your using similar code. |