ID:1670551
 
(See the best response by Kaiochao.)
Problem description:Basically, this verb pounces on any mob that you are within 3 tiles from. But if someone is on the opposite side of a door, some reason they can still jump through them. Same with my walls, even though their density is at 1 and you can not walk through them.


Code:
/mob/living/carbon/alien/humanoid/hunter/verb/pounce()
set name = "Pounce (50)"
set desc = "Pounce onto your prey."
set category = "Alien"

if(usedpounce >= 1)
src << "\red We must wait before pouncing again.."
return

if(powerc(50))
var/targets[] = list()
for(var/mob/living/carbon/human/M in oview())
if(M.stat) continue//Doesn't target corpses or paralyzed persons.
targets.Add(M)

if(targets.len)
var/mob/living/carbon/human/target=pick(targets)
var/atom/targloc = get_turf(target)
if (!targloc || !istype(targloc, /turf) || get_dist(src.loc,targloc)>=3)
src << "We cannot reach our prey!"
return
if(src.weakened >= 1 || src.paralysis >= 1 || src.stunned >= 1)
src << "We cannot pounce if we are stunned.."
return

visible_message("\red <B>[src] pounces on [target]!</B>")
if(src.m_intent == "walk")
src.m_intent = "run"
src.hud_used.move_intent.icon_state = "running"
src.loc = targloc
src.canmove = 0
src.frozen = 1
target.Weaken(3)
usedpounce = 12




Best response
By setting loc to targloc, you're teleporting the attacker to the target. There is no collision detection involved here.

What you could do instead is step_toward() the target until you hit something. If you end up next to the target, then that's a hit.
Yes but the mob must end up on top of the other mob, for roleplay effects. How would I set it up ?
In response to PoisonV3nom
PoisonV3nom wrote:
Yes but the mob must end up on top of the other mob, for roleplay effects. How would I set it up ?

Use step_towards(src, target) twice to make the character move forward. Check the return value of that proc to determine if you should continue.

On the third attempt, use LinkBlocked(src.loc, target.loc). If it returns TRUE (1) then you can continue and set src.loc = target.loc.

Note that the LinkBlocked() proc is exclusive to Space Station 13 and is not a built-in proc. A tip for anyone reading this is to implement something similar so you won't run into problems like these in your projects.

Addendum: I'm not an expert on the current state of SS13's source-code so there may be a better way, but that proc should get you going for now.