forked from Jondolf/avian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprismatic_joint_2d.rs
57 lines (51 loc) · 1.51 KB
/
prismatic_joint_2d.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use avian2d::{math::*, prelude::*};
use bevy::prelude::*;
use examples_common_2d::ExampleCommonPlugin;
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
ExampleCommonPlugin,
PhysicsPlugins::default(),
))
.insert_resource(ClearColor(Color::srgb(0.05, 0.05, 0.1)))
.insert_resource(SubstepCount(50))
.insert_resource(Gravity(Vector::NEG_Y * 1000.0))
.add_systems(Startup, setup)
.run();
}
fn setup(mut commands: Commands) {
commands.spawn(Camera2dBundle::default());
let square_sprite = Sprite {
color: Color::srgb(0.2, 0.7, 0.9),
custom_size: Some(Vec2::splat(50.0)),
..default()
};
let anchor = commands
.spawn((
SpriteBundle {
sprite: square_sprite.clone(),
..default()
},
RigidBody::Kinematic,
AngularVelocity(1.5),
))
.id();
let object = commands
.spawn((
SpriteBundle {
sprite: square_sprite,
transform: Transform::from_xyz(100.0, 0.0, 0.0),
..default()
},
RigidBody::Dynamic,
MassPropertiesBundle::new_computed(&Collider::rectangle(50.0, 50.0), 1.0),
))
.id();
commands.spawn(
PrismaticJoint::new(anchor, object)
.with_local_anchor_1(Vector::X * 50.0)
.with_free_axis(Vector::X)
.with_limits(25.0, 100.0),
);
}