Remember me
You are here: HomeForumCyberix3D ForumJob OfferingsAdvances of my game
Welcome, Guest
Username: Password: Remember me

TOPIC: Rotation Problem

Rotation Problem 1 year 9 months ago #3112

I've been working on a new movement system for both third person and first person and I keep running into this problem where if the player (in this case a cylinder) rotates beyond 90 degrees it starts rotating fast like crazy.

I'm not sure if this is a bug but I need some help fixing.

Here in the video you can see in the top left, when the rotation goes beyond 90 it'll start glitching out:



Source code:
<GameMaker3D original="0" use2dHierarchy="1" guid="ED90DB4A-33AB-CE4A-A723-A157F6B1239C">
  <Level name="thirdperson" isCollapse="0">
    <SkyBox right="right.jpg" left="left.jpg" top="top.jpg" bottom="bottom.jpg" front="front.jpg" back="back.jpg" guid="D26F7083-456E-FF05-0FA0-A1588A382FA0" name="SkyBox1"/>
    <Plane collision="1" static="1" guid="D591363E-31AE-330F-F58A-A158A6DDD6E7" castShadowsEnable="1" name="ground" xAxis="0" yAxis="0" zAxis="0" scaleX="10" scaleY="10" scaleZ="10"/>
    <Cylinder collision="1" static="1" guid="1C387862-5BF3-D356-EB56-A159BA29BCA6" castShadowsEnable="1" x="0" y="-8" z="0" scaleX="0.4" scaleY="0.8" scaleZ="0.4" yAxis="60" name="player" isCollapse="0" visible="1">
      <Loop isCollapse="1">
        <IfKey key="W" isCollapse="1">
          <Set var="localRotationY" value="camera.rotationY"/>
          <Set var="input.text" value="W" isCollapse="1"/>
        </IfKey>
        <IfKey key="A" isCollapse="1">
          <Set var="localRotationY" value="camera.rotationY-90" isCollapse="1"/>
          <Set var="input.text" value="A" isCollapse="1"/>
        </IfKey>
        <IfKey key="D" isCollapse="1">
          <Set var="localRotationY" value="camera.rotationY+90"/>
          <Set var="input.text" value="D" isCollapse="1"/>
        </IfKey>
        <IfKey key="S" isCollapse="1">
          <Set var="localRotationY" value="camera.rotationY-180"/>
          <Set var="input.text" value="S"/>
        </IfKey>
      </Loop>
      <Cube collision="1" static="1" castShadowsEnable="1" name="look_dir" height="15" x="0" y="83.65" z="141.02" width="25" depth="200"/>
    </Cylinder>
    <Cube collision="0" static="1" castShadowsEnable="1" name="cam_target" isCollapse="1" scaleY="0.2" scaleZ="0.2" scaleX="0.2" x="0.00" y="0.00" z="0.00" copyDir="Same Position">
      <Loop isCollapse="1">
        <Set var="x" value="player.x"/>
        <Set var="y" value="player.y+50"/>
        <Set var="z" value="player.z"/>
      </Loop>
      <Comment comment="what the camera will rotate towards"/>
    </Cube>
    <Cube collision="0" static="1" castShadowsEnable="1" name="cam_pos" isCollapse="1" scaleY="0.2" scaleZ="0.2" scaleX="0.2">
      <Loop isCollapse="1">
        <Comment comment="cam rot inputs"/>
        <IfKey key="L" isCollapse="1">
          <Increment var="cam_pos.rotationY" value="2"/>
        </IfKey>
        <IfKey key="J" isCollapse="1">
          <Increment var="cam_pos.rotationY" value="-2"/>
        </IfKey>
        <IfKey key="I" isCollapse="1">
          <Increment var="cam_pos.rotationX" value="2"/>
        </IfKey>
        <IfKey key="K" isCollapse="1">
          <Increment var="cam_pos.rotationX" value="-2"/>
        </IfKey>
        <Comment comment="cameraXYZ = thisXYZ"/>
        <Set var="camera.y" value="cam_pos.y"/>
        <Set var="camera.x" value="cam_pos.x"/>
        <Set var="camera.z" value="cam_pos.z"/>
        <Comment comment="thisXYZ = playerXYZ"/>
        <Set var="x" value="player.x"/>
        <Set var="y" value="player.y"/>
        <Set var="z" value="player.z"/>
        <Set var="translateZ" value="-1000"/>
        <Set var="cam_pos.rotationX"/>
      </Loop>
    </Cube>
    <OnReady isCollapse="1">
      <CameraController name="cam" mouseLock="1" forceFullScreen="1" controllerType="lookAt" lookAtObject="cam_target"/>
    </OnReady>
    <Label name="camrot_x_display" text="x" isCollapse="1" x="0"/>
    <Label name="camrot_y_display" text="y" isCollapse="1" x="0.00" y="10.00" copyDir="Same Position"/>
    <Label name="camrot_x_stats" x="10.00" isCollapse="1">
      <Loop>
        <Set var="camrot_x_stats.text" value="cam_pos.rotationX"/>
      </Loop>
    </Label>
    <Label name="camrot_y_stats" x="10.00" isCollapse="1" y="10.00" copyDir="Same Position">
      <Loop>
        <Set value="cam_pos.rotationY" var="camrot_y_stats.text"/>
      </Loop>
    </Label>
    <Message name="controls" text="IJKL to control camera&#xD;WASD to Move"/>
    <Label name="input" y="25.00"/>
  </Level>
</GameMaker3D>
Last Edit: 1 year 9 months ago by Symbiotic Interactives.
The administrator has disabled public write access.

Rotation Problem 1 year 9 months ago #3114

  • cyberix3d
  • cyberix3d's Avatar
  • OFFLINE
  • Administrator
  • Posts: 703
  • Thank you received: 697
Greetings,

When it comes to applying rotation to a collision object, it can pose some difficulties.
Therefore, we recommend using the "Rotate Towards" command instead.

To illustrate this, please refer to the following example:
www.gamemaker3d.com/player?pid=01663440
<GameMaker3D original="1" use2dHierarchy="1" guid="9580753E-744F-D43D-5770-DC6C19E1F439">
  <Level name="thirdperson" isCollapse="0">
    <SkyBox right="right.jpg" left="left.jpg" top="top.jpg" bottom="bottom.jpg" front="front.jpg" back="back.jpg" guid="D26F7083-456E-FF05-0FA0-A1588A382FA0" name="SkyBox1"/>
    <Plane collision="1" static="1" guid="D591363E-31AE-330F-F58A-A158A6DDD6E7" castShadowsEnable="1" name="ground" xAxis="0" yAxis="0" zAxis="0" scaleX="10" scaleY="10" scaleZ="10"/>
    <Cylinder guid="1C387862-5BF3-D356-EB56-A159BA29BCA6" castShadowsEnable="1" x="0" y="-8" z="0" scaleX="0.4" scaleY="0.8" scaleZ="0.4" yAxis="60" name="player" isCollapse="0" visible="1">
      <Loop isCollapse="0">
        <IfKey key="W" isCollapse="0">
          <Set var="input.text" value="W" isCollapse="1"/>
          <RotateTowards targetObject="Camera" yAngle="1" xAngle="0" zAngle="0" rotationY="180"/>
        </IfKey>
        <IfKey key="A" isCollapse="0">
          <RotateTowards targetObject="Camera" yAngle="1" xAngle="0" zAngle="0" rotationY="90"/>
          <Set var="input.text" value="A" isCollapse="1"/>
        </IfKey>
        <IfKey key="D" isCollapse="0">
          <RotateTowards targetObject="Camera" yAngle="1" xAngle="0" zAngle="0" rotationY="-90"/>
          <Set var="input.text" value="D" isCollapse="1"/>
        </IfKey>
        <IfKey key="S" isCollapse="0">
          <RotateTowards targetObject="Camera" yAngle="1" xAngle="0" zAngle="0"/>
          <Set var="input.text" value="S"/>
        </IfKey>
      </Loop>
      <Cube collision="1" static="1" castShadowsEnable="1" name="look_dir" height="15" x="0" y="83.65" z="141.02" width="25" depth="200" guid="6AFE7FA9-206A-68EE-050B-DC606C057B34"/>
    </Cylinder>
    <Cube collision="0" static="1" castShadowsEnable="1" name="cam_target" isCollapse="0" scaleY="0.2" scaleZ="0.2" scaleX="0.2" x="0.00" y="0.00" z="0.00" copyDir="Same Position" guid="5F79478B-B51B-EC7C-7D41-DC606C05083C">
      <Loop isCollapse="0">
        <Set var="x" value="player.x"/>
        <Set var="y" value="player.y+50"/>
        <Set var="z" value="player.z"/>
      </Loop>
      <Comment comment="what the camera will rotate towards"/>
    </Cube>
    <Cube collision="0" static="1" castShadowsEnable="1" name="cam_pos" isCollapse="0" scaleY="0.2" scaleZ="0.2" scaleX="0.2" guid="012299C7-288E-4618-76B1-DC606C0E54F5">
      <Loop isCollapse="0">
        <Comment comment="cam rot inputs"/>
        <IfKey key="L" isCollapse="1">
          <Increment var="cam_pos.rotationY" value="2"/>
        </IfKey>
        <IfKey key="J" isCollapse="1">
          <Increment var="cam_pos.rotationY" value="-2"/>
        </IfKey>
        <IfKey key="I" isCollapse="1">
          <Increment var="cam_pos.rotationX" value="2"/>
        </IfKey>
        <IfKey key="K" isCollapse="1">
          <Increment var="cam_pos.rotationX" value="-2"/>
        </IfKey>
        <Comment comment="cameraXYZ = thisXYZ"/>
        <Set var="camera.y" value="cam_pos.y"/>
        <Set var="camera.x" value="cam_pos.x"/>
        <Set var="camera.z" value="cam_pos.z"/>
        <Comment comment="thisXYZ = playerXYZ"/>
        <Set var="x" value="player.x"/>
        <Set var="y" value="player.y"/>
        <Set var="z" value="player.z"/>
        <Set var="translateZ" value="-1000"/>
        <Set var="cam_pos.rotationX"/>
      </Loop>
    </Cube>
    <OnReady isCollapse="1">
      <CameraController name="cam" mouseLock="1" forceFullScreen="1" controllerType="lookAt" lookAtObject="cam_target"/>
    </OnReady>
    <Label name="camrot_x_display" text="x" isCollapse="1" x="0" guid="2CEB74A8-D048-85FC-63B1-DC606C2C4E69"/>
    <Label name="camrot_y_display" text="y" isCollapse="1" x="0.00" y="10.00" copyDir="Same Position" guid="ED63E066-573C-A684-6CBE-DC606C2DE259"/>
    <Label name="camrot_x_stats" x="10.00" isCollapse="1" guid="9EBC76D4-3C86-38D3-F359-DC606C2D5367">
      <Loop>
        <Set var="camrot_x_stats.text" value="cam_pos.rotationX"/>
      </Loop>
    </Label>
    <Label name="camrot_y_stats" x="10.00" isCollapse="1" y="10.00" copyDir="Same Position" guid="9FC73819-B6A8-F543-7141-DC606C30D425">
      <Loop>
        <Set value="cam_pos.rotationY" var="camrot_y_stats.text"/>
      </Loop>
    </Label>
    <Message name="controls" text="IJKL to control camera&#xD;WASD to Move" guid="3C3AC39C-53B7-965A-CD55-DC606C3835AB"/>
    <Label name="input" y="25.00" guid="084E76FD-4C0A-B0E9-9838-DC606C39DF40"/>
  </Level>
</GameMaker3D>

Best regards,
The Cyberix3D Team
The administrator has disabled public write access.
The following user(s) said Thank You: Symbiotic Interactives

Rotation Problem 1 year 9 months ago #3115

Thank you so much it works perfectly!

Here's how it looks now with added movement:


Still needs work before releasing but I'm happy with how it is.
Last Edit: 1 year 9 months ago by Symbiotic Interactives.
The administrator has disabled public write access.

Rotation Problem 1 year 9 months ago #3116

  • cyberix3d
  • cyberix3d's Avatar
  • OFFLINE
  • Administrator
  • Posts: 703
  • Thank you received: 697
It's great to hear that your game featuring a dynamic third-person controller is progressing well.
We are confident that it will turn out fantastic with the additional improvements you're implementing.
Keep up the excellent work!
The administrator has disabled public write access.
The following user(s) said Thank You: Symbiotic Interactives
Time to create page: 0.080 seconds