Re: How to use the lindworm?
Posted: Fri Mar 27, 2015 8:26 pm
Use setPosition() and/or setWorldPosition() on the object immediately after spawning it.
I can't figure how to do this correctly!minmay wrote:Use setPosition() and/or setWorldPosition() on the object immediately after spawning it.
Code: Select all
class = "MonsterAttack",
name = "rangedAttack",
-- attackType = "projectile",
attackPower = 50,
minDistance = 2,
cooldown = 4,
animation = "rangedAttack",
sound = "lindworm_roar",
-- shootProjectile = "magma_meteor",
onAttack = function(self)
local dx,dy = getForward(self.go.facing)
local x = self.go.x + dx*2
local y = self.go.y + dy*2
local spell = spawn("magma_meteor", self.go.level, x, y, self.go.facing, self.go.elevation)
local wpos = spell:getWorldPosition()
local dx = nil
local dz = nil
if spell.facing == 0 then
dx = left and -0.1 or 0.1
dz = -1
elseif spell.facing == 1 then
dz = left and 0.1 or -0.1
dx = -1
elseif spell.facing == 2 then
dx = left and 0.1 or -0.1
dz = 1
else -- spell.facing == 3
dz = left and -0.1 or 0.1
dx = 1
end
spell:setWorldPosition(vec(wpos[1]-0.65,wpos[2]+0.25,wpos[3]+dz))
end,
thanks,minmay wrote:World position has global orientation, it is independent of facing. You have to adjust it depending on the facing of the caster. Your code is treating it as if the x position is local and the z position is global. All 3 positions are global. Also, you need to get rid of the lines with "left" because it will always be nil and only makes sense when it's a champion from the party casting the spell.
Also you need to check that your x and y positions are inside the map bounds, your current code will probably cause a crash if the lindworm breathes while on the edge of the map.
Code: Select all
{
class = "MonsterAttack",
name = "rangedAttack",
attackPower = 400,
minDistance = 2,
cooldown = 3,
animation = "rangedAttack",
sound = "lindworm_roar",
onAttack = function(self)
local dx,dy = getForward(self.go.facing)
local x = self.go.x + dx*2
local y = self.go.y + dy*2
local spell = spawn("magma_meteor", self.go.level, x, y, self.go.facing, self.go.elevation)
local wpos = spell:getWorldPosition()
if spell.facing == 0 then
spell:setWorldPosition(vec(wpos[1]+0.65,wpos[2]+0.25,wpos[3]+0))
elseif spell.facing == 1 then
spell:setWorldPosition(vec(wpos[1]+0,wpos[2]+0,wpos[3]-0.65))
elseif spell.facing == 2 then
spell:setWorldPosition(vec(wpos[1]-0.65,wpos[2]+0.25,wpos[3]+0))
else -- spell.facing == 3
spell:setWorldPosition(vec(wpos[1]+0,wpos[2]+0,wpos[3]+0.65))
end
end,
},
Code: Select all
spell:setWorldPosition(vec(wpos[1]-0.65,wpos[2]+0.25,wpos[3]+0))In Grimrock, the X world axis is west to east, the Y world axis is down to up, and the Z world axis is south to north. So for adjusting the world position position of a fired projectile, you'll want to change the X and Z positions depending on the facing of the monster. But the monster's animation will always be making the attack at the same height, regardless of which direction it's facing. So the Y world position, relative to the monster's Y position, should always be the same, and should not depend on facing.bongobeat wrote:lol I don't know
while trying how to represent that in a 3d space and use some values, I finally adjust it to that, and this works nice.
did I understand this correctly?Code: Select all
spell:setWorldPosition(vec(wpos[1]-0.65,wpos[2]+0.25,wpos[3]+0))
here wpos[1] is the x , [2] the y , and [3] the z? or that does have nothing to do with that.
I'm kinda lost now!