Nature2D - 2D Physics Engine for UI Elements

It looks like using .Object with GetBodyById returns nil.

print(engine:GetBodyById(id).Object)

image

engine:GetBodyById(id):GetFrame()

Should work. I know it’s a bit confusing but that’s just how it is :P. If you feel like this should be changed, we can discuss this over at Issues · jaipack17/Nature2D · GitHub

1 Like

Hi!
I think it would be a great way to optimize the engine, by suspending rigidbodies that can’t be seen.

1 Like

how to make a spring that is connected to the center of a box?

You’ll have to make a point, whose position gets updated to the box’s center (RigidBody:GetCenter()) each time the engine updates (Use Engine.Updated event). Use this point in your spring constraint.

1 Like

Continuing to work on hinge/revolute joints! More to come soon

2 Likes

Hey @jaipack17, I found Nature2D earlier today and i’m really impressed by it! You’ve inspired me to create a 2D character controller which has been going very smoothly. However I do have one issue, whenever I seem to jump using RigidBody:ApplyForce(Vector2.new(0,JumpVelocity), the player dips into the ground first then actually jumps.
Heres a video describing my issue:

I’ve also realised that the player seems to be a bit bouncy after landing (might be some of my RigidBody configuration settings but yeah not sure, just stating it).

4 Likes

You need to do

 RigidBody:ApplyForce(Vector2.new(0,-JumpVelocity)

Ah yep, that fixed it- thanks!

Having one more issue where if more than one object (anchored or unanchored) is present in the same EngineUI, the player moves incredibly fast even though i’ve capped their MaxForce.

Could you elaborate on that? Might be a bug. Character controller looks amazing so far!

Thanks so much! I’ll record a video displaying my problem where more then one object makes the player zoom around tomorrow as its l currently late. I’d love to chat on discord about this as i’m very impressed by this and would love to get some advice or ideas of things I could add to this character controller :))

1 Like

ill be sure to mess around with this, this is absolutely one of the best community resources ive seen so far

1 Like

how do you make contraints without a rope?

Hey! Quick question, how do we exactly set this up?

Could you elaborate on that?

You can start off with the installation page! Installation | Nature2D

Hey! Thanks for responding, I checked out the page and it only has a tutorial for the Github Version, not for the actual Roblox Model of Nature2D.

Hello, i am having a problem with making a character movement.

The problem is that when i jump while i’m moving to left or right, i don’t jump like when i stand still and jump, there is a video for better explanation:

I want the player to jump like when he stands still

This is my code:


-- // Variables \\ --

local Nature2D = require(game:GetService("ReplicatedStorage"):WaitForChild("Nature2D"))

local UIS = game:GetService("UserInputService")
local RunService = game:GetService("RunService")

local ScreenGui = script.Parent
local Floor = ScreenGui.Floor
local Player = ScreenGui.Player

local Engine = Nature2D.init(ScreenGui)

Engine:Create("RigidBody", {
	Object = Floor,
	Collidable = true,
	Anchored = true
})

local PlayerRB = Engine:Create("RigidBody", {
	Object = Player,
	Collidable = true,
	Anchored = false
})


Engine:Start()


RunService.RenderStepped:Connect(function(DeltaTime)
	
	-- Move left and right
	
	if UIS:IsKeyDown(Enum.KeyCode.D) then
		PlayerRB:ApplyForce(Vector2.new(0.2,0),0.03)
	end
	
	if UIS:IsKeyDown(Enum.KeyCode.A) then
		PlayerRB:ApplyForce(Vector2.new(-0.2,0),0.03)
	end
	
end)

UIS.InputBegan:Connect(function(input, GPE)
	
	if GPE then return end
	
	-- Jump
	
	if input.KeyCode == Enum.KeyCode.Space then
		PlayerRB:ApplyForce(Vector2.new(0,-3),0.03)
	end
end)
1 Like

You can install Nature2D by following any one method out of all. Here’s the one with the roblox model. All you do is get the model and insert it into your project (preferably ReplicatedStorage), require it from your LocalScript and start scripting!


I wonder what causes this issue since I don’t see any problems in how you apply the forces to the player. Have you doubled checked how you are managing the player input events?