Godot Engine

Godot Engine

Fratm Jan 11, 2018 @ 9:37am
Help with Path2Follow and sprite orientation
Hi everyone,

I made a simple project to show the issue I am trying to work through, basically I made a sprite the flys a loop, when it heads to the right, the sprite is in the correct orientation, but when it follows the loop and heads back to the left, the sprite is upside down.

Here is a quick yt vid showing what I mean.

https://www.youtube.com/watch?v=E1JrolR1Cus

My question is, how can I detect when the sprite is upside down and then correct it?

My tree looks like this :

Path -> Path2Follow -> Sprite

and my script looks like this :

extends Path2D

onready var follow = get_node("PathFollow2D")

func _ready():
set_process(true)

func _process(delta):
follow.set_offset(follow.get_offset() + 350 * delta)


Thanks for any help on this one. I'm quite new to godot, and trying to work my way through some of the interesting features :)

-F
Last edited by Fratm; Jan 11, 2018 @ 9:39am
< >
Showing 1-3 of 3 comments
Matt [Linux] Jan 11, 2018 @ 9:44am 
um, maybe check whether the next point in the path is before or after the current one on the X axis.

if its before, (i.e. a lower x value) then we know it travelling left, if its after (a greater x value), we know its moving towards a point on the right side.

Im sure you could brute force this and check every tick if the position of the planes x value is greater or lesser than the previous tick.

then flip the sprite on the y axis like this...

var tempPos

func _ready():
tempPos = $sprite.position.x

func _process(delta):
if $sprite.position.x < tempPos:
$sprite.set_flip_v(false)

if $sprite.position.x > tempPos:
$sprite.set_flip_v(true)

tempPos = $sprite.position.x

play around with the "h" and "v" flip, depending on what you need
Last edited by Matt [Linux]; Jan 11, 2018 @ 10:05am
Fratm Jan 11, 2018 @ 10:40am 
I'll give this a try tongiht (at work right now..) Thanks.
Fratm Jan 11, 2018 @ 12:42pm 
Okay here is the code I wrote, and it somewhat works..

extends Path2D

onready var follow = get_node("PathFollow2D")

func _ready():
set_process(true)

func _process(delta):
follow.set_offset(follow.get_offset() + 350 * delta)
var tempPOS = int ( follow.get_pos().x)
if tempPOS > 669 :
get_node("PathFollow2D/Sprite").set_flip_v(true)
if tempPOS == 3 :
print ("CORRECTING FLIP!!!!!")
get_node("PathFollow2D/Sprite").set_flip_v(false)


But, it only works ever other time around the loop.. :/ But I am way closer to a solution than I was before. Thank you for your help on this.

-F
< >
Showing 1-3 of 3 comments
Per page: 1530 50

Date Posted: Jan 11, 2018 @ 9:37am
Posts: 3