Page 1 of 1

Some help with movements

Posted: Mon Oct 14, 2019 15:32
by runs
I want a mob to move from pos to tpos. I do the following:

Code: Select all

local dir = vector.direction(pos, tpos)
local velocity = {
	x= self.max_speed* dir.x,
	y= self.max_speed* dir.y,
	z= self.max_speed* dir.z,
}
local new_yaw = minetest.dir_to_yaw(dir)
self.object:set_yaw(new_yaw)	
self.object:set_velocity(velocity)
But the mob moves in a straight movement.

Any help?

Re: Some help with movements

Posted: Mon Oct 14, 2019 19:18
by Termos
Yup, this code will move them in a straight line, given tpos is stationary.

What's the problem exactly, do they not go towards tpos, or you'd like them to arc towards tpos?

Re: Some help with movements

Posted: Mon Oct 14, 2019 22:11
by runs
Termos wrote:Yup, this code will move them in a straight line, given tpos is stationary.

What's the problem exactly, do they not go towards tpos, or you'd like them to arc towards tpos?
The second option I want. :-)

Re: Some help with movements

Posted: Mon Oct 14, 2019 23:18
by Termos
It's the easiest to use mobkit utils, for example:

Code: Select all

local tyaw = minetest.dir_to_yaw(vector.direction(pos, tpos))
mobkit.turn2yaw(self,tyaw,rate)          -- rate is in rads per sec
self.object:set_velocity(vector.multiply(minetest.yaw_to_dir(self.object:get_yaw()),max_speed)))
edit: or just try the new version, the code becomes:
mobkit.drive_to_pos(self,tpos,max_speed,?,?)

Re: Some help with movements

Posted: Tue Oct 15, 2019 15:39
by runs
Termos wrote:It's the easiest to use mobkit utils, for example:

Code: Select all

local tyaw = minetest.dir_to_yaw(vector.direction(pos, tpos))
mobkit.turn2yaw(self,tyaw,rate)          -- rate is in rads per sec
self.object:set_velocity(vector.multiply(minetest.yaw_to_dir(self.object:get_yaw()),max_speed)))
edit: or just try the new version, the code becomes:
mobkit.drive_to_pos(self,tpos,max_speed,?,?)
thanx!!! Just what I wanted! :-)