a quick pathfinding question before I go to sleep

0 favourites
  • 6 posts
From the Asset Store
The ultimate voice pack filled with 1,536 files of .......wav and mp3 of individual numbers, letters, and words (that go
  • So I created a way to make my object find path towards the closest target then move towards that path, the problem is the target position is always changing so it have to change it paths then move to it again, this cause the object to pause for a moment making the movement a bit annoying here is an example video

    :LINK:https://youtu.be/QNntToljCpg

  • Can I see the code?

  • Can I see the code?

    here

    let allEnemies = [];
    let targets = [];
    
    export function findTarget(AllEnemies,runtime){
    	
    	var tempTargets = runtime.objects.Plant.getAllInstances();
    	tempTargets.push(runtime.objects.Nyardo.getFirstInstance());
    	tempTargets.push(runtime.objects.Tree.getFirstInstance());
    	
    	var player = runtime.objects.Nyardo.getFirstInstance();
    	
    	allEnemies = AllEnemies;
    	
    	allEnemies.forEach((enemyInstance) => {
    	
    	var dists = [];
    		
    		if(enemyInstance.x != null){
    		
    		tempTargets.forEach((targets) => {
    	
    		const distance = calculateDistance(targets.x,targets.y,enemyInstance.x,enemyInstance.y);
    	
    		dists.push({TargetUID: targets.uid , TargetDistance: distance , targetX: targets.x , targetY: 				targets.y});
    	
    		});
    		
    		}
    	
    	
    	
    	const thisEnemyTargetDistance = Math.min(...dists.map(obj => obj.TargetDistance));
    	const foundTarget = dists.find(obj => obj.TargetDistance == thisEnemyTargetDistance);
    	
    	enemyInstance.instVars.targetX = foundTarget.targetX;
    	enemyInstance.instVars.targetY = foundTarget.targetY;
    	
    	
    	console.log(foundTarget);
    	
    	
    
    	
    	});
    
    	
    	targets = tempTargets;
    	allEnemies = AllEnemies;
    
    
    
    }
  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • How do you actually move the enemies though, I'm assuming pathfinding behavior? That's just the code for finding the targets, which looks fine.

    I think what might be the issue in your case is a setting in the pathfinding behavior, specifically the "rotate object" setting, which you can probably disable in your case. Or it's the acceleration being too slow, and you could increase it.

  • How do you actually move the enemies though, I'm assuming pathfinding behavior? That's just the code for finding the targets, which looks fine.

    I think what might be the issue in your case is a setting in the pathfinding behavior, specifically the "rotate object" setting, which you can probably disable in your case. Or it's the acceleration being too slow, and you could increase it.

    I've set it like this so it will check every tick if the enemy has a path to move through I'll try doing what you've said and the rotation is already disabled and about the speed, I'll try manipulating it thanks for the idea!

  • That's not how triggers work, you don't need that every tick. Although it doesn't appear to cause any issues either.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)