Coding Roblox Games Made Easy by Zander Brumbaugh

Coding Roblox Games Made Easy by Zander Brumbaugh

Author:Zander Brumbaugh
Language: eng
Format: epub
Publisher: Packt Publishing Pvt Ltd
Published: 2021-01-08T00:00:00+00:00


Body movers

Instances of the BodyMover base class are a convenient way of consistently applying forces directly or applying forces to accomplish a goal when working with BasePart instances. BodyMover instances will only have an effect if they're parented to BasePart instances. This means that if you wanted an entire model to move, the parts would need to be welded together with the BodyMover instance in a central part:

Figure 4.11 – There are six body mover instances, each with different behaviors

BodyForce is a Body Mover instance that applies a force to the instance it is parented to. This force is applied on a world space basis, meaning that it is not relative to the orientation of the part itself. The primary property of this instance is Force, a Vector3 that is applied to the center of mass of the part. Though applying direct force has many practical examples and in the following code, we will make a part locally experience zero gravity. To do this, we need a basic understanding of physics and the GetMass() method of BasePart instances. The force that must be used to suspend the part in the air is its mass multiplied by gravity, applied upward on the Y axis:

local part = workspace.Part

local bodyForce = Instance.new("BodyForce")

bodyForce.Parent = part

local requiredForce = part:GetMass() * workspace.Gravity

bodyForce.Force = Vector3.new(0,requiredForce,0)

BodyVelocity is another Body Mover instance that similarly operates on the world space. This instance is particularly useful when you want to set an object's velocity to be consistent without the need of a loop. The two main properties of this Body Mover are MaxForce and Velocity. The MaxForce is a Vector3 property and represents the amount of force that is applied to a part when a velocity is set. This means that if a part's mass is greater than the mover's MaxForce multiplied by gravity on a given axis, that part will be unable to move along that axis. The Velocity property is also a Vector3 and simply needs to be set to the desired velocity.

In the following example, we have a part moving forward relative to its front face. Notice that we set each component of the MaxForce property to math.huge, an essentially infinite value; this is so that the mover will be able to influence the part, regardless of the part's mass. As your skills become more advanced, you may want to adjust the value that's used for this property to prevent any unwanted behaviors, but for the examples shown here, this is optimal. By multiplying the desired speed by the forward-facing directional vector of the part, or the LookVector component of its CFrame, we can create a world space velocity that is still moving forward relative to the front face of the part. It is recommended that you run this code in the Command Bar area, or even have it in a server script and test it on Run mode for easier observation:

local Part1 = workspace.Part1

local bodyVelocity = Instance.new("BodyVelocity")

local huge = math.huge

bodyVelocity.MaxForce = Vector3.new(huge,huge,huge)

bodyVelocity.Parent = Part1

local projectileVel = 5

local moverVel = Part1.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Popular ebooks
Eco-friendly approach of bio-indigo synthesis and developing purification methods towards isolation of indigo from indirubin and bacterial fragments by Ramalingam Manivannan & Kaliyan Prabakaran & Young-A Son(214310)
Personalized inhaled bacteriophage therapy for treatment of multidrug-resistant Pseudomonas aeruginosa in cystic fibrosis by unknow(182810)
CONSORT 2025 statement: updated guideline for reporting randomized trials by unknow(91136)
Critical evaluation of the ProfiLER-02 study design and outcomes by Vivek Subbiah & Razelle Kurzrock(90756)
Cardiac gene therapy makes a comeback by Oliver J. Müller & Susanne Hille & Anca Kliesow Remes(90530)
Whisky: Malt Whiskies of Scotland (Collins Little Books) by dominic roskrow(74463)
Unveiling the design rules for tunable emission in graphene quantum dots: A high-throughput TDDFT and machine learning perspective by Şener Özönder & Mustafa Coşkun Özdemir & Caner Ünlü(50912)
A yeast-based oral therapeutic delivers immune checkpoint inhibitors to reduce intestinal tumor burden by unknow(40285)
Covalent hitchhikers guide proteins to the nucleus by Alexander F. Russell & Madeline F. Currie & Champak Chatterjee(40224)
Meet the Authors: Christopher R. Mansfield and Emily R. Derbyshire by Christopher R. Mansfield & Emily R. Derbyshire(40111)
Alkaline-earth metals promote propane dehydrogenation with carbon dioxide through geometric effects: Altering the reaction pathway by unknow(32753)
Induced iron vacancies boosting FeOOH loaded on sustainable Fenton-like collagen fiber membrane for efficient removal of emerging contaminants by unknow(32535)
Efficient electric-field-assisted photochemical conversion of methane to n-propanol exclusively over penetrated TiO2Ti hollow fibers by Guanghui Feng(32471)
Bi2SiO5 nanosheets as piezo-photocatalyst for efficient degradation of 2,4-Dichlorophenol by Hangyu Shi & Yifu Li & Lishan Zhang & Guoguan Liu & Qian Zhang & Xuan Ru & Shan Zhong(32408)
A novel NDIPTA organic heterojunction photocatalyst with built-in electric field for efficient hydrogen production by Jiahui Yang & Baojun Ma & Yongfa Zhu(32381)
Enhanced conversion of methane to liquid-phase oxygenates via hollow ferrite nanotube@horseradish peroxidase based photoenzymatic catalysis by Jun Duan & Shiying Fan & Xinyong Li & Shaomin Liu(32348)
Ordered macroporous superstructure of defective carbon adorned with tiny cobalt sulfide for selective electrocatalytic hydrogenation of cinnamaldehyde by Xiao-Shi Yuan & Sheng-Hua Zhou & San-Mei Wang & Wenbo Wei & Xiaofang Li & Xin-Tao Wu & Qi-Long Zhu(32269)
What's Done in Darkness by Kayla Perrin(27163)
Topological analysis of non-conjugated ethylene oxide cored dendrimers decorated with tetraphenylethylene: Insights from degree-based descriptors using the polynomial approach by A Theertha Nair & D Antony Xavier & Annmaria Baby & S Akhila(26552)
Investigation of mechanical and self-healing properties of hydroxyl-terminated polybutadiene functionalized with 2-ureido-4-pyrimidinone by Mohsen Kazazi & Mehran Hayaty & Ali Mousaviazar(26483)