im making a shoot em up that is a horizontal shooter.
the player is a child to the camera and is clamped inside the view.
i have the camera going around the playing field, the camera is a child to the waypoint manager.
the waypointmanager is the parent to all objects.
and the waypointmanager moves around to all waypoints and goes back to its origin.
for now, it goes in a circular motion. the camera is always looking towards the middle of the circle. -90 angle.
order:
parent-waypointmanager
1 child main camera
2 child player movement
3 child ship mesh
the problem is that when the parent is starting to get close to a Y axis close to 0, it also affects the player transform.Translate.
and when the Parent is -180 in the Y, the controls is backwards.
here is the player script.
how do i make it local for the transform.Translate controls?
using UnityEngine;
using System.Collections;
using Rewired;
[System.Serializable]
public class Boundary
{
public float xMin, xMax, yMin, yMax;
}
public class PlayerController : MonoBehaviour
{
public float speed;
public float tilt;
public Boundary boundary;
public Player player;
public int playerId = 0;
void Awake()
{
player = ReInput.players.GetPlayer(playerId);
}
private void Start()
{
}
void FixedUpdate()
{
float moveHorizontal = player.GetAxis("Move Horizontal");
float moveVertical = player.GetAxis("Move Vertical");
transform.Translate(transform.right * moveHorizontal * Time.deltaTime * speed);
transform.Translate(transform.up * moveVertical * Time.deltaTime * speed);
transform.localPosition = new Vector3(Mathf.Clamp(transform.localPosition.x, boundary.xMin, boundary.xMax),
Mathf.Clamp(transform.localPosition.y, boundary.yMin, boundary.yMax), Mathf.Clamp(transform.localPosition.z, 1, 1));
}
}
Ive switched over to rigidbody movement, and i still get the same results.
was hoping that the ridigbody physics would solve it.
but i have the same problem. when the parent (waypointmanager) is turning the entire heirarchy with all of its children, it also affects the direction of the getAxis inputs. -180 in Y flips gradualy the left/right into right/left on the joystick inputs.
please.
need help desperetly. im going out of my mind. nothing i do seems to solve this.
i was thinking that while the Waypointmanager goings on its stroll thru the level and turning its Y axis from 0 to -180, that it might be just best to make a static main parent on top of the waypoint manager. Making it the 0.0.0 parent. but i still get the same results when the waypointmanager turns around to the -180 Y axis. what is going on!?!
i seriously need help.
i just need to have a force that is relative to the local space the player is attached to.
its transform is always at 0.0.0.
the playing object moves as it should, tilting, horizontal/vertical moves. everything is fine except when its parent is turning its rotation on the Y axis. then the input force i put on the joystick is relating to the parents rotation, not the players local playing field.
if i unmark the second line of code for the vertical axis, the horizontal axis doesnt work.
any ideas how to write this in a better way?
its in a FixedUpdate.
but when i do the player moves towards the right(X axis) even thou if i use the same code but separate it moves in the Z axis (as in the blue foward).
The thing is that it works to override the parents rotation with the single movement (the commented line) but it doesnt work if i use the code that is in effect.
First it pulls the player in a wrong direction, and the problem is there again. The axis of the turning parent comes back and the controls starts to gradually flip backwards.
Im tyring my best here, but i need help.
Just this little thing.
help please.
moving the background will give me more problems.
but i solved it.
finally. by myself.
im not going for an endless loop, but its just to simulate the level further on. im going to have it as a road you can say. with twists and turns. dont want it to be just a straight path. so the player will have the same controlls whenever its facing the “wrong” way.