Post

Replies

Boosts

Views

Activity

rotate an entity in Realitykit
I am having trouble rotating an entity that is added in Reality Composer but rotated in code. I decided to follow the information in the Developer Documentation called Manipulating Reality Composer Scenes from Code. (https://developer.apple.com/documentation/realitykit/creating_3d_content_with_reality_composer/manipulating_reality_composer_scenes_from_code) I am starting with a default ARKit program that just displays the Steel Box. When I add code to rotate the box 45° it also shrinks the box along the x axis. The cube gets flattened about half way. Is there a way to rotate without it scaling at the same time? import UIKit import RealityKit class ViewController: UIViewController {          @IBOutlet var arView: ARView!          override func viewDidLoad() {         super.viewDidLoad()                  // Load the "Box" scene from the "Experience" Reality File         let boxAnchor = try! Experience.loadBox()                  // Add the box anchor to the scene         arView.scene.anchors.append(boxAnchor)                  if let box = boxAnchor.findEntity(named: "lid") {             let radians = -45.0 * Float.pi / 180.0             box.transform.rotation += simd_quatf(angle: radians, axis: SIMD3<Float>(1,0,0))         }              } } I have tried adding the "if let box =" part to above the "arView.scene.anchors.append(boxAnchor)" part and that doesn't help. I decided to go for the default code and work my way up to getting this to work with a touch to the box on the screen. Touching anywhere else should not rotate the box. Setting up a rotation animation inside Reality Composer is working, but I want a tap to rotate and a another tap to un-rotate. It will be opening a lid and closing a lid. I am on Catalina and xCode12. I have also noticed that the box is referred to as an object, entity, or element in the different pages of the documentation. This makes it difficult to we search for the issue I am having.
4
0
6.5k
Aug ’20
Swift Playgrounds Learn to Code 2 "Moving Further Forward" Page
One of the places I have noticed this on my MBP is in the Swift Playgrounds Learn to Code 2 "Moving Further Forward" Page. After successfully getting the "expert" to the end of the maze puzzle a box pops up.  It talks about defining a function using parameters to make the function more reusable.  To make the function work I wrote: let expert = Expert() func move(distance: Int) {     for i in 1 ... distance {         expert.moveForward()     } } If I try to put moveForward() without expert. as a prefix I get an error.  That's OK by me. However, the 'success box' after completing the maze says: "Now that you've defined move, you'll be able to use is as a method on the Character and Expert types.  For example, expert.move(distance: 4) will move the expert instance forward four tiles."   I do not see how to define the function so that I can call it this way in Learn to Code 2. Not knowing the correct words to use in a search on the internet makes it difficult to find an answer. I tried querying define a function as a method for an instance, or something like that. Is there a way to write the function so it becomes a method that I can call with either expert.move(distance: 4), or character.move(distance: 4), or even beginner.move(distance: 4)? When searching these forums I don't find a way to refine the search, or search through the results. Putting quote marks around part of the search doesn't search for that phrase. Most annoying having two phrases in quotes results in 403 Forbidden. The forbidden search is: Swift Playgrounds "Learn to Code 2" "Moving Further Forward" Page Why would searching for a phrase not work and searching two phrases be forbidden? WOW! 😳
4
0
3.0k
Jul ’20