glitch in my code
Blitz3D Forums/Blitz3D Programming/glitch in my code
| ||
Jsut wondered if anyone can help me fix this. It works kind of, but instead of the enemy retreating back to his litle base when i get out of his view, he looks up to the sky and moves off to the middle of the map somewhere. There are no entities where hs is trying ot go, so I am totally confused now. He just ignore his base. While Not KeyHit(1) If EntityVisible (Enemy1\model,player1\model) MoveEntity Enemy1\model,0,0,.1 PointEntity Enemy1\model,player1\model;Turn towards player If Animating(Enemy1\model)=Enemy1\walk Animate Enemy1\model,1,.7,1;walkforward EndIf EndIf If Not EntityVisible (Enemy1\model,player1\model) Animate Enemy1\model,3,0,1,5;walk PointEntity Enemy1\model,enemybase;Turn towards enemybase MoveEntity Enemy1\model,0,0,.1 EndIf If EntityDistance (Enemy1\model,player1\model)<=5 MoveEntity Enemy1\model,0,0,-.1 Animate Enemy1\model,1,0,3,5;stopped/idle EndIf |
| ||
You should save that source code. You may have discovered a sentient being with a mind of its own. Real AI. |
| ||
Perhaps enemybase should be Enemy1\base? Also you really should use if, else, end if, instead of doing two EntityVisible calls. Like this: If EntityVisible (Enemy1\model,player1\model) MoveEntity Enemy1\model,0,0,.1 PointEntity Enemy1\model,player1\model;Turn towards player If Animating(Enemy1\model)=Enemy1\walk Animate Enemy1\model,1,.7,1;walkforward EndIf ; I moved this... If EntityDistance (Enemy1\model,player1\model)<=5 MoveEntity Enemy1\model,0,0,-.1 Animate Enemy1\model,1,0,3,5;stopped/idle EndIf Else Animate Enemy1\model,3,0,1,5;walk PointEntity Enemy1\model,enemybase;Turn towards enemybase MoveEntity Enemy1\model,0,0,.1 EndIf |
| ||
Abba rue I am pretty new to this, So My code is obviously very basic.I am sure there are much better ways to do it, but I am learning a bit by doing it myself this way. Fredborg, thanks. I had to break it down like this becase I am having trouble making the animations work when they should. it really bugging me. The base thing is just winding me up. i tried using 'tree1' instead of 'enemybase'(naming convention isn't important here) and its doing the same thing ie looking towards the skybox for some bizarre reason and totally ignoring the 'base' I will try the 'else' way , I will let you know How I get on .cheers |
| ||
Also wondering why you have to do this If Animating(Enemy1\model)=Enemy1\walk Animate Enemy1\model,1,.7,1;walkforward Rather than just this Animate Enemy1\model,1,.7,1;walkforward This doesn't work by itself , can't figure out why, but the first one works fine. the '1' at the end should give it the correct sequence and make it animate. |
| ||
Try adding a:Debuglog "Enemy is moving towards "+EntityName(enemybase)+" at ("+EntityX(enemybase,true)+","+EntityY(enemybase,true)+","+EntityZ(enemybase,true)+")"To your 'moving towards base' code, or print it to the screen each frame... |
| ||
will do fredborg, will try it tomorrow. |
| ||
I was implying that sometimes a glitch can turn out to be a new feature, not insulting your code attempts. |
| ||
ahh,I see AbbaRue, thought you were taking the mick. To be fair though I don't know a lot, but am getting to grips with tpyes right now. The syntax is buggin me though. Like if I use Enemy1\model in the main loop it works , but if I use it inside a function say ,UpdateEnemy() I get error message 'variable must be a type' .Driving me mad because Enemy1\model is a a type Hope my numerous coding mistakes do in fact turn out to be a new form of ai , doubt it somehow. |