9Panzer
Well-known member
I've been a bit hesitant to share my code since it doesn't always work the same way in other people's projects as it does in mine. As a result, I often get flooded with messages from people insisting it's broken and demanding tech support—like I somehow owe them for publishing it. But recently, while helping RetroBro with his project, he convinced me that this one was worth sharing.
So, enough complaining—let's get to the good stuff! This is a simple yet effective script that adds a touch of realism to your flying objects. It gives them a natural bobbing motion, making them feel more alive and dynamic. Just plug it in, and watch your objects hover with style!
Examples:
Frontiers:
TheRetroBros
The Adventures of Panzer 3
1. First things first. You are going to need 3 Variables.
Bobbing1
Bobbing2
myTinyTimer
2. Next, open your HandleGameTimer and add:
3. Open your Handle Physics and add this:
After you pop this in you should now have a bobbing object!
One important thing to keep in mind with this code is that it forces the object to move up and down. While it works well for AI-driven horizontal movement, the object will still be pushed into solid surfaces above or below, potentially causing it to get stuck. Keep this in mind when designing your levels!
Good luck!
So, enough complaining—let's get to the good stuff! This is a simple yet effective script that adds a touch of realism to your flying objects. It gives them a natural bobbing motion, making them feel more alive and dynamic. Just plug it in, and watch your objects hover with style!
Examples:
Frontiers:
TheRetroBros
The Adventures of Panzer 3
1. First things first. You are going to need 3 Variables.
Bobbing1
Bobbing2
myTinyTimer
2. Next, open your HandleGameTimer and add:
INC myTinyTimer
LDA myTinyTimer
CMP #03
BEQ +reset
JMP +DoneSequence
+reset
LDA #00
STA myTinyTimer
+DoneSequence
3. Open your Handle Physics and add this:
- LDA Object_type,x ;;;
CMP #23; Helicopter ;; ADD THE OBJECT NUMBER THAT YOU WANT TO BOB HERE
BEQ +bobbing
JMP +NotHelicopter
+bobbing
LDA vBlankTimer
AND #%00000001
BNE +runCode
Jmp +EndBobbing
+runCode
LDA myTinyTimer
CMP #01
BEQ +runCode
Jmp +EndBobbing
+runCode
LDA Bobbing1 ; Initialize a counter for bobbing movement
; Compare with a threshold value (e.g., 10 or any suitable value)
CMP #8
; If the counter is below the threshold, increment it and continue bobbing
BCC +IncrementCounter
; If the counter reaches the threshold, reset it and change the bobbing direction
LDA #00
STA Bobbing1
LDA Bobbing2
EOR #01 ; Toggle bobbing direction (e.g., from up to down or vice versa)
STA Bobbing2
+IncrementCounter ; Label +
; Increment the bobbing counter
LDA Bobbing1
CLC
ADC #01
STA Bobbing1
; Check the bobbing direction (0 for up, 1 for down)
LDA Bobbing2
CMP #00
; If bobbing up, decrement Object_y_hi,x by 1
BEQ +BobUp
; If bobbing down, increment Object_y_hi,x by 1
JMP +BobDown
+BobUp ; Label +
LDA Object_y_hi,x
SEC
SBC #01
STA Object_y_hi,x
JMP +EndBobbing
+BobDown ; Label +
LDA Object_y_hi,x
CLC
CLC
ADC #01
STA Object_y_hi,x
+EndBobbing ; Label +
+NotHelicopter
After you pop this in you should now have a bobbing object!
One important thing to keep in mind with this code is that it forces the object to move up and down. While it works well for AI-driven horizontal movement, the object will still be pushed into solid surfaces above or below, potentially causing it to get stuck. Keep this in mind when designing your levels!
Good luck!
Last edited: