Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411508 Posts in 69374 Topics- by 58429 Members - Latest Member: Alternalo

April 26, 2024, 08:27:59 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsCommunityTownhallForum IssuesArchived subforums (read only)TutorialsHelp with space shooter and room rotation?
Pages: [1]
Print
Author Topic: Help with space shooter and room rotation?  (Read 1834 times)
eddieion
Guest
« on: April 07, 2013, 03:50:03 PM »

Hey guys - sorry if this isn't quite in the right place.

http://speedy.sh/Js29C/example.gmk

I'm trying to get a basic space shooter working, and ideally would like the player object to face the top of the screen at all times whilst the room rotates around the player object when left and right directional buttons are pushed.

That isn't what's happening at the moment though - atm both the room view  and the ship rotates (the ship slightly faster than the view). Sorry if that doesn't much sense, it's late and i've been trying to get this working for a while.

Any help is really really appreciated!

Creation event:

x_speed = 0
y_speed = 0
acc_speed = 0.5 //acceleration
speed_friction = 0.95 //1 = no friction  

Step event:

view_angle[0] = direction
image_angle = direction

//step event
if keyboard_check(vk_left) direction += 3
if keyboard_check(vk_right) direction -= 3

if keyboard_check(vk_up) {
x_speed += lengthdir_x(acc_speed, direction)
y_speed += lengthdir_y(acc_speed, direction)
}

if keyboard_check(vk_down) {
x_speed -= lengthdir_x(acc_speed, direction)
y_speed -= lengthdir_y(acc_speed, direction)
}

x += x_speed  



Edit: Sorry for the swearing in the title literally didn't even realise i'd written that!  
Edit: Example of the file at the star of post.
« Last Edit: April 07, 2013, 04:36:05 PM by eddieion » Logged
Glyph
Level 10
*****


Relax! It's all a dream! It HAS to be!


View Profile
« Reply #1 on: April 07, 2013, 03:54:57 PM »

Hey guys - sorry if this isn't quite in the right place.

I'm trying to get a basic space shooter working, and ideally would like the player object to face the top of the screen at all times whilst the room rotates around the player object when left and right directional buttons are pushed.

That isn't what's happening at the moment though - atm both the room view  and the ship rotates (the ship slightly faster than the view). Sorry if that doesn't much sense, it's late and i've been trying to get this working for a while.

Any help is really really appreciated!

Creation event:

x_speed = 0
y_speed = 0
acc_speed = 0.5 //acceleration
speed_friction = 0.95 //1 = no friction  

Step event:

view_angle[0] = direction
image_angle = direction


//step event
if keyboard_check(vk_left) direction += 3
if keyboard_check(vk_right) direction -= 3

if keyboard_check(vk_up) {
x_speed += lengthdir_x(acc_speed, direction)
y_speed += lengthdir_y(acc_speed, direction)
}

if keyboard_check(vk_down) {
x_speed -= lengthdir_x(acc_speed, direction)
y_speed -= lengthdir_y(acc_speed, direction)
}

x += x_speed    

Just move the part I bolded to the very end of the code... I think that should solve your problem!
Logged


eddieion
Guest
« Reply #2 on: April 07, 2013, 04:20:24 PM »

Unfortunately that didn't work. At the moment the ship is rotating whereas I want it to be fixed in the very center of the screen so that everything else moves around it.

image_angle=direction //Makes sure the sprite is facing the direction of the object. (But really I want the object and the sprite to remain facing the top of the screen)

view_angle[0]=direction // Is working but along with the rotation of the ship as well makes for a very confusing, dizzy experience!

^ If that makes any more sense to anyone.
Logged
Glyph
Level 10
*****


Relax! It's all a dream! It HAS to be!


View Profile
« Reply #3 on: April 07, 2013, 05:28:14 PM »

oh, yeah,

view_angle=direction

should be

view_angle=-direction

and also make sure that your sprite's origin is centered! Perhaps that will work for you.
Logged


eddieion
Guest
« Reply #4 on: April 07, 2013, 05:43:05 PM »

Thank you very much!  Smiley i've got it centered and with a rotating view now. The only small issue now is that it is still moving to the right when i press the up key.


if keyboard_check(vk_up) {
y_speed += lengthdir_y(acc_speed, direction)
x_speed += lengthdir_x(acc_speed, direction)

}

if keyboard_check(vk_down) {
y_speed -= lengthdir_y(acc_speed, direction)
x_speed -= lengthdir_x(acc_speed, direction)
}

x += x_speed
y += y_speed


I've tried messing around with this for ages but the object only ever seems to want to move left or right no matter what I try.     
Logged
Sean A.
Level 8
***



View Profile
« Reply #5 on: April 22, 2013, 02:57:14 PM »

Is your sprite set up properly in the sprite editor. In Game Maker, 0 degrees is to the right so the default image for the ship should be facing right, that way it will always be pointing in the correct direction. That may not be the issue but it's something to check.
Logged
Serapth
Level 2
**


View Profile
« Reply #6 on: April 22, 2013, 04:45:31 PM »

I'm thinking Sean has the right of it. Even though you and I think zero is up, many functions treat 90 degrees to the right as zero.

Read this http://www.gamefromscratch.com/post/2012/11/18/GameDev-math-recipes-Rotating-to-face-a-point.aspx
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic