Some help with movements

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

Some help with movements

by runs » Mon Oct 14, 2019 15:32

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?
 

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

Re: Some help with movements

by Termos » Mon Oct 14, 2019 19:18

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: 885
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: Some help with movements

by runs » Mon Oct 14, 2019 22:11

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. :-)
 

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

Re: Some help with movements

by Termos » Mon Oct 14, 2019 23:18

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: 885
Joined: Sat Oct 27, 2018 08:32
GitHub: runsy

Re: Some help with movements

by runs » Tue Oct 15, 2019 15:39

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! :-)
 


Return to Modding Discussion



Who is online

Users browsing this forum: No registered users and 2 guests