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: lookVector

Previous Thread :: Next Thread 
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
12 Sep 2015 03:22 AM
How would i apply a force in the opposite direction of the players lookVector. So say if they look down, they are forced upward. Here is what i have so far;

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

mouse.Button1Down:connect(function()
local force = Instance.new("BodyForce", player.Character.Torso)
force.force = Vector3.new(player.Character.Torso.CFrame.lookVector.X * -1, player.Character.Torso.CFrame.lookVector.Y * -1, player.Character.Torso.CFrame.lookVector.Z * -1)
print(force.force)
wait(1)
force:Destroy()
end)

No errors just it doesnt do anything
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
12 Sep 2015 03:24 AM
From your description I'd say that you want to use the lookVector of the camera's CFrame.




Muad'Dib
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
12 Sep 2015 03:28 AM
Ok; the game is in first person but ill try.

workspace.CurrentCamera.lookVector?
Report Abuse
distalDigitPhalanx is not online. distalDigitPhalanx
Joined: 25 Jan 2015
Total Posts: 1509
12 Sep 2015 03:28 AM
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local cam = game.Workspace.CurrentCamera
local power = 4000

mouse.Button1Down:connect(function()
local force = Instance.new("BodyForce", player.Character.HumanoidRootPart)
force.force = cam.CoordinateFrame.lookVector * -1 * power
print(force.force)
wait(1)
force:Destroy()
end)
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
12 Sep 2015 03:32 AM
@Above thanks, that works on the y but due to the baseplate friction i willh ave to change the power along the other axis.
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
12 Sep 2015 03:33 AM
How would i go about this?
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
12 Sep 2015 03:39 AM
b
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
12 Sep 2015 03:42 AM
Also when i look it 2 axis i only get fired x or z and dont go up
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
12 Sep 2015 03:48 AM
Like I said, you have to use the camera for this.

local Cam = workspace.CurrentCamera
local UIS = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer

local Selection = script.Parent:WaitForChild("Frame")
Selection.Visible = false

local Start

local Force = function(m,dir)
local f = 0
local main
local mainM
local function GetMass(p)
for i,v in next, p:GetChildren() do
if v:IsA("BasePart") then
local mass = v:GetMass()
f = f + mass
if mainM then
if mass > mainM then
main = v
mainM = mass
end
else
mainM = mass
main = v
end
end
GetMass(v)
end
end
GetMass(m)
local Bforce = Instance.new("BodyForce",main) -- Place bodyforce in part with most mass
Bforce.Force = (dir - main.Position).Unit * (f*1000) -- Apply force here
wait(0.5) -- How long the force lasts
Bforce:Destroy()
end

UIS.InputBegan:connect(function(input,core)
if not core then
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if Player.Character then
Force(Player.Character,(Cam.CoordinateFrame.p - Player.Character:GetModelCFrame().p).Unit*1000)
end
end
end
end)


Muad'Dib
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
12 Sep 2015 03:50 AM
Ignore this stuff:

local Selection = script.Parent:WaitForChild("Frame")
Selection.Visible = false

local Start

Those are from the script I added the force stuff to and I forgot to delete it from the post.



Muad'Dib
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
12 Sep 2015 03:52 AM
@chim

It is not detecting when uis has began, i added a print statement and it didnt show
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
12 Sep 2015 03:53 AM
Dw didnt see your post.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
12 Sep 2015 03:54 AM
I messed some stuff with the function this one is fixed:

local Force = function(m,dir)
local f = 0
local main
local mainM
local function GetMass(p)
for i,v in next, p:GetChildren() do
if v:IsA("BasePart") then
local mass = v:GetMass()
f = f + mass
if mainM then
if mass > mainM then
main = v
mainM = mass
end
else
mainM = mass
main = v
end
end
GetMass(v)
end
end
GetMass(m)
local Bforce = Instance.new("BodyForce",main) -- Place bodyforce in part with most mass
Bforce.Force = (dir).Unit * (f*1000) -- Add force here
wait(0.5)
Bforce:Destroy()
end


Muad'Dib
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
12 Sep 2015 03:54 AM
I have tested and thanks so much it works, however it is still so much overpowered on the y when you aim at an angle
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
12 Sep 2015 03:55 AM
Yes so use the edited Force function instead. It fixes that problem.


Muad'Dib
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
12 Sep 2015 03:56 AM
Yes i am trying it and when i aim at the ground and to an angle i still justfly up and not x and z shall i make it active place?
Report Abuse
yobo89 is not online. yobo89
Joined: 05 Jun 2010
Total Posts: 2341
12 Sep 2015 03:58 AM
It works when i look up and to an angle
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