so i tried using the input system and it does look a little different from his older version but there was an option for up/down/left/right and thats what i chose and did all the keybinding and wrote the code like his but nothing is moving for me. do i need to turn off the timeline so i can move it not the timeline?
Hi felixq,
Please make sure that only the PlayerRig (= the parent) is animated. The PlayerShip (= the child of PlayerRig) must not be animated. Only the PlayerShip may be moved via code.
Did this help you fix the problem?
See also:
- Forum User Guides : How to mark a topic as solved
hi nina i havent tried it yet but i do in fact know that i have animated my player ship because i wanted it to go in between a couple mountains so i had it turn on its side to fit in there. i noticed that if i animate the rig to do this it would change the camera to follow it the same way and i didnt want that. is there a way to not have the camera angle change? or does rick talk about it in upcoming lessons
just clarify im watching using unitys new input system video i have redone the animation on just the rig so the player doesnt have an animation and the movement doesnt work. only moves from the timeline
Have you tried to disable the timeline to see if you are able to move the ship? If you are not able to move the ship, double check the spelling of your user input method. The correct spelling can be found in the PlayerInput component.
i deleted the timeline gameobject and all related components on the enemy and player rig and nothing works heres my code too
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
float horizontalInput = Input.GetAxis("Horizontal");
float verticalInput = Input.GetAxis("Vertical");
float xOffset = 1f;
float newXPos = transform.localPosition.x + xOffset;
transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, transform.localPosition.z);
}
}
That’s not the new input system. That’s the old one. If you enabled the new input system, it might be that Input.GetAxis does not work anymore because that’s part of the old input system.
Have you already tried to add Debug.Logs to your code to see what is going on during runtime?
Oh sorry I forgot to say that I did this for both the new and old system I even tried putting the settings to both when I tried both systems and I also tried putting it to the system I was using only to see if that would fix it. And yes I used the debug and it showed that the keys being pressed were working just wasn’t doing anything to my ship
Where do you use horizontalInput
and verticalInput
?
And could you explain me in detail what this code is supposed to do?
transform.localPosition = new Vector3(
transform.localPosition.x,
transform.localPosition.y,
transform.localPosition.z
);
I copied and pasted a line of code from your code, and formatted it. The code is still the same.
The horizontal and vertical input are the variable name for the axis movement and that code should be stating the current position of the ship right
that code should be stating the current position of the ship right
Why would we want to do that? The current position is stored in transform.localPosition
. Why would we want to assign the current position values again?
Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?
So should I take that code out and I never compare my code to the lecture notes only what I see on video
Your code is almost like Rick’s. Almost. If you read your code carefully and try to reenact the logic, you’ll probably see why it does not work as expected. If you can’t, that’s fine. Reading code in videos is difficult. Rick uploaded his code as text. You can find a link to his repository in the Resources of the video.
am i supposed to have transform.localposition = new Vector3(0, 0, 0)
Test it, and let me know what happened.
ok i think i figured it out i forgot to put the newxpos in place of transform.localposition.x it moves now but now i need to make it move on player input not automatically i dont want to jump ahead of the lesson so i will wait for rick to get to that part. thank you for guiding me to figure out the problem
Good job!
Yes, you had everything you needed in your code. You calculated the new position and assigned it to newXPos
. However, the problem was that you did not use that new x-position.
yes it all makes sense sometimes i just overlook things when i am doing coding i thought i might have broke something when importing the new input system it was so frustrating thanks again im glad to finally be able to move on and continue the lesson
No worries. That happens to everybody.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.