Some help with movements

Post Reply
User avatar
runs
Member
Posts: 1779
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Some help with movements

by runs » Post

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?
Day 42 of the quarantine

Termos
Member
Posts: 321
Joined: Sun Dec 16, 2018 12:50

Re: Some help with movements

by Termos » Post

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?

User avatar
runs
Member
Posts: 1779
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: Some help with movements

by runs » Post

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. :-)
Day 42 of the quarantine

Termos
Member
Posts: 321
Joined: Sun Dec 16, 2018 12:50

Re: Some help with movements

by Termos » Post

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,?,?)

User avatar
runs
Member
Posts: 1779
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: Some help with movements

by runs » Post

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! :-)
Day 42 of the quarantine

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests