4.5 solid detection with grid based movement

jcramer

New member
I want to add a few finishing touches to my space walk game that I couldn't figure out how to do.

The grid based movement causes the player to not stop on solid tiles. Is there something I can add to the solid tile or player that can make solid boundaries?
 

Jonny

Well-known member
If the solid tile type doesn't work, is there a way you could use a monster for the solid block and set your players reaction to stop when they colide? Also, if they were monsters and not tiles, you could have day / night mosters so the solid blocks change mid level.

Is it a custom code for the grid movement causing the problem?
 

jcramer

New member
I do have 1 monster I could use on any screen, but there's a lot of grid to cover. Someone told me on the FB group that I could use a game object that follows the player and use a variable to check for solid collisions, but I didn't have any luck making it work.
 

Jonny

Well-known member
I see. I thought it was just a couple of solid blocks per screen. I hope you get it sorted because the game looks great.
 

jcramer

New member
Thanks, I appreciate that. I'm happy with the game, it just has this one flaw that makes it more frustrating than it needs to be.
 

mouse spirit

Well-known member
This may sound too roundabout but may strike up an idea. When you are on a certain ttile. Limit your inputs maybe. Like when on tiletype, stop moving right and cant press release right.
This may get too complex. But if its just left and right, this may work.
 

Pauldalyjr

Active member
You could do that with the tile types,that's a good idea. Would need like 18 that I can think of for all possible moves but I'm probably missing something.... This would be a good use for the multi tile(s).
 

mouse spirit

Well-known member
Yeah but i wonder how we would set it. It couldnt be by screen. Maybe you can wrap your head around it a lil better than me.
 

jcramer

New member
That's a good idea. I have a lot of tile space left. So basically...
Tile that blocks up and down
Tile that blocks left and right

4 tiles for corners.
Then I could use the multi tile for special cases where there's T shaped intersections.
 

Pauldalyjr

Active member
Im not sure how your inputs work exactly, but you may be able to remove the traditional input script method and have your movement strictly driven by what tile you are currently standing on. Would take a bit more work on the front end but it would work exactly how you wanted it to in the end.
 

AllDarnDavey

Active member
Do solid tile collision not work because for grid movement you're not setting normal StartMovement in your inputs, but Player_x_hi, ADC #$0F or whatever?

I would think the work around would be to put a collision check in the input script itself, and for example skip moving right, if there's a solid tile 16 pixels right of the player.
 

mouse spirit

Well-known member
Well kinda like if on tile , variable equalls 5.

When 5, can only move left or right.(in the input scripts, add checks to see what variable equals.

When on null tile, variable equals 0.

When 0, i can use any input.
 

jcramer

New member
Here's what I'm using for up. i tried mixing it with parts of the regular movement scripts but didn't work.

Code:
    LDX player1_object

; get horizontal offset of Player
    LDA Object_x_hi,x

; get vertical offset of Player
    LDA Object_y_hi,x
; get horizontal offset of Player


    LDA Object_y_hi,x	; load x offset of X (player1 is loaded in X above)
    SEC			; set carry
    SBC #$10		; substract 16 pixels (substract for moving up, add for moving down)
    STA Object_y_hi,x	; store the new value in player1's position
	
	;PlaySound #sfx_step
	
	RTS
 

mouse spirit

Well-known member
Like at the begining can you say....
LDA variable
CMP a number specific to the tile and this input
BEQ skipallcode

Like we do with isPaused.

So at the start of every input(dpad inputs) put this check.
But you would have to make a variable and some tiles like i was sayin earlier.
But i also am not good in 4.5 yet.

So on the right input and up input scripts say....
If variable 5, skipall code.
If not 5, let me do the code.
 

AllDarnDavey

Active member
jcramer said:
Here's what I'm using for up. i tried mixing it with parts of the regular movement scripts but didn't work.

That's what I thought... you're not using the normal physics movement system, just forcing an offset directly. Probably how I would've handled tile based movement too. But it means you bypass the normal tile collisions checks you'd get.

So the solution is to add those checks into your input scripts themselves.
Here's an example added to the moveUP script you posted.
Code:
    LDX player1_object
; get horizontal offset of Player
	LDA Object_x_hi,x ;; Get this object's origin location
	CLC
	ADC self_center_x
	;; add offset based on direction below
	STA tempA	
; get vertical offset of Player
	LDA Object_y_hi,x
	CLC
	ADC self_center_y
	;; add offset based on direction below
	;; look 1 tile up from player
	SEC 
	SBC #$10	
	STA tempB	
; check if tile is solid if so don't move
	GetCollisionPoint tempA, tempB, tempA
	CMP #$01
	BEQ +end
; if not solid move 1 tile

; set tempA to object x position for LR scripts
	;LDA tempA
	;STA Object_x_hi,x	; store the new value in player1's position
	
; set tempB to object y position for UD scripts	
	LDA tempB
	STA Object_y_hi,x	; store the new value in player1's position
	
	;PlaySound #sfx_step
	+end
	RTS

The other movement input scripts are just the same template, just adding or subtracting 16 pixels in either the x or y depending on the movement direction.
 

jcramer

New member
For some reason, it still doesn't work. Like if I set the solid object reaction to "destroy me" it'll kill the player, but stop doesn't work.
 

AllDarnDavey

Active member
jcramer said:
For some reason, it still doesn't work. Like if I set the solid object reaction to "destroy me" it'll kill the player, but stop doesn't work.
Hmm... definitely worked on my maze game test...

Is your solid tile, the second tile on the list tile #$01? This is hard coded to check for that. Also how big is your bounding box maybe make it a couple pixels smaller then a full tile, you might still be registering a hit on an adjacent tile by mistake.

This is just checking 1 tile above the center of the player, and ignoring the move up input unless that tile is not solid (tile #$01).
 
Top Bottom