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 » Scripting Helpers
Home Search
 

Re: Position and Velocity help

Previous Thread :: Next Thread 
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
07 Jan 2014 04:09 PM
So im using this to create an ejection system for my gun
It works pretty well, but the shell changes ejection positions whenever I rotate my character.

How can I have it to where the shell ejects to the same side every time?
And how can I make the velocity of the shell be away from the weapon everytime?


function EjectCasing()
SpawnAt = barrel_1.CFrame+Vector3.new(0,0,1)
shell = Instance.new("Part")
shell.FormFactor = "Custom"
shell.Size = Vector3.new(.4,.2,.2)
shell.Parent = game.Workspace
shell.CFrame = SpawnAt
shell.Velocity = Vector3.new(math.random(-3,3), math.random(5,10), math.random(10,15))
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
07 Jan 2014 04:11 PM
multiply it by the lookVector of the barrel
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
07 Jan 2014 04:15 PM
like this?

this just spaws it in like, 0,0,0


SpawnAt = barrel_1.CFrame.lookVector+Vector3.new(0,0,1)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
07 Jan 2014 04:19 PM
No:

SpawnAt = barrel_1.CFrame * CFrame.new(0,0,-1)
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
07 Jan 2014 04:35 PM
what about the velocity?

How can I get it to always be pushing the shell away from the wep?
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
07 Jan 2014 04:37 PM
shell.Velocity = barrel_1.CFrame.lookVector * Vector3.new(math.random(-3,3), math.random(5,10), math.random(10,15))
I believe
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
07 Jan 2014 04:41 PM
Well, that didnt break it, but the shells are just being spawned without velocity.

They arent being pushed anywhere.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
07 Jan 2014 04:42 PM
Without velocity, or with a very low amount?
Report Abuse
StBashkir is not online. StBashkir
Joined: 29 Aug 2008
Total Posts: 26171
07 Jan 2014 04:44 PM
function EjectCasing()
       SpawnAt = CFrame.new(barrel_1.CFrame.p + barrel_1.CFrame.lookVector)
       shell = Instance.new("Part")
       shell.FormFactor = "Custom"
       shell.Size = Vector3.new(.4,.2,.2)
       shell.Parent = game.Workspace
       shell.CFrame = SpawnAt
       shell.Velocity = shell.CFrame.lookVector * ((shell:GetMass() * 196.2) * 20)
       end
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
07 Jan 2014 04:44 PM
It doesnt have any

I put the number to a huge ammount like 1k+ and it did nothing
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
07 Jan 2014 04:45 PM
Why didn't I think of that...
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
07 Jan 2014 04:46 PM
Remind me, StefanBashkir, the use of parenting the part after defining Size and FormFactor, but not Position or CFrame.
Report Abuse
StBashkir is not online. StBashkir
Joined: 29 Aug 2008
Total Posts: 26171
07 Jan 2014 04:49 PM
"Remind me, StefanBashkir, the use of parenting the part after defining Size and FormFactor, but not Position or CFrame."

Well, I don't see how that applies here since I just copied the code and changed the starting CFrame and Velocity.

But positioning before parenting will allow the part to be merged. Doing so afterwards will invoke collision-detection on the spawning object.
Report Abuse
Absurdism is not online. Absurdism
Joined: 18 Jul 2013
Total Posts: 2568
07 Jan 2014 04:50 PM
I know the latter. The said code set position afterward.
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
07 Jan 2014 04:52 PM
What St told me to do launches them straight down .-.
Report Abuse
StBashkir is not online. StBashkir
Joined: 29 Aug 2008
Total Posts: 26171
07 Jan 2014 04:56 PM
Probably because that's the direction of the FrontSurface.
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
07 Jan 2014 05:01 PM
so you cant do the look vector of a different surface?
Report Abuse
StBashkir is not online. StBashkir
Joined: 29 Aug 2008
Total Posts: 26171
07 Jan 2014 05:03 PM
You can.

local rightVector = CFrame:vectorToWorldSpace( Vector3.new(1,0,0) )
local leftVector = CFrame:vectorToWorldSpace( Vector3.new(-1,0,0) )
local upVector = CFrame:vectorToWorldSpace( Vector3.new(0,1,0) )
local downVector = CFrame:vectorToWorldSpace( Vector3.new(0,-1,0) )
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
07 Jan 2014 05:19 PM
Ok this is working good now :D
shell.Velocity = barrel_1.CFrame:vectorToWorldSpace(Vector3.new(.2,0,0)) * ((shell:GetMass() * 200) * math.random(3,6))


But how would I modify how the shell comes out on different planes?
As of right now it only comes out straight, with a math.random of how far it comes out.
How would I make it maybe go a little forward and backward, or up and down?
Report Abuse
FootBa11 is not online. FootBa11
Joined: 16 Sep 2008
Total Posts: 11501
07 Jan 2014 05:26 PM
nvm i got it
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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