Skip to content

Commit

Permalink
シューティングゲーム改: 重力の働く弾と働かない弾を混ぜる
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoto committed Aug 21, 2024
1 parent a9fa5e3 commit 93934bf
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Chapter8/Chapter8/ShootingLogic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class ShootingLogic: ObservableObject {
let bulletClone = bullet.clone(recursive: true)
bulletClone.position = position
bulletClone.physicsMotion?.linearVelocity = velocity
// 重力が効くかを乱数で決める
let g = Bool.random()
bulletClone.physicsBody?.isAffectedByGravity = g
// 重力が効くかによって色を変える
var material = PhysicallyBasedMaterial()
material.baseColor = .init(tint: g ? .green : .red, texture: nil)
bulletClone.model?.materials = [material]
bulletRoot.addChild(bulletClone)
// アクションのコールバック
shootAction()
Expand Down

0 comments on commit 93934bf

Please sign in to comment.