Jump to content

#1
Slastraf

Slastraf
  • Members
  • 322 posts
I have a few turrets and some enemies just with health and the walk in a circle.

http://pasteboard.co/LnHZqB1OU.gif

As one can see from the gif , when one turret is in the scene it is turning smoothly.
But when multiple ones are spawned, they only update once in a while.

The line uses Point() and looks like this :

if self.target then
   self.entity:Point(self.target.entity,2,Time:GetSpeed()*0.1)
end

How can i fix / optimize this ?

The gif is (only) 6 mb but it takes long to load, sorry for this.

#2
macklebee

macklebee
  • Members
  • 3,527 posts
How is the 'self.target' being set? If by pick, maybe some of the turrets do not have a target or only see a target occasionally if the pick's collisiontype is hitting the turrets? Hard to tell without actual example or code to try.

#3
Slastraf

Slastraf
  • Members
  • 322 posts

View Postmacklebee, on 19 March 2017 - 06:14 PM, said:

How is the 'self.target' being set? If by pick, maybe some of the turrets do not have a target or only see a target occasionally if the pick's collisiontype is hitting the turrets? Hard to tell without actual example or code to try.
Its the same script as here, it performs AABB
http://www.leadwerks.com/werkspace/blog/1/entry-1671-building-the-turret-ai/
but at the first line I added
if extra.script.target == nil then
because the method would be called too often resulting in a crash,  if multiple enemies are nearby

#4
macklebee

macklebee
  • Members
  • 3,527 posts
That script posted in that blog is a WIP that is missing alot of features that its supposed to do - no check of team ID, no occlusion check, no rotating the turret... etc... Again, without an actual example or code to try, it makes it hard to troubleshoot.

Edit-- I assume you are using the updated code shown here? http://www.leadwerks.com/werkspace/blog/1/entry-1673-building-turret-ai-part-2/

And if that is the case, then it performs a pick that may not see an enemy. Your example 'gif' has everything ontop of each other. Try spreading the turrets out and put the targets in the center to see if this helps your situation. Also note what Josh posted at the beginning of the blog:

Quote

"To avoid overloading the engine I am only performing the visibility test at most once every 500 milliseconds.  This provides near-instantaneous updating while preventing the picking from becoming a bottleneck and slowing down performance."
You may need to increase this time if you are performing so many picks.



Also tagged with one or more of these keywords: Point, Turrets