actionscript 3 - Action Script 3. Platform game physics glitch (gravity) -
When my player touches the floor, he is unable to proceed because he is on the floor and is increasing.
I have an agitation in the main category
Personal function processation (): zero {if (touching ground) {if (its) is {character.jumpUp (); } If (leftKey) {character.moveLeft (); } if (rightKey) {character.moveRight (); } If (! Left that & amp;; right & amp;; above) {character.dontMove (); }}} Then in the character category you will see this. A public class player spreads onground {public war cannepain: boolean; Public Varun AN: Boolean; Public Wise Judge: Number = 18; Public function player () {addEventListener (Event.ADDED_TO_STAGE, OnAud); } Personal Function OnAd (E: Event): Zero {removeEventListener (Event.ADDED_TO_STAGE, OnAud); } Move Public Function (): Zero {// Decrease VELOCITY xV - = 2; If (xV> -7) {xV = -7; } This.gotoAndStop ("run"); // Add it to MC X position child this.x + = xV; This. ScaleX = -1; CharIsrunning = true; } Public Function Tray (): Zero {// Growth VELOCITY xV + = 2; If (xV> 7) {xV = 7; } This.gotoAndStop ("run"); // Add it to MC X position child this.x + = xV; This.scaleX = 1; CharIsrunning = true; } Public function dontMove (): Zero {// If no button is pressed then geto this and stop ("stop"); // slow down the ball xV * = friction; CharIsrunning = false; IsDefending = false; // If you are not running (xV> - 1 & amp; xV & lt; 1) then stop the ball {xV = 0; }} Override public function status Online (): zero {isJumping = false; /// = gotoAndStop (1); } Protection of public function (): zero {isDefending = true; this.gotoAndStop ("rescue"); CharIsrunning = false; } Public function attack (): zero {this.gotoAndStop ("attack"); } Public event jumpup (): zero {if (Isjumping) {isjumping = true; this.gotoAndStop ("jump"); //}}} }
Ongound is another class that runs the player, as you can see. Public class on-line movieclip {Public Gratitude: number; Public Violence Friction: Number; Public var xV: number; Public var yV: number; Protected var charIsrunning: boolean; Safe Work Defending: Boolean; Protected Virgining: Boolean; Public Event OnGround () {addEventListener (Event.ADDED_TO_STAGE, init) charIsrunning = false; IsDefending = false; // gotoAndStsop ("jump"); } Private work init (e: Event): zero {removeEventListener (Event.ADDED_TO_STAGE, init); // gravity grave = 0.6; // Y vel yV = 0; // x velocity xv = 0; // Friction = 0.9; AddEventListener (event .ENTER_FRAME, decline); } Pivot function collapses (E: Event): Add zero {// semen yV + = grav; Detection (YV); This.y + = yV} public function incrementUp (): zero {this.y - = 0.1; // trace ("enhance"); } Public Function keepOnGround (): zero {// trace ("on ground beach"); Guru = 0; yV = 0; PositionOnLand (); } Public function statusOnland (): Zero {// overide}} }
This is a function that is in the main category
For (var c: int = 0; c & lt; childrenOnStage; c ++) {if (getChildAt (c) .name == "player") {if (ground.level1Ground.hitTestPoint (getChildAt (c) ) .x + 13, getChildAt (c) .y, true) · ground.level1Ground.hitTestPoint (getChildAt (c) .x - 13, getChildAt (c) .y, true)) {getChildAt (c) .y -; // OnGround (getChildAt (c)) incrementUp () .; . OnGround (getChildAt (c)) keepOnGround (); Touchinggrad = true; } And {touching ground = false; } The problem is that when the player touches the ground, then the position of y will increase until he touches the ground and then it is placed on the ground to receive it = 0 and Y velocity 0
This means that gravity has been stopped and the player y position will not change (when I jump) or if it is placed on the ground after going down.
P> I appreciate it if someone can give me a hand or tell me in the right direction.
I'm not sure why you do not value gravity per object unless you really want to Examples of different objects are individual gravity.
If I do not refer to a gravity stability instead ...
Is a feature of anti-gravitational game? If not, I would like to avoid gravity 0. This can be 'work' (to an extent), but it is not a good model of reality / abstract.
Instead, what I will do is apply different force and current speed:
The force (bottom) of gravity applies all the time.
When you are standing on the ground, a force is applied equal to and above the gravity. When you jump, add an example of the upper force.
Use existing powers to change the current speed and use the current speed to change the situation.
Comments
Post a Comment