Follower units have a following glitch

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
HedgeHog builder
Prole
Posts: 15
Joined: Sat Aug 19, 2017 9:13 am

Follower units have a following glitch

Post by HedgeHog builder »

What is supposed to happen:
The follower is supposed to be following the mouse-controlled player but suffers from glitches.

Glitch 1
The follower does not move vertically. That is, it does not move up and down regardless of where the player is.
Glitch 2
The follower only follows you to the right if you are below it.
Glitch 3
The follower only follows you to the left if you are above it.

If you are on the same vertical plane, it does not do anything.

Where to look

Code: Select all

	for p,v in ipairs(Spawned_Units) do
	local speed = 150
	if v.x > follow.x then
	v.x = v.x - (speed*dt)
	end
		if v.x < follow.x then
	v.x = v.x + (speed*dt)
	end
		if v.y > follow.y then
	v.x = v.x - (speed*dt)
	end
		if v.y < follow.y then
	v.x = v.x + (speed*dt)
	end
	end
Guesses where/what it might be wrong
In the unit control section.
It could be a problem with my 'end' commands, stopping the program from completing other tasks

Whole code
Attachments
main.lua
(3.33 KiB) Downloaded 95 times
User avatar
Tjakka5
Party member
Posts: 243
Joined: Thu Dec 26, 2013 12:17 pm

Re: Follower units have a following glitch

Post by Tjakka5 »

In the snippet you posted your vertical checking if's are changing the 'x' values. Swap these to 'y' and it should fix all your issues.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 92 guests