public static void _Register(ChipmunkBody body) { if (Chipmunk._interpolationManager) { Chipmunk._interpolationManager.RegisterHelper(body); } }
public void _Remove(ChipmunkBody obj) { if (obj._handle == IntPtr.Zero) { Debug.LogError("ChipmunkBody handle is NULL"); return; } if (!CP.cpSpaceContainsBody(_handle, obj._handle)) { Debug.LogError("Space does not contain ChipmunkBody."); return; } PostStepFunc del = delegate(){ // Debug.Log("Removing body."); bodies.Remove(obj); CP.cpSpaceRemoveBody(_handle, obj._handle); }; if (locked) { _AddPostStepCallback(_handle, obj.handle, del); } else { del(); } }
// Use this for initialization void Awake() { crouch = GetComponent <Crouch>(); jumpAC = AnimateTiledConfig.getByName(gameObject, EnumAnimateTiledName.Jump, true); body = GetComponent <ChipmunkBody>(); resetStatus(); }
void Start() { body = GetComponent <ChipmunkBody>(); shape = GetComponent <ChipmunkShape>(); // invokes subclass own starting method ownStart(); }
public void die() { // avoid re doing the animation if (dying) { return; } dying = true; // resize the game object, it also affects the chipmunk shape transform.localScale -= CRUNCH_VECTOR * CRUNCH_PROPORTION; // transform the body downwards ChipmunkBody body = GetComponent <ChipmunkBody>(); float centerOffsetY = ((1f - CRUNCH_PROPORTION) * 0.5f) * sizeY; Vector3 thePos = body.position; thePos.y -= centerOffsetY * (1f + CRUNCH_PROPORTION); body.position = thePos; // disable the game object (not children) to avoid ugly upward movement due to // unknown behavior (maybe because its move script continues working?) #if UNITY_4_AND_LATER gameObject.SetActive(false); #else gameObject.active = false; #endif }
void Awake() { body = GetComponent <ChipmunkBody>(); automaticFly = false; stop = false; goDown = true; // starting going down }
void Awake() { jump = GetComponent <Jump>(); patrol = GetComponent <Patrol>(); shape = GetComponent <ChipmunkShape>(); body = GetComponent <ChipmunkBody>(); }
void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); } else { instance = this; DontDestroyOnLoad(gameObject); } PauseGameManager.Instance.register(this, gameObject); jump = GetComponent <Jump>(); walk = GetComponent <PlayerWalk>(); firePivot = transform.FindChild("FirePivot"); teleportable = GetComponent <Teleportable>(); dieAnim = GetComponent <PlayerDieAnim>(); crouch = GetComponent <Crouch>(); idle = GetComponent <Idle>(); lookUpwards = GetComponent <LookUpwards>(); body = GetComponent <ChipmunkBody>(); walkVelBackup = walkVelocity; rightFireDir.x = 1f; rightFireDir.y = -0.5f; leftFireDir.x = -1f; leftFireDir.y = -0.5f; fireDir = rightFireDir; collisionGroupSkip = GetComponent <ChipmunkShape>().collisionGroup; collisionLayers = unchecked ((uint)~(1 << gameObject.layer)); // all layers except Player's layer }
void Awake() { jump = GetComponent <Jump>(); patrol = GetComponent <Patrol>(); shape = GetComponent <ChipmunkShape>(); body = GetComponent <ChipmunkBody>(); PauseGameManager.Instance.register(this, gameObject); }
// Use this for initialization void Awake() { walk = GetComponent <WalkAbs>(); patrol = GetComponent <Patrol>(); idle = GetComponent <Idle>(); body = GetComponent <ChipmunkBody>(); stop = true; operable = true; }
public static void ChipmunkBodyDestroy(ChipmunkBody b) { if (b != null) { b.enabled = false; // registering a disable body will remove it from the list ChipmunkInterpolationManager._Register(b); } }
// Use this for initialization void Awake() { fly = GetComponent <Fly>(); chase = GetComponent <Chase>(); body = GetComponent <ChipmunkBody>(); shape = GetComponent <ChipmunkShape>(); PauseGameManager.Instance.register(this, gameObject); }
void Awake() { dieAnim = GetComponent <GoombaDieAnim>(); patrol = GetComponent <Patrol>(); idle = GetComponent <Idle>(); body = GetComponent <ChipmunkBody>(); patrol.setDir(1f); // initialize patrol direction }
protected void UpdateGrounding() { bool wasGrounded = _grounded; // Reset the grounding values to defaults _grounded = false; groundNormal = new Vector2(0f, -1f); groundPenetration = 0f; groundBody = null; groundShape = null; groundImpulse = Vector2.zero; // Find the best (most upright) normal of something you are standing on. body.EachArbiter(delegate(ChipmunkArbiter arbiter){ ChipmunkShape player, ground; arbiter.GetShapes(out player, out ground); Vector2 n = -arbiter.GetNormal(0); // Magic thershold here to detect if you hit your head or not. if (n.y < -0.7f) { // Bumped your head, disable further jumping. remainingAirJumps = 0; remainingBoost = 0f; } else if (n.y > groundNormal.y) { _grounded = true; groundNormal = n; groundPenetration = -arbiter.GetDepth(0); groundBody = ground.body; groundShape = ground; } groundImpulse += arbiter.impulseWithFriction; }); // If the player just landed from a significant jump, send a message. if (_grounded && !wasGrounded && airTime > landThreshold) { SendMessage("OnLand"); } // Increment airTime if the player is not grounded. airTime = (!_grounded ? airTime + Time.deltaTime : 0f); // To be well grounded, the slope you are standing on needs to less than the amount of friction float friction = _grounded ? shape.friction * groundShape.friction : 0f; wellGrounded = grounded && Mathf.Abs(groundNormal.x / groundNormal.y) < friction; if (wellGrounded) { recentGroundVelocity = (groundBody != null ? groundBody.velocity : Vector2.zero); remainingAirJumps = maxAirJumps; remainingJumpLeniency = jumpLeniency; } }
void Awake() { dieAnim = GetComponent <GoombaDieAnim>(); patrol = GetComponent <Patrol>(); idle = GetComponent <Idle>(); body = GetComponent <ChipmunkBody>(); shape = GetComponent <ChipmunkShape>(); PauseGameManager.Instance.register(this, gameObject); }
protected void Start() { body = GetComponent <ChipmunkBody>(); shape = GetComponent <ChipmunkShape>(); if (body == null) { Debug.LogError("Your SideScrollerController is not configured properly! Add a body!"); } }
void Awake() { jump = GetComponent <Jump>(); idle = GetComponent <Idle>(); crouch = GetComponent <Crouch>(); body = GetComponent <ChipmunkBody>(); walkAC = AnimateTiledConfig.getByName(gameObject, EnumAnimateTiledName.Walk, true); agUpdater = GetComponent <AirGroundControlUpdater>(); lookingRight = true; }
protected void Start() { body = GetComponent <ChipmunkBody>(); controller = GetComponent <SideScrollerController>(); if (body == null) { Debug.LogError("Your PlayerController is not configured properly! Add a body!"); } startPos = body.position; spriteScale = sprite.transform.localScale; }
public static void ChipmunkBodyDestroy(ChipmunkBody b, ChipmunkShape s) { if (s != null) { s.enabled = false; // makes the shape to be removed from the space } if (b != null) { b.enabled = false; // registering a disable body will remove it from the list ChipmunkInterpolationManager._Register(b); } }
protected void UpdateParentBody() { ChipmunkBody body = this.GetComponentUpwards <ChipmunkBody>(); if (body != this.body && space != null) { space._Remove(this); CP.cpShapeSetBody(_handle, body == null ? space._staticBody : body.handle); space._Add(this); } this.body = body; }
protected Matrix4x4 BodyRelativeMatrix(ChipmunkBody body) { if (body != null) { Matrix4x4 bmatrix = body.transform.worldToLocalMatrix; Vector3 bodyScale = body.transform.localScale; return(Matrix4x4.Scale(bodyScale) * bmatrix * this.transform.localToWorldMatrix); } else { return(this.transform.localToWorldMatrix); } }
protected void RegisterHelper(ChipmunkBody body) { if (!body.enabled || body._interpolationMode == ChipmunkBodyInterpolationMode.None) { // Remove disabled or non-interpolating bodies bodies.Remove(body); this.enabled = (bodies.Count > 0); } else if (!bodies.Contains(body)) { // Add enabled, interpolating ones. bodies.Add(body); this.enabled = true; } }
private void AddBox() { var go = Instantiate(prefab, RandomPos(), Quaternion.identity) as GameObject; ChipmunkBody body = go.GetComponent <ChipmunkBody>(); if (body != null) { bodies.Add(body); } else { transforms.Add(go.transform); } }
protected bool ChipmunkBegin_player_jumpshroom(ChipmunkArbiter arbiter) { ChipmunkShape player, shroom; arbiter.GetShapes(out player, out shroom); if (arbiter.GetNormal(0).y < -0.9f) { ChipmunkBody body = player.GetComponent <ChipmunkBody>(); body.velocity = new Vector2(body.velocity.x, 50f); return(false); } else { return(true); } }
protected void OnEnable() { if (_handle == IntPtr.Zero) { Debug.LogError("ChipmunkConstraint handle is not set."); return; } bodyA = this.GetComponentUpwards <ChipmunkBody>(); CP.ConstraintSetBodies(_handle, handleA, handleB); UpdateConstraint(); // add to space: space = Chipmunk.manager._space; space._Add(this); }
public void _Add(ChipmunkBody obj) { PostStepFunc del = delegate(){ // Debug.Log("Adding body."); bodies.Add(obj); CP.cpSpaceAddBody(_handle, obj.handle); }; if (locked) { _AddPostStepCallback(_handle, obj.handle, del); } else { del(); } }
/// Unity doesn't provide notification events for when a transform is modified. /// Unfortunately that means that you need to call this to let Chipmunk know when you modify a transform. public static void UpdatedTransform(GameObject root) { HashSet <ChipmunkBody> bodies = new HashSet <ChipmunkBody>(); foreach (ChipmunkBinding.Base component in root.GetComponentsInChildren <ChipmunkBinding.Base>()) { ChipmunkBody affectedBody = component._UpdatedTransform(); if (affectedBody != null) { bodies.Add(affectedBody); } } // Update the mass properties of the bodies. foreach (ChipmunkBody body in bodies) { body._RecalculateMass(); } }
protected void FixedUpdate() { _space._Step(Time.fixedDeltaTime); for (int i = 0, c = _space.bodies.Count; i < c; ++i) { ChipmunkBody b = _space.bodies[i]; //b.transform.position = (Vector3) b.position + (Vector3.forward * b._savedZ); // Next lines do the same than above line Vector3 thePos = b.transform.position; thePos.x = b.position.x; thePos.y = b.position.y; thePos.z = b._savedZ; b.transform.position = thePos; // next rotation operation seems to be the fastest, since it immediately executes internal call to engine api b.transform.rotation = Quaternion.AngleAxis(b.angle * Mathf.Rad2Deg, Vector3.forward); } }
public static bool isHitFromAbove(float sourceMaxY, ChipmunkBody target, ChipmunkArbiter arbiter) { /// The collision normal is the direction of the surfaces where the two objects collided. /// Keep in mind that the normal points out of the first object and into the second. /// If you switch the order of your collision types in the method name, it will flip the normal around. // came from above? if (target.velocity.normalized.y < -COS_45) { // check collision points to be all above collider's height for (int i = 0, c = arbiter.contactCount; i < c; ++i) { if (sourceMaxY > (arbiter.GetPoint(i).y - arbiter.GetDepth(i))) { return(false); } } return(true); } return(false); }
private void updateGrounding() { // reset the grounding values to defaults _grounded = false; Vector2 groundNormal = GROUND_NORMAL; groundPenetration = 0f; ChipmunkBody groundBody = null; ChipmunkShape groundShape = null; // find the best (most upright) normal of something you are standing on body.EachArbiter(delegate(ChipmunkArbiter arbiter){ ChipmunkShape component, ground; arbiter.GetShapes(out component, out ground); Vector2 n = -arbiter.GetNormal(0); // magic threshold here to detect if you hit your head or not if (GameObjectTools.isCeiling(arbiter)) { // bumped your head, disable further jumping or whatever you need } else if (n.y > groundNormal.y) { _grounded = true; groundNormal = n; groundPenetration = -arbiter.GetDepth(0); groundBody = ground.body; groundShape = ground; } }); // To be well grounded, the slope you are standing on needs to be less than the amount of friction float friction = _grounded ? shape.friction * groundShape.friction : 0f; wellGrounded = grounded && Mathf.Abs(groundNormal.x / groundNormal.y) < friction; if (wellGrounded) { recentGroundVelocity = (groundBody != null ? groundBody.velocity : VECTOR_ZERO); } }