I called it getObjectsInRoom, but you could also call it getAllOjects. It should return a list of potential objects that could be intersecting with the segment. It could be the list of all objects in the game (that would be slower, but it's a good first value).CRxTRDude wrote:@kikito Hello again, i saw the code, it's looking fine, but i saw getObjectsInRoom and i don't know what function it is ... Is that a set of tables or something else?
[SOLVED] Collision Line (or something similar)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: Collision Line (or something similar)
When I write def I mean function.
Re: [SOLVED] Collision Line (or something similar)
Hey guys, for my implementation, I'll share it to you guys:
All of these are in the enemy's code, not the player's code!
For the distance check:
from this site...
as usual [x1,y1] is the player's coords and [x2,y2] is the enemy's.
then the y check:
this checks if the player's is hit vertically by your enemy, the code here gives the enemy a range of 150 px for his vertical LOS.
finally, the code for facing:
Found this from a GM tutorial. This will check if the player and enemy are facing each other.
Now for implementing it to the code:
That's my implementation so far. If it's helpful to some, use it. But remember to credit me for some of that. (I placed it in QUEUE and it's under the MIT license so you can use it anytime, but credit it. See this for details.)
All of these are in the enemy's code, not the player's code!
For the distance check:
Code: Select all
function Thug:curDist(x1,y1,x2,y2)
local calc_x = math.abs(x1-x2)
local calc_y = math.abs(y1-y2)
local calc = math.sqrt((calc_x^2) + (calc_y^2))
return math.floor(calc)
end
as usual [x1,y1] is the player's coords and [x2,y2] is the enemy's.
then the y check:
Code: Select all
function Thug:yHit()
if ((p.y+150) >= (self.y)) and ((p.y) <=(self.y+32)) then
return true
else return false
end
end
finally, the code for facing:
Code: Select all
function Thug:getPlayerFacing(pl)
local facing = false
if (self.x_vel < 0) and (pl.x < self.x) then
facing = true
elseif (self.x_vel < 0) and (pl.x > self.x) then
facing = false
elseif (self.x_vel > 0) and (pl.x > self.x) then
facing = true
elseif (self.x_vel > 0) and (pl.x < self.x) then
facing = false
end
self.towards = facing
end
Now for implementing it to the code:
Code: Select all
dist = self:curDist(p.x, p.y, self.x, self.y) -- updates the player's distance
self:getPlayerFacing(p) -- my implementation of if the enemy faces the player.
-- check your distances
if self.towards and self:yHit() then -- using our vertical LOS and a towards check
if dist <= 150 then -- the distance is just close enough...
self.state = 2 -- to start a chase
end
end
~ CRxTRDude || Will be out of touch for a wee longer than expected. Will keep in touch with soon enough. Sorry bout that.
Who is online
Users browsing this forum: Google [Bot] and 1 guest