generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: I have a question about the MoveTo function for Humanoids.

Previous Thread :: Next Thread 
Bergan is not online. Bergan
Joined: 23 Nov 2007
Total Posts: 4942
19 Sep 2015 12:36 PM
So, I am working on an enemy that chases a player. It doesn't just target the player's position; it stops (x number) of studs before reaching the target. The script works fine, except for an unintended side-effect.

The problem is, the script's calculations seem to change based on the target's torso's rotation, even though the script has absolutely NO calculations based on the rotation of the target's torso.

If I am facing the direction the enemy is facing (it is behind me), it will calculate a target position between it and me. However, if I face towards the enemy, it will calculate a target position PAST me, making it try to walk THROUGH me.

---Tldr, though applies to ALL readers.
So my question is: does the MoveTo function of Humanoids calculate based on the cfame/rotation of the target part (second parameter of the function)?
Report Abuse
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
19 Sep 2015 12:38 PM
I think its just Vector3.

(Signature): Welcome to the forums!
Report Abuse
Bergan is not online. Bergan
Joined: 23 Nov 2007
Total Posts: 4942
19 Sep 2015 12:41 PM
MoveTo has two parameters: A Vector3, and a BasePart.
I try making BasePart nil, and the movement becomes choppy.
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
19 Sep 2015 12:42 PM
after ~ 8 seconds it stops moving, you have to loop it
Report Abuse
Bergan is not online. Bergan
Joined: 23 Nov 2007
Total Posts: 4942
19 Sep 2015 12:47 PM
The script works continously. If I move, the NPC follows me, even if I change the direction I am walking.

My problem is that when the MoveTo function uses its second Parameter, BasePart (in this case, the target's torso), it calculates based on the BasePart's CFrame/Rotation, which can mess up the NPC's movement if the target faces a direction other than away from the NPC.
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
19 Sep 2015 12:48 PM
You dont need the second pramater
Report Abuse
hunxrepair is not online. hunxrepair
Joined: 07 Aug 2011
Total Posts: 777
19 Sep 2015 12:51 PM
moveto is vector3 value meaning
only x y and z no rotation


you've probably done something wrong with your script for it to behave like that
though i really do not understand what you said, anyway code or place to see it would help


also if you do not know moveto is one time only

meaning if you walk away from the zombie it won't follow you to your torso's position


Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
19 Sep 2015 12:54 PM
Your torso could also be facing in the wrong direction
Report Abuse
DeathsLASTwords is not online. DeathsLASTwords
Joined: 28 Jan 2012
Total Posts: 2701
19 Sep 2015 12:54 PM
wait(3)
local Victim = game.Workspace.Player
while wait(0.25) do
local MagnitudePos = (script.Parent.Torso.Position - Victim.Torso.Position).magnitude
if MagnitudePos < 15 then
script.Parent.Humanoid:MoveTo(Victim.Torso.Position)
end
end

this is an example taht works


(Signature): Welcome to the forums!
Report Abuse
Bergan is not online. Bergan
Joined: 23 Nov 2007
Total Posts: 4942
19 Sep 2015 12:54 PM
Without the second parameter, the movement isn't as smooth. I'll test it in Online Mode, though.
In the meantime, I suppose I will share with you the part of the script that uses MoveTo.



function Move(target)
local FinalAngle = math.atan2(target.Position.Z - script.Parent.Torso.Position.Z, target.Position.X - script.Parent.Torso.Position.X)
local FinalLength = math.sqrt(math.pow(target.Position.X - script.Parent.Torso.Position.X,2) + math.pow(target.Position.Z - script.Parent.Torso.Position.Z,2))

--Smin is a minimum distance, so the NPC doesn't target the player's actual position, but instead one close --to it. Smin is 2.5 in this case, defined outside of this function.

local SemiFinalX = (FinalLength - Smin) * math.cos(FinalAngle)
local SemiFinalZ = (FinalLength - Smin) * math.sin(FinalAngle)


local FinalX = (script.Parent.Torso.Position.X) + SemiFinalX
local FinalZ = (script.Parent.Torso.Position.Z) + SemiFinalZ

local FinalPos = Vector3.new(FinalX, script.Parent.Torso.Position.Y, FinalZ)
script.Parent.Monster:MoveTo(FinalPos,target)
script.Parent.Monster.ResetVal.Value = 3 --don't worry about this. Prevents walking animation when still.
Extra.Value = true --This is something else too; don't worry about this.
end
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
19 Sep 2015 12:55 PM
humanoid:MoveTo(workspace.Part.Position)

This is all you need. wtf is all that math for?!
Report Abuse
Bergan is not online. Bergan
Joined: 23 Nov 2007
Total Posts: 4942
19 Sep 2015 01:02 PM
There is a reason for my math.

If I simply use target.Position, the NPC will continue moving against the target, trying to get to a position it can never reach while the target occupies it.

Let's say that the target is 4 Studs away from the NPC.
With target.position, the NPC moves 4 Studs toward the target, running into them.
With my math, the NPC moves 2.5 Studs towards the target, giving space between the NPC and target.

With my math, the NPC has room for animations to attack the target; otherwise, their arms would go through the target, which is unrealistic.

Report Abuse
OrangeKitten is not online. OrangeKitten
Joined: 12 Jul 2007
Total Posts: 383
19 Sep 2015 01:04 PM
The math is unneeded, use target.Position + Vector3.new(0,0,-2) to calculate a few studs away.
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
19 Sep 2015 01:06 PM
local sub = (workspace.Part.Position-torso.Position)
local toward = sub.Unit
humanoid:MoveTo(sub*(sub.Magnitude-2.5))

While that is some impressive math I think this might be a better option.
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
19 Sep 2015 01:07 PM
@orange
This isn't cframe it doesnt work like that.
Report Abuse
OrangeKitten is not online. OrangeKitten
Joined: 12 Jul 2007
Total Posts: 383
19 Sep 2015 01:09 PM
Pinker it actually does work, I've used that many times. I'm the 8 some years veteran here.
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
19 Sep 2015 01:14 PM
That is impossible for it to work because vector3 is on a global scale so if you subtract it, it wont be behind it, it will be to studs along the z axis away from it. There's a huge difference
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
19 Sep 2015 01:16 PM
http://prntscr.com/8i5ttk
Report Abuse
Bergan is not online. Bergan
Joined: 23 Nov 2007
Total Posts: 4942
19 Sep 2015 01:17 PM
The + (0,0,2) does work, but the problem is, it is not in relation to the direction between the target and the NPC. This means that it can be to the front left, front right, back left, and back right of the target, depending on where the target is. This isn't my intention of following the target.

Report Abuse
OrangeKitten is not online. OrangeKitten
Joined: 12 Jul 2007
Total Posts: 383
19 Sep 2015 01:18 PM
Oh rlly? Didn't realize your an idiot. Your talking big to sound smart, but yet, I find it funny how I use that just fine in some of my games.
Report Abuse
OrangeKitten is not online. OrangeKitten
Joined: 12 Jul 2007
Total Posts: 383
19 Sep 2015 01:18 PM
That was @ pinker
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
19 Sep 2015 01:21 PM
You must be using it diffrent than you described because if you looked at my picture it would explain
Report Abuse
OrangeKitten is not online. OrangeKitten
Joined: 12 Jul 2007
Total Posts: 383
19 Sep 2015 01:22 PM
Your picture is terrible and shows no point at all
Report Abuse
Pinkerten is not online. Pinkerten
Joined: 03 Aug 2014
Total Posts: 840
19 Sep 2015 01:24 PM
Yes.. it kinda does..
Report Abuse
Bergan is not online. Bergan
Joined: 23 Nov 2007
Total Posts: 4942
19 Sep 2015 01:24 PM
@pink

Your recent suggestion (sub, unit, etc) doesn't make the NPC follow the humanoid; it goes wherever the magnitude itself is. And it still changes direction if I face a different way but stay in the same place.

Say I turn left; it starts moving left.
I turn right, and it starts moving right.
Even if I stay still when I move.

The original script, before I posted this, never had this problem UNLESS I was already within the minimum range of the script. It shouldn't even move anymore by then, but it does. Perhaps I missed that detail, I'll have to re-read what I first posted.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image