crouch enable

red moon

Member
I'm back this time with a question about setting up crouch.

I went ahead and setup the sprites and added a crouch animation set, set the sprites then directed them to the left and right crouch image associated with them. I then added a move down script and set the controller inputs to down right and down left since I was unsure how it determined facing. This resulted in the sprites being scrambled. What is the proper way to go about doing a couch and release to previous state (standing idle) ?
Thanks!
 

Attachments

  • crouch.jpg
    crouch.jpg
    770.6 KB · Views: 2,372

dale_coop

Moderator
Staff member
Here's some scripts for crouch idle (using DOWN LEFT and DOWN RIGHT)...

A "StartCrouch.asm" script:
Code:
	LDX player1_object

	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;;;; this is for platform game.
	GetCurrentActionType player1_object
	CMP #$03 ;; attack
	BEQ +
	CMP #$01
	BEQ +
	LDA Object_physics_byte,x
	AND #%00000001 ;; is it on the ground?
	BEQ +
	ChangeObjectState #$01, #$04
	JMP +
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;;;;;;;;;;; END PLATFORM TYPE GAME
+
	LDA Object_movement,x
	AND #%00000111
	CMP #%00000110	;; is the player curenlty facing left ?
	BNE ++
	;; player was facing left:
	FaceDirection player1_object, FACE_DOWN_LEFT
	JMP +
	++
	CMP #%00000010	;; is the player curenlty facing right ?
	BNE + 
	;; player was facing right:
	FaceDirection player1_object, FACE_DOWN_RIGHT
	
+
    RTS


A "StopCrouch.asm" script:
Code:
;;;; STOP PLAYER FROM MOVING LEFT
;;; Here, we will stop the player from moving,  
	StopMoving player1_object, STOP_LEFT
	GetCurrentActionType player1_object
	CMP #$02 ;; if the state is invincible
	BEQ + 
	CMP #$03
	BEQ + ; skip if we are casting spell
	LDX player1_object

;;; and we will change the object state to idle.
	ChangeObjectState #$00, #$04  

	LDA Object_movement,x
	AND #%00000111
	CMP #%00000111	;; is the player was down left ?
	BNE ++
	;; player was facing left:
	FaceDirection player1_object, FACE_LEFT
	JMP +
	++
	CMP #%00000001	;; is the player was down right ?
	BNE +	
	;; player was facing right:
	FaceDirection player1_object, FACE_RIGHT
	
+ 
    RTS


To assign to your inputs ("hold" down and "release" down)
 

red moon

Member
Excellent, thank you so much! I will set this up after work and let you know how it goes.

A final question, is there a release for the ladder animation loop?
I imagine the script would function in a similar manner to stop the animation sequence when up or down is released.
 

dale_coop

Moderator
Staff member
The ladder is hard coded... when you on ladder tile tile, it will set the action step 4.
When no more on a ladder tile, you’ll be set back to the action step 0.
 

red moon

Member
hmmm, I did not know that. Interesting...maybe this will change in the future when mods are updated. Thanks for letting me know.
 

red moon

Member
Dale, I added the input scripts and for some reason it did not work. Let me know if you see anything wrong in these screenshots. I did have a question, the crouch has a single animation on the sheet and it's mirrored for left and right facing; but the animation Down slot only has one choice...
Thanks for the help with this one!

I did do a test deleting the crouchleft and couchright choices and replaced it with a single crouch animation sprite option. I thought there might have been a conflict with the two choices, with both choices having left or right attached to them.
 

Attachments

  • screen1.jpg
    screen1.jpg
    695.5 KB · Views: 2,335
  • screen2.jpg
    screen2.jpg
    651.6 KB · Views: 2,334
  • screen3.jpg
    screen3.jpg
    602.9 KB · Views: 2,336

dale_coop

Moderator
Staff member
Don't make a new "Animation Type", just use the "Idle" animation type, and assign the crouchLeft and crouchRight animations for the diagonals "Down Left" and "Down Right".

Also, in your Input Editor, assign the the "HOLD" instead of the "PRESS".
 

red moon

Member
Excellent, thank you Dale! That did the trick. It's working which is great.

I now slide down ladders really fast, but they are functional at least!

I am curious about the player's default collision state, is there a way to have varying collision states? That way ducking works correctly and allows for projectile avoidance.
 

dale_coop

Moderator
Staff member
For the ladder, forgot about that, maybe a small modfication would be required (to check if on a ladder to prevent from crouching)
I am not sure what you mean by "default collision state". The default player state is idle (action step 0...), now when input scripts are executed, the code of those scripts check if the player is this state or that state... to prevent/allow to the code to continue (and change the action step accordingly).
So, if you have your logic ready for crouch/projectile/walk/... you can write the cheks needed for each script.

Don't forget that each state (idle/walk/attack/jump/climb) uses it's own action step. When you execute the script for attacking/shooting (by pressing the b button), it will change the player action step to the "Attack/shoot" one. if you're crouching and are able to shoot, the player will change to the Attacking/Shooting action step (and no more crouched Idle) :p
Etc...
 

Mugi

Member
to set "skip top collision"
Code:
    LDA Object_vulnerability,x
    ORA #%10000000
    STA Object_vulnerability,x

to remove "skip top collision"
Code:
    LDA Object_vulnerability,x
    AND #%01111111
    STA Object_vulnerability,x
 

red moon

Member
Thank you both and I appreciate the response either way, and that script will help greatly Mugi, thank you!

I will drop the new script into CrouchStart and Crouch Stop asm to disable/enable top collision. I am guessing it keeps any collision in the lower 16x16 block intact but disables anything above it.
 

Mugi

Member
objects in nesmaker engine use a 6-point collision system in a following configuration

0 1
4 5
3 2

using the "skip top collision" makes your object ignore the collisionpoints 0 and 1 when it's hit. effectively using it halves the height of your object.

also note that collision points are not in any way bound to the object's graphics, or the 8x8 tile grid. they are exclusively bound to the hit box (or bounding box as nesmaker calls it) which can be of any size inside your object.
skipping top collision halves the hitbox, not the object itself.
 

red moon

Member
The breakdown is really helpful for explaining how the code work, much appreciated Mugi. And i kept referring to the bounding box as collision in that regard!
 

Dirk

Member
@dale_coop: Do you know a way to make your crouch script compatible with 4.0? Compiling gives the error, that Object_physics_byte isn't defined. I tried to find out what was used instead of Object_physics_byte in 4.0, but had no luck
 

dale_coop

Moderator
Staff member
I think for 4.0, it's way more complicated... because in the code engine, "skipping top collision" is not implemented. So while in 4.1, it's just a flash to set, in the 4.0 you'd have to add all the code in the collision detection and calculations >_<
 

Dirk

Member
Okay, thank you. Do you know if there is a way to make just the crouch animation without skipping the top collision?
 

dale_coop

Moderator
Staff member
Take a look at mugi's post:
http://nesmakers.com/viewtopic.php?f=35&t=1731&p=15347
(I think his is compatible with the 4.0)
 

Mugi

Member
my codes are more or less all made for 4.1.4 but action stage / input stuff hasn't really changed anywhere so that should work on all versions.
 
Top Bottom