How To Make Homing Objects.: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
mNo edit summary
>Mindraker
No edit summary
Line 4: Line 4:
Create the RocketPropulsion and the [[RBX.lua.Part (Object)|part]] object.  Alternatively, you could make a missile with rocketpropulsion without a target, and put it in [[RBX.lua.Lighting (Object)|Lighting]], then [[Clone (Function)|clone]] the rocket.
Create the RocketPropulsion and the [[RBX.lua.Part (Object)|part]] object.  Alternatively, you could make a missile with rocketpropulsion without a target, and put it in [[RBX.lua.Lighting (Object)|Lighting]], then [[Clone (Function)|clone]] the rocket.


==Defining the target==
===Defining the target===
This requires a [[RBX.lua.Script (Object)|script]].  The script will define the target's [[Position (Property)|position]], the thing you want to home in on!
This requires a [[RBX.lua.Script (Object)|script]].  The script will define the target's [[Position (Property)|position]], the thing you want to home in on!


Line 12: Line 12:
</pre>
</pre>


==Firing The Part==
===Firing The Part===
This also requires a [[RBX.lua.Script (Object)|script]], this will set off your part (If Unanchored) after The Target:
This also requires a [[RBX.lua.Script (Object)|script]], this will set off your part (If Unanchored) after The Target:


Line 20: Line 20:
</pre>
</pre>


==Additional Features==
===Additional Features===


The [[CartoonFactor]] property sets whether your part should head Directly towards it, ignoring the point its facing, or whether it faces straight at you.  1 Would be always facing at you.  0.5 Would be sort of facing you.  0 would be No effort to face you.
The [[CartoonFactor]] property sets whether your part should head Directly towards it, ignoring the point its facing, or whether it faces straight at you.  1 Would be always facing at you.  0.5 Would be sort of facing you.  0 would be No effort to face you.


:[[Abort (Function)|abort()]]
:[[Abort (Function)|abort()]]
This, as its name suggests, aborts the RocketPropulsion's mission to get to you, You could us this if your objects need fuel, and when the fuel is 0 they drop out of the sky.
This, as its name suggests, aborts the RocketPropulsion's mission to get to you, you could use this if your objects need fuel, and when the fuel is 0 they drop out of the sky.


==Connecting The Event==
===Connecting The Event===


You would need to do something like:
You would need to do something like:
Line 45: Line 45:
</pre>
</pre>


==Using This Is Script Builder==
This is what you might use in script builder:
This is what you might use in script builder:


Line 54: Line 53:
</pre>
</pre>
This would make Name look like he's orbiting you.
This would make Name look like he's orbiting you.
== Another homing brick example ==
* Insert > Object > Part<br>
* The name of this brick part is insignificant.<br>
* Insert > Object > NumberValue into the Part.<br>
* Set NumberValue to 0.20000000000000001 and call it "Speed".<br>
* Insert > Object > BodyGyro into the Part.<br>
* Insert > Object > BodyPosition into the Part.<br>
* Insert > Object > Script into the Part.<br>
In the Script, insert the following:
<pre>
bin = script.Parent
function move(target)
local dir = (target.Position - bin.Position).unit
local spawnPos = bin.Position
local pos = spawnPos + (dir * 1)
bin:findFirstChild("BodyGyro").cframe = CFrame.new(pos,  pos + dir)
bin:findFirstChild("BodyGyro").maxTorque = Vector3.new(9000,9000,9000)
end
function moveTo(target)
bin.BodyPosition.position = target.Position
bin.BodyPosition.maxForce = Vector3.new(10000,10000,10000) * bin.Speed.Value
end
function findNearestTorso(pos)
local list = game.Workspace:GetChildren()
local torso = nil
local dist = 1000
local temp = nil
local human = nil
local temp2 = nil
for x = 1, #list do
temp2 = list[x]
if (temp2.className == "Model") and (temp2 ~= script.Parent) then
temp = temp2:findFirstChild("Torso")
human = temp2:findFirstChild("Humanoid")
if (temp ~= nil) and (human ~= nil) and (human.Health > 0)  then
if (temp.Position - pos).magnitude < dist then
torso = temp
dist = (temp.Position - pos).magnitude
end
end
end
end
return torso
end
function shoot(pos)
dir = (pos - bin.CFrame.p).unit
for i = 1, 50 do
local ex = Instance.new("Explosion")
ex.BlastRadius = 1
ex.Position = bin.Position + (dir * 10 * i) + (dir * 7)
ex.Parent = game.Workspace
end
end
function shootAt(torso)
local dir = (torso.Position - bin.Position).unit
local spawnPos = bin.Position
local pos = spawnPos + (dir * 1)
shoot(pos)
end
while true do
local torso = findNearestTorso(bin.Position)
if torso~=nil then
move(torso)
moveTo(torso)
end
wait()
end
</pre>
This will make a brick that will follow you.


==See also==
==See also==

Revision as of 09:28, 10 November 2008

Rocket Propulsion And The Part

Create the RocketPropulsion and the part object. Alternatively, you could make a missile with rocketpropulsion without a target, and put it in Lighting, then clone the rocket.

Defining the target

This requires a script. The script will define the target's position, the thing you want to home in on!

Example:

game.Workspace.Part.RocketPropulsion.Target = game.Workspace.yourusernamehere.Head

Firing The Part

This also requires a script, this will set off your part (If Unanchored) after The Target:

Example:

game.Workspace.Part.RocketPropulsion:fire()

Additional Features

The CartoonFactor property sets whether your part should head Directly towards it, ignoring the point its facing, or whether it faces straight at you. 1 Would be always facing at you. 0.5 Would be sort of facing you. 0 would be No effort to face you.

abort()

This, as its name suggests, aborts the RocketPropulsion's mission to get to you, you could use this if your objects need fuel, and when the fuel is 0 they drop out of the sky.

Connecting The Event

You would need to do something like:

function onTouched(hit)
local a = hit.Parent.Humanoid
if a ~= nil then
local b = game.Lighting.Rocket
b.Position = Vector3.new(0,200,0) -- drop out of sky
b.Parent = game.Workspace
b.RocketPropulsion.Target = hit
wait(0.01)
b.RocketPropulsion:fire()
end
end
script.Parent.Touched:connect(onTouched)

This is what you might use in script builder:

a = Instance.new("RocketPropulsion") 
a.Target = game.Players.dreaddraco2.Character.Torso 
a.Parent = game.Players.Name.Character.Torso

This would make Name look like he's orbiting you.

Another homing brick example

  • Insert > Object > Part
  • The name of this brick part is insignificant.
  • Insert > Object > NumberValue into the Part.
  • Set NumberValue to 0.20000000000000001 and call it "Speed".
  • Insert > Object > BodyGyro into the Part.
  • Insert > Object > BodyPosition into the Part.
  • Insert > Object > Script into the Part.

In the Script, insert the following:

bin = script.Parent

function move(target)
	local dir = (target.Position - bin.Position).unit
	local spawnPos = bin.Position
	local pos = spawnPos + (dir * 1)
	bin:findFirstChild("BodyGyro").cframe = CFrame.new(pos,  pos + dir)
	bin:findFirstChild("BodyGyro").maxTorque = Vector3.new(9000,9000,9000)
end

function moveTo(target)
	bin.BodyPosition.position = target.Position
	bin.BodyPosition.maxForce = Vector3.new(10000,10000,10000) * bin.Speed.Value
end

function findNearestTorso(pos)
	local list = game.Workspace:GetChildren()
	local torso = nil
	local dist = 1000
	local temp = nil
	local human = nil
	local temp2 = nil
	for x = 1, #list do
		temp2 = list[x]
		if (temp2.className == "Model") and (temp2 ~= script.Parent) then
			temp = temp2:findFirstChild("Torso")
			human = temp2:findFirstChild("Humanoid")
			if (temp ~= nil) and (human ~= nil) and (human.Health > 0)  then
				if (temp.Position - pos).magnitude < dist then
					torso = temp
					dist = (temp.Position - pos).magnitude
				end
			end
		end
	end
	return torso
end

function shoot(pos)
	dir = (pos - bin.CFrame.p).unit 
	for i = 1, 50 do 
		local ex = Instance.new("Explosion") 
		ex.BlastRadius = 1
		ex.Position = bin.Position + (dir * 10 * i) + (dir * 7) 
		ex.Parent = game.Workspace 
	end
end

function shootAt(torso)
	local dir = (torso.Position - bin.Position).unit
	local spawnPos = bin.Position
	local pos = spawnPos + (dir * 1)
	shoot(pos)
end

while true do
	local torso = findNearestTorso(bin.Position)
	if torso~=nil then
		move(torso)
		moveTo(torso)
	end
	wait()
end

This will make a brick that will follow you.


See also