Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # SpaceCell.gd
- extends Area
- var contacts = {}
- var force = Vector3(0,0,0) # the force that acts on the cell
- var velocity = Vector3(0,0,0) # the velocity of the cell
- const FORCE_K = 1 # the constant k in F=kx between the cells
- const REST_DISTANCE = 1 # the distance between two cells at which the cells are at rest
- func update_force():
- # updates the force that acts on a cell i from all other cells j
- # var pos_i = get_pos() # <------- THE PROBLEM
- # var pos_i = position # <------- THE PROBLEM
- var pos_i = self.position # <------- THE PROBLEM
- for cell_j in contacts:
- var pos_j = cell_j.position # <------- THE PROBLEM
- var x = pos_i - pos_j
- var x0 = x.normalized()*REST_DISTANCE
- var force_ij = FORCE_K*(x - x0)
- force += force_ij
- func update_velocity(delta):
- velocity += force * delta
- func update_position(delta):
- self.position = self.position + velocity*delta
- func _physics_process(delta):
- update_force()
- update_velocity(delta)
- update_position(delta)
- func area_entered(area):
- contacts[area.cellname] = area
- func area_exited(area):
- contacts.erase(area.cellname)
- # ERROR OUTPUT:
- # Invalid get index 'position' (on base: 'Area (SpaceCell.gd)').
- # SpaceCell SCENE SETUP:
- # SpaceCell [Area] <----- Script attached called SpaceCell.gd, see above
- # ---- CollisionShape (shaped like sphere)
- # ---- ---- CSGMesh (shaped like sphere)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement