isFixedRotation bug?

Even if I add isFixedRotation = true to my main character, he starts to rotate when he hits my invisible walls.

local Scene = display.newGroup();  
  
--\> Invisible ground  
local ground = display.newRect(0,0,2024,1)  
ground:setReferencePoint(display.CenterReferencePoint)  
ground.x = 0  
ground.y = \_H + 55  
ground.objectType = "ground"  
physics.addBody(ground, "static", {friction=0, bounce = 0})  
player.isFixedRotation = true  
  

Am I missing something here or is this another bug?

Joakim [import]uid: 81188 topic_id: 15610 reply_id: 315610[/import]

Hey there,

I tested isFixedRotation earlier today (as part of another thread you were also involved with) and couldn’t fault it.

Can you provide code to test with? What you are showing is only you setting up a ground and stating the player is fixed rotation - but we can’t see you adding the player, the walls, his movement or collision with said walls, etc. [import]uid: 52491 topic_id: 15610 reply_id: 57743[/import]

Hi,

Yes I can send the code but the place where you file bugs just allows fileattachment of 800KB. With my spritesheets its more over 3MB.

Below is all the code anyway and I am running release 621,

player.lua

module(..., package.seeall)  
  
  
require "sprite"  
physics = require("physics")  
physics.start()  
physics.setGravity(0, 1.5)   
physics.setScale(38)  
  
  
GUI\_STATE = ""  
SPRITE\_STATE = ""  
STAT\_LIVES = 3  
  
--\> Skapa mark, tak och väggar  
local Scene = display.newGroup();  
  
--\> Skapa en osynlig mark  
local ground = display.newRect(0,0,2024,1)  
ground:setReferencePoint(display.CenterReferencePoint)  
ground.x = 0  
ground.y = \_H + 55  
ground.objectType = "ground"  
physics.addBody(ground, "static", {friction=0, bounce = 0})  
  
--\> Skapa en osynlig vägg till vänster  
local left\_wall = display.newRect(0,0,1,\_H)  
left\_wall:setReferencePoint(display.CenterReferencePoint)  
left\_wall.x = -20  
left\_wall.y = \_H \* 0.5  
  
--\> Skapa en osynlig vägg till höger  
local right\_wall = display.newRect(0,0,5,\_H)  
right\_wall:setReferencePoint(display.CenterReferencePoint)  
right\_wall.x = \_W +30  
right\_wall.y = \_H \* 0.5  
physics.addBody(right\_wall,"static")  
  
--\> Skapa en osynlig himmel  
local top = display.newRect(0,0,2024,1)  
top:setReferencePoint(display.CenterReferencePoint)  
top.x = 0   
top.y = -55  
physics.addBody(top, "static")  
physics.addBody(left\_wall, "static", {friction=0, bounce = 0})  
function loadSprite()   
  
 flyRightSheet = sprite.newSpriteSheetFromData( "chester.png", require("chester\_SH").getSpriteSheetData() )  
  
 spriteSet1 = sprite.newSpriteMultiSet(   
 {  
 { sheet = flyRightSheet, frames = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120}},   
 }  
 )  
  
 sprite.add(spriteSet1,"fly\_right",1,40,1000,0)  
 sprite.add(spriteSet1,"turn\_left",41,20,1000,1)  
  
 sprite.add(spriteSet1,"fly\_left",61,40,1000,0)   
 sprite.add(spriteSet1,"turn\_right",101,20,1000,1)  
  
end  
  
--\> Get current sprite sequence from chester  
local function getSpriteSeq(event)   
 SPRITE\_STATE = event.sprite.sequence  
end  
  
--\> Listen to  
local function spriteListener( event )  
 if(GUI\_STATE=="TL") then  
 player:prepare("turn\_left")  
 player:play()   
 GUI\_STATE =""  
 end  
  
 if(GUI\_STATE=="TR") then  
 player:prepare("turn\_right")  
 player:play()   
 GUI\_STATE =""  
 end  
  
 if(SPRITE\_STATE=="turn\_left" and event.sprite.currentFrame==20) then  
 player:prepare("fly\_left")  
 player:play()   
 end  
  
 if(SPRITE\_STATE=="turn\_right" and event.sprite.currentFrame==20) then  
 player:prepare("fly\_right")  
 player:play()   
 end  
  
end  
  
--\> Create Chester  
function createPlayer()  
 player = sprite.newSprite( spriteSet1 )  
 --\>player:setReferencePoint(display.CenterReferencePoint)  
 player.xScale = 2.0  
 player.yScale = 2.0  
 player.x = 200  
 player.y = 180  
 player.isFixedRotation = true  
  
 player.objectType = "player"  
 player:addEventListener("sprite", getSpriteSeq)  
 player:addEventListener( "sprite", spriteListener )  
 physics.addBody(player,{friction=.9, bounce = .1})  
 player:prepare("fly\_right")  
 player:play()   
end  
  
--\> Check to see if we are about to fly  
local function fly( event )  
  
 if not (player==nil) then  
 player:applyLinearImpulse(0, -.2, player.x, player.y)  
 energy.width = energy.width -1  
 end  
  
end  
  
--\> Check for movment from user  
local function moveforward( event)  
  
 if(event.phase=="began") then  
 x0 = event.x  
  
 end  
 if(event.phase=="moved") then  
  
 if(player==nil) then  
  
 else   
  
 if(x0 \< event.x) then  
 player:applyLinearImpulse(.02, 0, player.x, player.y)  
 --\>leanFormward()  
  
 if(SPRITE\_STATE=="fly\_left") then  
 GUI\_STATE = "TR"  
 end  
 else  
 player:applyLinearImpulse(-.02, 0, player.x, player.y)  
 --\>leanBackward()  
 if(SPRITE\_STATE=="fly\_right") then  
 GUI\_STATE = "TL"   
 end  
 end  
  
 end  
  
 end  
end  
  
function leanFormward()  
 transition.to( player, { rotation = 20, time=1000, onComplete = leanBack } )   
 player.isFixedRotation = true  
end  
  
function leanBackward()  
 transition.to( player, { rotation = -20, time=1000, onComplete = leanBack } )   
 player.isFixedRotation = true  
end  
  
function leanBack()  
 transition.to( player, { rotation = 0, time=800 } )   
 player.isFixedRotation = true  
end  
  
Runtime:addEventListener("touch", moveforward)  
Runtime:addEventListener("tap", fly)  
  

Main.lua

display.setStatusBar(display.HiddenStatusBar)  
  
\_W = display.contentWidth  
\_H = display.contentHeight  
  
--\> Get player logic & Physics  
local player = require("player")  
  
system.activate( "multitouch" )  
  
splash = display.newImage("splash.png",true)  
splash.x= \_W / 2  
splash.y = \_H / 2  
  
local function main()  
 splash:removeSelf()  
 splash = nil  
  
 player.init\_score()  
  
 player.loadSprite()  
 player.createPlayer()  
  
end  
  
timer.performWithDelay(500, main)  

[import]uid: 81188 topic_id: 15610 reply_id: 57766[/import]

.621 is not a stable version; are you having this error with a stable build? (The last stable build was .591 and daily builds are not guaranteed to work well, or even at all;))

Peach [import]uid: 52491 topic_id: 15610 reply_id: 57945[/import]

Ok, switched back to .591 but it behaves exactly the same.

The problem is that I want my character in a fixed position whatever he smashes into.

But I also want him to lean forward and backward and I guess that this is the problem. I add a small rotate to the character when he is moving forward, and viceversa backward.

That seems to set isFixedRotation to false, and he starts to spin around whenever he hits something.

Is this the way it is designed? or what is happening here?

Joakim

[import]uid: 81188 topic_id: 15610 reply_id: 58017[/import]

Joakim,

I have just noticed you are calling isFixedRotation BEFORE you add the physics body - try placing it AFTER you add the body and let me know results.

Thanks,
Peach :slight_smile: [import]uid: 52491 topic_id: 15610 reply_id: 58156[/import]

Great Peach, that did work out as it should!

Many thanks!

Joakim [import]uid: 81188 topic_id: 15610 reply_id: 58184[/import]

No worries, glad to hear it :slight_smile: [import]uid: 52491 topic_id: 15610 reply_id: 58334[/import]