RealityKit Basics: moving entities
We can use move() and its variants to move entities to new locations.
RealityKit entities have a number of instance methods for performing common actions. One that we use often is move(to:relativeTo:).
Important: this method uses Transform, not just position. We can use this to change the position, orientation, and scale of our entity.
Example 1: We can move the subject to the current transform of another entity. This will happen Instant instantaneously.
subject.move(to: value.entity.transform, relativeTo: value.entity.parent)Example 2: We can also perform this move over time by specifying a duration. We can adjust the animation with timingFunction.
subject.move(to: value.entity.transform,
relativeTo: value.entity.parent,
duration: 1,
timingFunction: .easeOut
)Example 3: Sometime we may only want to move to a position, but keep the current scale and orientation. In situations like this we can construct a new transform.
let boxTransform = value.entity.transform
var newTransform = Transform()
newTransform.translation = boxTransform.translation
newTransform.scale = subject.transform.scale
newTransform.rotation = subject.transform.rotation
subject.move(to: newTransform, relativeTo: value.entity.parent, duration: 1)The examples in this post were all done in tap gestures, but we can call this anytime we have access to an entity.
Video Demo
Example Code
struct Example077: View {
@State var subject = Entity()
@State var box1 = Entity()
@State var box2 = Entity()
@State var box3 = Entity()
var body: some View {
RealityView { content in
guard let scene = try? await Entity(named: "MoveToExamples", in: realityKitContentBundle) else { return }
content.add(scene)
guard let subjectEntity = scene.findEntity(named: "Subject") else { return }
subject = subjectEntity
guard let box1Entity = scene.findEntity(named: "Box_1") else { return }
box1 = box1Entity
guard let box2Entity = scene.findEntity(named: "Box_2") else { return }
box2 = box2Entity
guard let box3Entity = scene.findEntity(named: "Box_3") else { return }
box3 = box3Entity
} update: { content in
}
.gesture(tapSubect)
.gesture(tapBox1)
.gesture(tapBox2)
.gesture(tapBox3)
}
var tapSubect: some Gesture {
TapGesture()
.targetedToEntity(subject)
.onEnded { value in
// Reset the subject transform to default
let newTransform = Transform()
subject.move(to: newTransform, relativeTo: value.entity.parent)
}
}
var tapBox1: some Gesture {
TapGesture()
.targetedToEntity(box1)
.onEnded { value in
// Example 1: Move the subject to the transform of box one
subject.move(to: value.entity.transform, relativeTo: value.entity.parent)
}
}
var tapBox2: some Gesture {
TapGesture()
.targetedToEntity(box2)
.onEnded { value in
// Example 2: Move the subject to the transform of box two. Move over time with an ease out animation
subject
.move(
to: value.entity.transform,
relativeTo: value.entity.parent,
duration: 1,
timingFunction: .easeOut
)
}
}
var tapBox3: some Gesture {
TapGesture()
.targetedToEntity(box3)
.onEnded { value in
// Example 3: move to the position of box 3, but use the scale and orientation from the subject
let boxTransform = value.entity.transform
var newTransform = Transform()
newTransform.translation = boxTransform.translation
newTransform.scale = subject.transform.scale
newTransform.rotation = subject.transform.rotation
subject.move(to: newTransform, relativeTo: value.entity.parent, duration: 1)
}
}
}Support our work so we can continue to bring you new examples and articles.
Download the Xcode project with this and many more examples from Step Into Vision.
Some examples are provided as standalone Xcode projects. You can find those here.

Hi. I am trying to make a car game in vision OS, and I am looking for a solution to control my car model, at start model loads in scene cars has a physic component and falls on floor at start and then controls appear, can I use this function for my use case, because car may keep moving as long as button is pressed and so there is some continuous change in position in every frame how to handle this?